求大神,用java编写出来输出的结果要求是对话框
1个回答
展开全部
第一题
public class Student {
private String name;
private String id;
private float chinese;
private float math;
private float english;
public Student(){
this.name="张三";
this.id="111111";
}
public Student(String name,String id){
this.name=name;
this.id=id;
}
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;
}
public void sorce(){
System.out.println("总成绩是:"+(chinese+math+english));
}
public void average(){
System.out.println("平均分是:"+(chinese+math+english)/3);
}
public void goodstudent(){
if((chinese+math+english)/3>90){
System.out.println("你是三好学生");
}else{
System.out.println("你不是三好学生");
}
}
}
第二题
public class studentDemo {
public static void main(String[] args) {
String name="王五";
String id="123456";
Float chinese;
Float math;
Float english;
Student st=new Student(name,id);
do{
System.out.println("请输入语文成绩");
Scanner sc=new Scanner(System.in);
chinese= sc.nextFloat();
}while(chinese<1 || chinese>100);
st.setChinese(chinese);
do{
System.out.println("请输入数学成绩");
Scanner sc=new Scanner(System.in);
math= sc.nextFloat();
}while(math<1 || math>100);
st.setMath(math);
do{
System.out.println("请输入英语成绩");
Scanner sc=new Scanner(System.in);
english= sc.nextFloat();
}while(english<1 || english>100);
st.setEnglish(english);
System.out.println("姓名:"+ name);
System.out.println("学号:"+ id);
System.out.println("语文:"+ st.getChinese());
System.out.println("数学:"+ st.getMath());
System.out.println("英语:"+ st.getEnglish());
st.sorce();
st.average();
st.goodstudent();
}
}
运行结果:
请输入语文成绩
91
请输入数学成绩
92
请输入英语成绩
93
姓名:王五
学号:123456
语文:91.0
数学:92.0
英语:93.0
总成绩是:276.0
平均分是:92.0
你是三好学生
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询