Question

In: Computer Science

Start with code given for Student, StudentOther, StudentUpdate See code comments Student has two method that...

  • Start with code given for Student, StudentOther, StudentUpdate
    1. See code comments
    2. Student has two method that overloads rating
    3. StudentOther extends Student and has one method that overrides rating
    4. StudentUpdate call both classes
    5. Code as required
  • public class studentUpdate {
            
            
            public static void main(String[] args) {
    
                    //      instantiate Student object
                    Student s = ?; 
                    
    //              instantiate StudentOther object
                    StudentOther sO = ?; 
            
                    // set the fields
                    s.setStudentName ?;
                    s.setId ?;
                    s.setCredits ?;
                    s.setGpa ?;
                    s.setScholarship ?;
                    s.setCommuter ?;
                    
                    // check input          
                    System.out.println(s.getStudentData());
                    
                    // change this as needed
                    // run rating method 1
                    s.rating( s.getCredits(), s.getGpa() );
                    
                    // run rating method 2
                    s.rating( s.getCredits(), s.getGpa(), s.getScholarship() );
    
                    // run rating method 3
                    s.rating( s.getScholarship(), s.getGpa() );
                    
                    // run rating 4
                    sO.rating( s.getCredits(), s.getGpa() );
                    
                    
            }
    
    }
  • public class StudentOther ? Student {
            
    //      @Override       
            // new student rating method - use c and g
            public void rating( ? ) {       
                    System.out.println("This is student rating 4 - Override");
            }
    
    }
  • public class Student {
            
            // variables
            public String studentName;                        
            public int id;
            public int credits;      
            public double gpa; 
            public double scholarship;
            public boolean commuter;
            
            // getters and setters
            // select all- access Public
    
            
            // returns all the data in one string
            public String getStudentData()
               {
                  return(studentName +  " has a gpa of " +  gpa + " and has completed " + credits + "  credits");
               } 
            
            // student rating method
            // this is the primary method
            public void rating(int c, double g) {
                    System.out.println("Student rating 1 is: " + (c * g));
            }
            
    //      @Overload       
            // overload by count - add double s
            public void rating( ? ) {
                    System.out.println("Student rating 2 is: " + ((c + s) * g) + " Overload by count" );
            }
    
    //      @Overload       
            // overload by type
            public void rating(  ? ) {
                    System.out.println("Student rating 3 is: " + (s * g) + " Overload by type");
            }
            
    
    
    }

Solutions

Expert Solution

Below are the completed classes as per comments:

Student.java

public class Student {

        // variables
        public String studentName;
        public int id;
        public int credits;
        public double gpa;
        public double scholarship;
        public boolean commuter;

        // getters and setters
        // select all- access Public

        // returns all the data in one string
        public String getStudentData() {
                return (studentName + " has a gpa of " + gpa + " and has completed "
                                + credits + "  credits");
        }

        // student rating method
        // this is the primary method
        public void rating(int c, double g) {
                System.out.println("Student rating 1 is: " + (c * g));
        }

        // @Overload
        // overload by count - add double s
        public void rating(int c, double g, double s) {
                System.out.println("Student rating 2 is: " + ((c + s) * g)
                                + " Overload by count");
        }

        // @Overload
        // overload by type
        public void rating(double s, double g) {
                System.out.println("Student rating 3 is: " + (s * g)
                                + " Overload by type");
        }

        public String getStudentName() {
                return studentName;
        }

        public void setStudentName(String studentName) {
                this.studentName = studentName;
        }

        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        public int getCredits() {
                return credits;
        }

        public void setCredits(int credits) {
                this.credits = credits;
        }

        public double getGpa() {
                return gpa;
        }

        public void setGpa(double gpa) {
                this.gpa = gpa;
        }

        public double getScholarship() {
                return scholarship;
        }

        public void setScholarship(double scholarship) {
                this.scholarship = scholarship;
        }

        public boolean isCommuter() {
                return commuter;
        }

        public void setCommuter(boolean commuter) {
                this.commuter = commuter;
        }

}

StudentOther.java

public class StudentOther extends Student {

        // @Override
        // new student rating method - use c and g
        public void rating(int c, double g) {
                System.out.println("This is student rating 4 - Override and the rating is: " + (c * g));
        }

}

StudentUpdate.java

public class StudentUpdate {

        public static void main(String[] args) {

                // instantiate Student object
                Student s = new Student();

                // instantiate StudentOther object
                StudentOther sO = new StudentOther();

                // set the fields
                s.setStudentName("Nitya");
                s.setId(1);
                s.setCredits(32);
                s.setGpa(3.5);
                s.setScholarship(250.50);
                s.setCommuter(true);

                // check input
                System.out.println(s.getStudentData());

                // change this as needed
                // run rating method 1
                s.rating(s.getCredits(), s.getGpa());

                // run rating method 2
                s.rating(s.getCredits(), s.getGpa(), s.getScholarship());

                // run rating method 3
                s.rating(s.getScholarship(), s.getGpa());

                // run rating 4
                sO.rating(s.getCredits(), s.getGpa());

        }
}

Output

Nitya has a gpa of 3.5 and has completed 32 credits
Student rating 1 is: 112.0
Student rating 2 is: 988.75 Overload by count
Student rating 3 is: 876.75 Overload by type
This is student rating 4 - Override and the rating is: 112.0


Related Solutions

How do I go back to the start of the main method with the given code?...
How do I go back to the start of the main method with the given code? Hello I am making this java program and there is a point in the code where if the user types the character y it will start the program back at the beginning of the main method. How can I do this without drastically changing the code? For instance, if I type y, the program will go back to line 1 and repeat the entire...
27) Consider the student class. There is a method setSemesterGrade(int grade) In that method write code...
27) Consider the student class. There is a method setSemesterGrade(int grade) In that method write code to throw a new IllegalStateException if the average is less than 0 And an IndexOutOfBoundsException if the average is > 0 28) Consider a student represented by the variable s1 and we are trying to set the average of s1. Write a try catch routine to catch either error listed above try { s1.setSemesterGrade(-30); s1.setSemesterGrade(200);
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
Basically, the code already functions properly. Could you just write in method header comments explaining what...
Basically, the code already functions properly. Could you just write in method header comments explaining what the method does and what the parameters are? Some of them are already done. Additionally could you change the variables and method names to make them more descriptive of what they're actually holding? Thank you! import java.util.Scanner; /** * This class contains the entire program to print out a yearly calendar. * * @author * @author TODO add your name here when you contribute...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
In python and comments your code : Exercise 1 1.Write a function waiting for two matrices...
In python and comments your code : Exercise 1 1.Write a function waiting for two matrices and returning their addition, −1 if it is not not possible. 2. Write a function associated with a matrix and a scalar and returning the produced matrix. 3. Write a function accompanying an n × m matrix and a vector n and returning the vector produced by each other, −1 if this is not possible. 4. Write a function accompanying two n × m...
Given the following code below: public class Calculation { //method that returns cube of the given...
Given the following code below: public class Calculation { //method that returns cube of the given number public int findMax(int arr[]){    int max=0;    for(int i=1;i<arr.length;i++){        if(max<arr[i]){           max=arr[i]; }     }     return max;   } //method that returns cube of the given number   public static int cube(int n){        return n*n*n;     }   } (5 points) Define the class CalculationTest a subclass of TestCase (10 points) Define a setUp() method (20 points) Define a test method testfindMax that exercises Calculation.findMax() in Calculation class (5 points)Define...
An instructor has given a short quiz consisting of two parts. For a randomly selected student,...
An instructor has given a short quiz consisting of two parts. For a randomly selected student, let X = the number of points earned on the first part and Y = the number of points earned on the second part. Suppose that the joint pmf of X and Y is given in the accompanying table.   y p(x, y) 0 5 10 15 x 0 0.03 0.06 0.02 0.10 5 0.04 0.15 0.20 0.10 10 0.01 0.15 0.13 0.01 (a)...
An instructor has given a short quiz consisting of two parts. For a randomly selected student,...
An instructor has given a short quiz consisting of two parts. For a randomly selected student, let X = the number of points earned on the first part and Y = the number of points earned on the second part. Suppose that the joint pmf of X and Y is given in the accompanying table. y p(x, y)        0      5      10      15    x 0 0.03 0.06 0.02 0.10 5 0.04 0.13 0.20 0.10 10 0.01...
An instructor has given a short quiz consisting of two parts. For a randomly selected student,...
An instructor has given a short quiz consisting of two parts. For a randomly selected student, let X = the number of points earned on the first part and Y = the number of points earned on the second part. Suppose that the joint pmf of X and Y is given in the accompanying table. y p(x, y)    0 5 10 15 x 0 0.03 0.06 0.02 0.10 5 0.04 0.16 0.20 0.10 10 0.01 0.15 0.12 0.01 (a)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT