Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java The goal of this lab is to learn the followings: Get familiar with the method input validation, array parameters, and method overloading Phase 1

java image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
The goal of this lab is to learn the followings: Get familiar with the method input validation, array parameters, and method overloading Phase 1 - Modifying the Student class Validate the input in setCurrentSemester method to make sure it is between 1 and 10. Otherwise, display an error message and set the currentSemester instance variable to 1. Add the following method. calculate GPA(char[] grades): This method takes the student's grades as a char array and validates the input. Next, it calculates and returns the GPA using the following formula. Assume that all the courses are 4 credits. Input validation: If an element of the array is P. assign to that element. Any other invalid element (i.e. not A, B, C, D, F. or P) assign F to that element. No need to display messages. Using the validated input array calculate the GPA and return. Assume that the possible letter grades and their related grade points are as follows: Grade Grade Points A 4.0 3.0 2.0 1.0 0.0 ONIS grades.length gpa related grade points of grades[i] * 4 grades.length 4 Add the following private instance variable and its getter and setter method. Variable name Data type address String Add the following methods. [Note that these are overloaded methods of the setAddress method.) setAddress(String street, String city): Set the address instance variable as follows. Here (Unknown....) is a string value. address = street.city. [Unknown State]. [Unknown Zip] setAddress(String street, String city, String state): Set the address instance variable as follows. Here Unknown ....) is a string value. address = street, city, state , (Unknown Zip] setAddress(String street, String city, String state, int zip): Set the address instance variable as follows. address = street, city, state, zip Add or modify the JavaDoc comments in Student class based on the newly added/modified methods Phase 2 - Modifying the Cat class and Dog class In both Cat and Dog classes, validate the input in the following set methods. If the input is not in between 1 and 10, display an error message and set the instance variable to 1 setMood setHungry .setEnergy setSpeed .setCraftiness Modify the JavaDoc comments in CatDog classes based on the newly modified methods. 2 Phase 3- Modifying the MainDriver class Add the following methods into the Main Driver class. [Note: These are non-static methods. Therefore, to call these methods within the main method, you need to first create an object of the MainDriver class within the main method and use that object.] The cat win score and the dog win score are calculated using the same formulas given in Big Lab 4 Cat Win Score = (((meow Volume craftiness) / (ageFactor)) (speed + clawFactor) ageFactor = Max of (absolute value of (age - 5) and 1) The max replaces 0 with 1 of Cat has claws, clawFactor= 2 If Cat does not have claws, clawFactor = 0 Dog Win Score = (growlVolume craftiness) speed 4 findWinner(Cat C1, Cat c2): This method takes two Cat class objects and returns the winner's name. The cat with the highest win score wins. findWinner(Cat C1, Cat C2, Cat c3): This method takes three Cat class objects and returns the winner's name. The cat with the highest win score wins. findWinner(Dog d1, Dog d2): This method takes two Dog class objects and returns the winner's name. The dog with the highest win score wins. findWinner(Cat c1, Dog d1): This method takes a Cat class object and a Dog class object and returns the winner's name. The one with the highest win score wins. Add the JavaDoc comments in MainDriver class based on the newly added methods. 3 Phase 4-Modifying the main method in the MainDriver class Your existing code in the main method can be either deleted (if you have submitted all the previous labs) or commented. 1. Create a Student class object using the constructor defined in Big Lab 3. You may pass constant string values for the name, email, major, degreeType and the currentYear public Student(String name, String email, String major, String degreeType. String currentYear): a. Create a character array called myGrades with the following values. 'B', 'A', 'C', 'F', 'N', 'D', 'K','P','A', 'A b. Display the values of myGrades with a text message "Before calling to calculate GPA". c. Call the calculate GPA method in Student class using the created object and passing the myGrades as an argument. Display the returned value from the method. d. Again, display the values of my Grades with a text message "After calling to calculate GPA". e. Write a testbench for calculate GPA method to check whether it is correctly calculating the GPA. Use myGrades as the argument. f. Call the three setAddress methods by passing constant strings. After each setAddress call, use getAddress and display the value of the address instance variable 2. Create three Cat class objects (say C1, C2, C3) and two Dog class objects (d1 d2) using the constructor defined in Big Lab 3. You may pass constant string values for the names and the colors. public Cat(String name, String color) public Dog(String name, String color) Create an object of the Main Driver class called mainObj and call the four find Winner methods by passing Cat and Dog class objects. Display the winner in each case. 4

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions