Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have shared with a starter Code Due to the popularity of you've been asked to extend the program to have more functionality, In particular,

I have shared with a starter Code image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Due to the popularity of you've been asked to extend the program to have more functionality, In particular, the administrator is tired of writing letters to each of the students and would prefer instead to automate this entire process. Default Constructors When we create objects we can use the default constructor. Although we haven't put the code below into any of our programs yet, the compiler has automatically created this when we miss it out, and this is what is being called when we say public student 0 f 3 This implicitly also sets each of the variables to their default values (which is normally , We can then go through each of our attributes and manually change these to the values we want them to using setters. Student alice - new Student O : alice nane = "Alice"; atice.student1d - 1234567; altee,enait - "aliceXtremeltiol con": alice.enrolmentrear 2021; alice yearoffirth - 1984; Better Constructors There is no need for us to have such a simple constructor however, and constructors can take arguments the same as any other method, as well as having class level access (can change below. variables belonging to that class). For example we could use the constructor like public Student(String studentName) ( name - studentName; In a separate (line of the) program we can then instantiate a new student with name "Alice" like this: This enables us to save on some code when creating Student classes, which improves readability of programs all round. Your Turn! Change the constructor of the Student class so that it takes two s. and three _, and creates a new having to call the setter of each of these variables individually, e.g. Sudent alice - new Student ("Alice", "olticextremefool, com", 1984, 2021, 1234567) You will notice that the class has not main method and can therefore not be executed directly. In order to test your class, write a main method either in this, or a new dummy "application" class, which just instantiates and prints a few students. But Wait There's More In addition to being able to define a constructor, we can define multiple constructors! This gives wider applicability to constructors, where we may not know all of the information about an object where we create it, or maybe the information given about an object is given in different formats. For example we might create a class when the student first applies to the university, we don't know what their student ID is at this point, and when their place is accepted they may choose to defer their placement for a year. When we define multiple methods with the same method name, but different arguments this is called overloading a method. Your Turn! Create a new overioaded constructor method for the class which takes only three arguments, two birth year for each of these students. Other Functionality in Constructors Seeing how useful these constructors are, the administrator has asked you to change your program 50 that we can store all the historic details of students also. This data is mostly the same, but the date of birth for these students is in format such as "01/06/1984: Your Turn! Add a new constructor to your class which takes three i and correctly parses these. You will still store the year of birth as an integer however, so you will need to add some more code into this constructor to process this date string and store the year as an Hint: classes have a built in method, This could be very useful. The class has a built in method that allows to interpret a String as a number. public class Student \{ public boolean hasSubmitted = ialui; pibluc void submitCoursework() \{ hasSubmitted = iria; 3

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions