Hi,
I have designed a basic student class diagram (below) in order to write the code for this class.
Student
studentNumber: String
studentName: String
markForMaths:int
markForEnglish:int
markForScience:int
Student(String, String)
getNumber(): String
getName(): String
enterMarks(int, int, int)
getMathsMark():int
getEnglishMark():int
getScienceMark():int
calculateAverageMark():double
Writing the code for the student class (below) was fairly straightforward but I am having problems with another class called tester which tests the student class.
The tester class is the problem, i very simple problem. All i want to change is it to show the name of the student before it asks the student to enter their marks. But it always comes up with errors when i try and do this.Code:public class Student { //The attributes private String studentNumber; private String studentName; private int markForMaths; private int markForEnglish; private int markForScience; //The methods //The constructor public Student (String numberIn, String nameIn) { studentNumber = numberIn; studentName = nameIn; } //Methods to read the attributes public String getStudentNumber() { return studentNumber; } public String getStudentName() { return studentName; } public void enterMarks(int mathsIn,int engIn, int sciIn) { markForMaths = mathsIn; markForEnglish = engIn; markForScience = sciIn; } public int getMathsMark() { return (markForMaths); } public int getEnglishMark() { return (markForEnglish); } public int getScienceMark() { return (markForScience); } public double calculateAverageMark() { return (markForMaths + markForEnglish + markForScience)/3.0; } }
The code is below:
Any suggestions would be appreciatedCode:public class StudentTester { public static void main(String []args) { int maths,english,science; Student Marks; System.out.println("Please enter your mark for maths"); maths = EasyIn.getInt(); System.out.println("Please enter your mark for english"); english = EasyIn.getInt(); System.out.println("Please enter your mark for science"); science = EasyIn.getInt(); Student exam = new Student("234444","David Billabonna"); exam.enterMarks(maths, english, science); System.out.println("Student no. is " + exam.getStudentNumber()); System.out.println("Student name is " + exam.getStudentName()); System.out.println("Maths mark is " + exam.getMathsMark()); System.out.println("English mark is " + exam.getEnglishMark()); System.out.println("Science mark is " + exam.getScienceMark()); System.out.println("The average mark is " + exam.calculateAverageMark()); System.out.println(); } }
Thanks


Reply With Quote


Bookmarks