import java.util.Scanner;
class Test_6{
public static void main(String[] args)
{
Scanner c = new Scanner(System.in);
System.out.println("请输入语文成绩:");
int chineseCord=c.nextInt();
System.out.println("请输入数学成绩:");
int mathCord=c.nextInt();
System.out.println("请输入英语成绩:");
int englishCord=c.nextInt();
Student s = new Student();
s.setChineseCord(chineseCord);
s.setMathCord(mathCord);
s.setEnglishCord(englishCord);
s.getSum();
System.out.println("语文="+s.getChineseCord()+" 数学="+s.getMathCord()+" 英语="+s.getEnglishCord()+" sum="+s.getSum());
}
}
class Student{
private int chineseCord;
private int mathCord;
private int englishCord;
public void setChineseCord(int chineseCord) {
this.chineseCord = chineseCord;
}
public int getChineseCord(){
return chineseCord;
}
public void setMathCord(int mathCord) {
this.mathCord = mathCord;
}
public int getMathCord(){
return mathCord;
}
public void setEnglishCord(int englishCord) {
this.englishCord = englishCord;
}
public int getEnglishCord(){
return englishCord;
}
public int getSum(){ // 若括号添加了变量 代表什么????
int sum =chineseCord+mathCord+englishCord ;
//System.out.println("总成绩="+sum);
return sum;
}
}
|
|