Jerrylinusa
2015-12-01 11:35
package eletricpet;
public class dog {
private String name = "无名氏";
private int health = 100;
private int love = 0;
private String strain = "聪明的拉布拉多";
//给名字赋值
public void setName(String name){
this.name=name;
}
//取name值
public String getName(){
return this.name;
}
//health
public void setHealth(int health){
if(health<=0 || health>100){
System.out.println("健康有误");
this.health=60;
}else
this.health=health;
}
//love
public void setLove(int love){
if(love<=0 || love>100){
System.out.println("亲密度有误");
this.love=3;
}else
this.love=health;
//品种
public void print(){
}
package com.huawei.xuexi;
import java.net.MalformedURLException;
import java.net.URL;
//关于url的常用方法
public class Test02 {
private String name = "无名氏";
private int health = 100;
private int love = 0;
private String strain = "聪明的拉布拉多";
//给名字赋值
public void setName(String name){
this.name=name;
}
//取name值
public String getName(){
return this.name;
}
//health
public void setHealth(int health){
if(health<=0 || health>100){
System.out.println("健康有误");
this.health=60;
}else
this.health=health;
}
//love
public void setLove(int love){
if(love<=0 || love>100){
System.out.println("亲密度有误");
this.love=3;
}else
this.love=health;
}
//品种
public void print(){
}
}
少两个大括号,this.love=health;这行下面少一个,最后少一个。
//love
public void setLove(int love){
if(love<=0 || love>100){
System.out.println("亲密度有误");
this.love=3;
}else
this.love=health;
这个方法是不是少一个大括号?
Java入门第二季
531531 学习 · 6329 问题
相似问题