Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE LOOK AT THE RUNS!!! 2 . Create a new Java class named Student, according to the UML diagram. Specifications for the Student Class (

PLEASE LOOK AT THE RUNS!!!
2. Create a new Java class named Student, according to the UML diagram.
Specifications for the Student Class (In combination with the UML):
Constructor without arguments - will assign all field values based on your personal
information (your student number, full name with a score of 100).
Constructor with 3 arguments - will assign all field values based on the information
passed in the arguments.
printInfo()- prints out the three field values
with the help of the printf() method. It uses field width and justification as shown in the sample output.
(Note: in the sample output, the field width of 20,20,3 and 2 have been used to present the name, student number, score, and letter grade, respectively, and all the data-items used left justification.)
The accessor/getter method getName() returns the students full name (the first name followed by a space followed by the last name), while getScore() returns the score of a student.
The mutator/setter methods setName(), setStudentName(), setScore() will set the appropriate values (see the UML diagram) received from the user
The member method called getLetterGrade() returns the letter grade for the corresponding score according to the table given below (Hint: See Unit 5, slide 24-26).
Student
-name: String -studentNumber: int -score: int
+Student()
+Student(nm: String, sn: int, sc: int)+printInfo(): void
+getName() : String
+getScore(): int
+setName(nm: String): void +setStudentNumber(sn: int): void +setScore(sc: int): void +getLetterGrade() : String
Score
Letter
Grade
90 or greater A+80-89 A-70-79 B+60-69 B-
50-59 C+40-49 C-30-39 D
29 or less F
3. In the same Java package, create a driver class with the name StudentGradesByYourFirstName (YourFirstName should be your first name) and do the following:
Page 2 of 8
ES1036B - Programming Fundamentals for Engineers
Lab Exercise 05
a. Declare a public static Scanner type field and instantiate it. Note: When in a class, we declare a Scanner type field called input (we can use any valid name) and instantiate it as public static Scanner input = new Scanner(System.in);this field can be used in any of the static methods of this class. But if we declare a Scanner type reference variable as a local variable then this one can only be used inside the method that we declare it.
b. Declare another public static int type field called counter and assign it to zero value. This will keep the count of number of students inside the dataEntry() method.
c. Define a public static void method called dataEntry() that has the following header:
public static void dataEntry(Student s){}
This method will receive a Student type reference in s and do the following inside the
method:
o Incrementtheintegertypefieldcounteryoudeclared;wewilluseittokeep track of the number of Students overall in a run. You can see in the sample output that it says Student 1,2 etc. Please note that when you increment any static field inside any method, that incremented value remains the same for all the other methods inside the same class.
o Prompttheusertoenterthestudentnumber,andwiththeuseoftheScanner field declared in (a) get the value from the keyboard and store it in an appropriate variable. Note: the student number must be entered first otherwise, no mark will be awarded. The goal in maintaining this order is to test our understanding of buffer-clearing dummy-calls associated with the use of the nextLine() method which we need for the next specification.
o Prompttheusertoenterthefullname,andwiththeuseofthesameScannerfield declared in (a) get the value from the keyboard and store it in an appropriate variable.
o Prompttheusertoenterthescore,andwiththeuseofthesameScannerfield declared in (a) get the value from the keyboard and store it in an appropriate variable.
o Youcanchooseany9-digitstudentnumber,anyfullname(firstnameandlast name with a space in between) and any score between 0 and 100. Assume that the user will enter valid data only.
o Nowitwillsetalltheabovevaluestoswiththehelpofthesettermethods.
d. Define a public static method called compareGrades() that has the following header: public static int compareGrades(Student s1, Student s2){} This method will receive two Student type references s1 and s2, and do the following:
o It will return 1 if s1s score is greater, else, it will return -1 if s2s score is greater, otherwise, if both are equal it will return 0.
e. Copy and paste the myHeader() and myFooter() methods you created in the previous lab.
f. Now define the driver method with the following specifications:
o Inside the main() method, call myHeader() with appropriate arguments. o Declare a Student type reference variable s1 and instantiate it to create an
object with the help of the constructor without argument.
o Using the printInfo() method print the information on the screen. Since you
have defined the constructor without parameter with your own information, the printInfo() me

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 Tsukuba Japan April 2010 Proceedings Part 1 Lncs 5981

Authors: Hiroyuki Kitagawa ,Yoshiharu Ishikawa ,Wenjie Li ,Chiemi Watanabe

2010th Edition

3642120253, 978-3642120251

More Books

Students also viewed these Databases questions