Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a package named Q 1 . Create a new Java class named Student, according to the UML diagram. Specifications for the Student Class (

Create a package named Q1.
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 student's 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 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 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() method call by s1 will print your information on the screen (see the sample output).
o Declare another Student type reference variable s2 and instantiate it using the constructor without arguments.
o Now call the dataEntry() method for s1 and s2, and populate the student objects that are referred to by s1 and s2.
o Now, print the information for both the students by calling the printInfo() method for each (see the sample output).
o Now call the compareGrade() method to compare the grades of the two
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions