JAVA题求解
展开全部
//学生对象
public class Student {
private double computerScore;
private double sportScore;
private double musicScore;
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
}
public double getSportScore() {
return sportScore;
}
public void setSportScore(double sportScore) {
this.sportScore = sportScore;
}
public double getMusicScore() {
return musicScore;
}
public void setMusicScore(double musicScore) {
this.musicScore = musicScore;
}
public Student(double computerScore, double sportScore, double musicScore) {
super();
this.computerScore = computerScore;
this.sportScore = sportScore;
this.musicScore = musicScore;
}
public Student() {
super();
}
}
//Score文件
public class Score {
public static double getTotalScore(Student student) {
return student.getComputerScore() + student.getSportScore() + student.getMusicScore();
}
public static double getAverage(Student student) {
return (student.getComputerScore() + student.getSportScore() + student.getMusicScore()) / 3;
}
public static double getMaxScope(Student student) {
double computerScore = student.getComputerScore();
double sportScore = student.getSportScore();
double musicScore = student.getMusicScore();
if(computerScore >= sportScore && computerScore >= musicScore) {
return computerScore;
}else if(sportScore >= computerScore && sportScore >= musicScore) {
return sportScore;
}else {
return musicScore;
}
}
public static double getMinScope(Student student) {
double computerScore = student.getComputerScore();
double sportScore = student.getSportScore();
double musicScore = student.getMusicScore();
if(computerScore <= sportScore && computerScore <= musicScore) {
return computerScore;
}else if(sportScore <= computerScore && sportScore <= musicScore) {
return sportScore;
}else {
return musicScore;
}
}
public static void outputTotalScope(Student student) {
double computerScore = student.getComputerScore();
double sportScore = student.getSportScore();
double musicScore = student.getMusicScore();
System.out.println(computerScore+sportScore+musicScore);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入计算机成绩");
double computerScore = scan.nextDouble();
System.out.println("请输入体育成绩");
double sportScore = scan.nextDouble();
System.out.println("请输入音乐成绩");
double musicScore = scan.nextDouble();
System.out.println("开始实例化学生=========");
Student student = new Student(computerScore,sportScore,musicScore);
System.out.println("实例化学生成功====");
scan.close();
/*求总成绩
* */
System.out.println(getTotalScore(student));
/*求平均成绩
* */
System.out.println(getAverage(student));
/*求最大成绩
* */
System.out.println(getMaxScope(student));
/*求最小成绩
* */
System.out.println(getMinScope(student));
/*输入总成绩
* */
outputTotalScope(student);
}
}
public class Student {
private double computerScore;
private double sportScore;
private double musicScore;
public double getComputerScore() {
return computerScore;
}
public void setComputerScore(double computerScore) {
this.computerScore = computerScore;
}
public double getSportScore() {
return sportScore;
}
public void setSportScore(double sportScore) {
this.sportScore = sportScore;
}
public double getMusicScore() {
return musicScore;
}
public void setMusicScore(double musicScore) {
this.musicScore = musicScore;
}
public Student(double computerScore, double sportScore, double musicScore) {
super();
this.computerScore = computerScore;
this.sportScore = sportScore;
this.musicScore = musicScore;
}
public Student() {
super();
}
}
//Score文件
public class Score {
public static double getTotalScore(Student student) {
return student.getComputerScore() + student.getSportScore() + student.getMusicScore();
}
public static double getAverage(Student student) {
return (student.getComputerScore() + student.getSportScore() + student.getMusicScore()) / 3;
}
public static double getMaxScope(Student student) {
double computerScore = student.getComputerScore();
double sportScore = student.getSportScore();
double musicScore = student.getMusicScore();
if(computerScore >= sportScore && computerScore >= musicScore) {
return computerScore;
}else if(sportScore >= computerScore && sportScore >= musicScore) {
return sportScore;
}else {
return musicScore;
}
}
public static double getMinScope(Student student) {
double computerScore = student.getComputerScore();
double sportScore = student.getSportScore();
double musicScore = student.getMusicScore();
if(computerScore <= sportScore && computerScore <= musicScore) {
return computerScore;
}else if(sportScore <= computerScore && sportScore <= musicScore) {
return sportScore;
}else {
return musicScore;
}
}
public static void outputTotalScope(Student student) {
double computerScore = student.getComputerScore();
double sportScore = student.getSportScore();
double musicScore = student.getMusicScore();
System.out.println(computerScore+sportScore+musicScore);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入计算机成绩");
double computerScore = scan.nextDouble();
System.out.println("请输入体育成绩");
double sportScore = scan.nextDouble();
System.out.println("请输入音乐成绩");
double musicScore = scan.nextDouble();
System.out.println("开始实例化学生=========");
Student student = new Student(computerScore,sportScore,musicScore);
System.out.println("实例化学生成功====");
scan.close();
/*求总成绩
* */
System.out.println(getTotalScore(student));
/*求平均成绩
* */
System.out.println(getAverage(student));
/*求最大成绩
* */
System.out.println(getMaxScope(student));
/*求最小成绩
* */
System.out.println(getMinScope(student));
/*输入总成绩
* */
outputTotalScope(student);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询