public static void main(String[] args) {
Student student
float chinese
float math
float english
do {
chinese = getByInputBox("输入语文成绩:")
} while (chinese < 1 || chinese > 100)
do {
math = getByInputBox("输入数学成绩:")
} while (math < 1 || math > 100)
do {
english = getByInputBox("输入英语成绩:")
} while (english < 1 || english > 100)
student = new Student("xxx","xxxxxxxxx")
student.setChinese(chinese)
student.setMath(math)
student.setEnglish(english)
System.out.println(student)
}
private static float getByConsole(String msg) {
System.out.print(msg)
return new Scanner(System.in).nextFloat()
}
private static float getByInputBox(String msg) {
String result = JOptionPane.showInputDialog(null, msg)
try{
return Float.parseFloat(result)
}catch (Exception e){
return 0
}
陆雹 }
}
class Student {
private String name
private String id
private float chinese
private float math
private float english
public Student() {
name = "张三"
id = "111111"
}
public Student(String name, String id) {
this.name = name
this.id = id
}
public float score() {
return chinese + math + english
}
public float average() {
return score() / 3
}
public boolean goodStudent() {
return average() > 90
}
public float getChinese() {
return chinese
}
public void setChinese(float chinese) {
this.chinese = chinese
}
public float getMath() {
return math
}
public void setMath(float math) {
this.math = math
}
public float getEnglish() {
早激帆 return english
}
public void setEnglish(float english) {
this.english = english
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
铅纤 ", id='" + id + '\'' +
", chinese=" + chinese +
", math=" + math +
", english=" + english +
'}'
}
}
package testpublic class Student {
private String name
private String id
private String clazz
private int age
private String address
/**
* sayHello方法唤晌枝
*/
public void sayHello() {
System.out.println("学号为" + this.id + "的同学的具体信息如下:")
System.out.println("姓名谨肢:" + this.name)
System.out.println("班级:" + this.clazz)
System.out.println("年龄:" + this.age)
System.out.println("家庭住址:" + this.address)
}
/**
* 测试方法
*
* @param args
*/
public static void main(String[] args) {
// 第一问
Student student = new Student()
student.setAddress("百度知道")
student.setAge(1)
student.setClazz("一班")
student.setId("071251000")
student.setName("lsy605604013")
student.sayHello()
// 第二问
Student studentNew = new Student()
studentNew.setAddress("搜搜知道")
studentNew.setAge(2)
studentNew.setClazz("二班")
studentNew.setId("和敏071251001")
studentNew.setName("lady")
if (student.getAge() <studentNew.getAge())
studentNew.sayHello()
else if (student.getAge() >studentNew.getAge())
student.sayHello()
else
System.out.println("两人一样大")
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public String getId() {
return id
}
public void setId(String id) {
this.id = id
}
public String getClazz() {
return clazz
}
public void setClazz(String clazz) {
this.clazz = clazz
}
public int getAge() {
return age
}
public void setAge(int age) {
this.age = age
}
public String getAddress() {
return address
}
public void setAddress(String address) {
this.address = address
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)