Assignment Q2
Create a new BlueJ project called YourFirstNameLastName-A1Q2. For example, mine would be AlexHendry-A1Q2.
Create a class called Student.
Make sure you write a description of your new Class in the comments, with your name as author and date as the last date you worked on this exercise.
Add definitions for the following fields:
• A name field of type String
• A studentId field of type int
• A degree field of type String
• An international field of type boolean
Write a constructor for your Student class that takes two parameters - the first of type String called myName, and the second of type int called myStudentId. Set the initial values of the corresponding fields, using the constructor.
Write an accessor method called getName that returns the value of the name field.
Write a mutator method called setStudentId that takes a single parameter of type int and sets the value of the studentId field.
Work out what other accessor and mutator methods would be useful for this Class and add them. You should be able to get and set all fields in the Class.
Write a method called printDetails, which prints out all the details of a Student object. You must take into account the international status and print a line saying either that the student is international, or the student is not international.
For example, if:
• The name field holds the value "Helen"
• The studentId field holds the value 111222
• The degree field holds the value "Bachelor of IT"
• The international field holds the value true
Then the printDetails method would print out the following:
The name of the student is Helen. The student id of the student is 111222. The degree of the student is Bachelor of IT. The student is international.
If the international field holds the value false then the printDetails method would print out the following:
The name of the student is Helen. The student id of the student is 111222. The degree of the student is Bachelor of IT. The student is not international.
Please Note: In the above examples the name, studentId , degree and whether the student
is international or not (in red) will change based on the values the fields hold. However you
must print the remainder of the statements exactly as in the above examples.
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.