大贤者
精华
|
战斗力 鹅
|
回帖 0
注册时间 2007-8-16
|
StudentTester.javaimport java.util.Scanner;
public class StudentTester {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\\"Please enter your name\\");
String Name = scan.nextLine();
System.out.println(\\"Please enter your student ID\\");
int ID = scan.nextInt();
System.out.println(\\"Please enter your address\\");
String Add = scan.nextLine();
Student std = new Student(Name, ID, Add);
int times = 0;
while (true) {
System.out.println(\\"Please enter your Quiz mark on by \\" + \\"one. End with a negative number.\\");
double mark = scan.nextDouble();
if (mark < 0)
break;
else
std.addQuiz(mark);
times++;
}
System.out.println(\\"Student: \\" + \\"\\t\\" + std.getName());
System.out.println(\\"ID: \\" + \\"\\t\\" +std.getStudentID());
System.out.println(\\"Address: \\" + \\"\\t\\" +std.getAddress());
System.out.println(\\"Total times: \\" + \\"\\t\\" +times);
System.out.println(\\"Total score: \\" + \\"\\t\\" + std.getTotalScore());
System.out.println(\\"Adverage score: \\" + \\"\\t\\" + std.getAverageScore(times));
}
}Student.javapublic class Student
{
public Student(String Name, int ID, String Add)
{
sName = Name;
sID = ID;
sAdd = Add;
sTotal = 0;
sAdverge = 0;
}
public String getName()
{
return sName;
}
public int getStudentID()
{
return sID;
}
public String getAddress()
{
return sAdd;
}
public void addQuiz(double mark)
{
sTotal = sTotal +mark;
}
public double getTotalScore()
{
return sTotal;
}
public double getAverageScore(int times)
{
sAdverge = sTotal / times;
return sAdverge;
}
private String sName;
private int sID;
private String sAdd;
private double sTotal;
private int times;
private double sAdverge;
}errors found after compiled, including use of bracket, incorrect spellings etc
对照之前的version看一下吧 |
|