
Java coding assignment
- or -
Post a project like this936
$10
- Posted:
- Proposals: 3
- Remote
- #3735980
- Awarded
Description
Experience Level: Entry
Estimated project duration: 1 day or less
Create a class Student that has instance variables for first and last name and int age and double gpa (grade point average)
In your mutators, throw an IllegalArgumentException if you get an age or gpa outside a reasonable range.
In a separate main, create a Student, ask the user to enter the student's information, and use what they give you to set the values.
To read in numbers, you may choose to use Scanner's nextInt and nextDouble methods (InputMismatchException), or use nextLine, and then parseInt and parseDouble (NumberFormatException). Either way, if they give you an invalid value an exception will happen.
Note: If you choose to use nextInt, and nextDouble, after an exception the Scanner will use up only the next int/double it comes to and not any spaces or newline after it. So in this case you need to do .nextLine() as well to clear out the rest of the line IF an exception happens.
Also, if they give you a value in the wrong range, the mutator will throw an exception. (Usually it would be better to check our values before giving them to the mutator, but we will let this happen.)
Catch each possible type of exception separately, and give the user a specific explanation of which problem occurred, for instance, if they give you a number outside the range, tell them what range the value should be in (hint: IllegalArgumentException has a parameterized constructor you can use), if they don't give you a number at all, tell them a number is required.
For both age and GPA, make the user keep trying until you get valid input. Think about how to structure your loops; users get very frustrated if they have to re-enter everything when they only got one input wrong. (hint: either think about when you know you have to repeat, or when you know you are done, and use an extra variable to keep track of whether you have to try again)
When you have successfully finished setting the Student's information, print the Student.
Also give Student clone and a copy constructor that throws an IllegalArgumentException if given a null; check in main that these work, catching the exception appropriately.
In your mutators, throw an IllegalArgumentException if you get an age or gpa outside a reasonable range.
In a separate main, create a Student, ask the user to enter the student's information, and use what they give you to set the values.
To read in numbers, you may choose to use Scanner's nextInt and nextDouble methods (InputMismatchException), or use nextLine, and then parseInt and parseDouble (NumberFormatException). Either way, if they give you an invalid value an exception will happen.
Note: If you choose to use nextInt, and nextDouble, after an exception the Scanner will use up only the next int/double it comes to and not any spaces or newline after it. So in this case you need to do .nextLine() as well to clear out the rest of the line IF an exception happens.
Also, if they give you a value in the wrong range, the mutator will throw an exception. (Usually it would be better to check our values before giving them to the mutator, but we will let this happen.)
Catch each possible type of exception separately, and give the user a specific explanation of which problem occurred, for instance, if they give you a number outside the range, tell them what range the value should be in (hint: IllegalArgumentException has a parameterized constructor you can use), if they don't give you a number at all, tell them a number is required.
For both age and GPA, make the user keep trying until you get valid input. Think about how to structure your loops; users get very frustrated if they have to re-enter everything when they only got one input wrong. (hint: either think about when you know you have to repeat, or when you know you are done, and use an extra variable to keep track of whether you have to try again)
When you have successfully finished setting the Student's information, print the Student.
Also give Student clone and a copy constructor that throws an IllegalArgumentException if given a null; check in main that these work, catching the exception appropriately.

Yash P.
100% (9)Projects Completed
4
Freelancers worked with
2
Projects awarded
71%
Last project
6 Dec 2022
India
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies