Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java using netbeans please provide student,cat and dog classes thank you /* * To change this license header, choose License Headers in Project Properties. *

java using netbeans please provide student,cat and dog classes thank you image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package csc170labs; /* * Student.java * CSC 170 Example code */ /** * Represents a Student. * Includes name, age along with a GPA. * @author CSC170LAB */ public class Student{ //instance variables - data private String name; private int age; private double gpa; //setters and getters /** * Sets the name of this Student. * @param name the name for this Student. */ public void setName(String name){ this.name = name; } /** * Returns the name of this Student. * @return the name of this Student. */ public String getName(){ return this.name; } /** * Sets the age of this Student. * @param age the age for this Student. */ public void setAge(int age){ this.age = age; } /** * Returns the age of this Student. * @return the age of this Student. */ public int getAge(){ return this.age; } /** * Sets the grade point average of this Student. * @param gpa the grade point average for this Student. */ public void setGpa(double gpa){ this.gpa = gpa; } /** * Returns the grade point average of this Student. * @return the grade point average of this Student. */ public double getGpa(){ return this.gpa; } /** * Display the student name, age and grade point average. * @return nothing. */ public void displayInfo(){ System.out.println("Name: " + this.name); System.out.println("Age: " + this.age); System.out.println("GPA: " + this.gpa); } }
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 C to that element. Any other invalid element (1.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 retum. Assume that the possible letter grades and their related grade points are as follows: Grade Grade Points A 4.0 B 3.0 2.0 D 1.0 F 0.0 grades length gpa= related grade points of grades[i].4 grades.length. 4 1 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 Cat/Dog classes based on the newly modified methods. 2 Phase 3- Modifying the Main Driver class Add the following methods into the MainDriver 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 = {(meowvolume " craftiness) / (ageFactori) * (speed + dawFactor) ageFactor = Max of (absolute value of (age - 5) and 1) i/The max replaces 0 with 1 If 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 my Grades with the following values. 'B', 'A', 'C', 'F', 'N', 'D', ' KP 'A', 'A' b. Display the values of myGrades with a text message "Before calling to calculate GPA". 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, 3) 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 main obj and call the four findWinner methods by passing Cat and Dog class objects. Display the winner in each case, Submission. Zip file from your project folder and submit via Moodle BigLab6 link. (Your exam submission will be the same.) Grading Breakdown: Student.java (25 points) Cat.java (5 points) Dog.java (5 points) MainDriver.java (20 points) Main class code - Creating objects and calling the methods (25 points) JavaDoc of Student, Cat Dog, and MainDriver classes (20 points)

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

Students also viewed these Databases questions