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).
Understand the code and explain the code and answer the questions. Type your answers as comments....
Understand the code and explain the code and answer the questions. Type your answers as comments. #include #include using namespace std; // what is Color_Size and why it is at the end? enum Color {        Red, Yellow, Green, Color_Size }; // what is Node *next and why it is there? struct Node {        Color color;        Node *next; }; // explain the code below void addNode(Node* &first, Node* &last, const Color &c) {        if (first == NULL)...
write code with proper comments for ever step the code should be in form of pseudocode                            &
write code with proper comments for ever step the code should be in form of pseudocode                                    To Print Triangle of any size, by taking size as input. To Print Triangle of any size, by taking size as input. If size is 4 then triangle is: To calculate Factorial of any number. To calculate the power of any given number. To Print Table of Any Number up till 10: as shown in this figure. for a program which reads 10 integers...
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,...
Java: modify the given example code to make it possible to create a student object by...
Java: modify the given example code to make it possible to create a student object by only specifying the name, all other info may be absent. it may also be possible to add a tag with an absent value. use OPTIONAL TYPE and NULL object design pattern.   import java.util.HashMap; import java.util.Map; public class Student { private final String aName; private String aGender; private int aAge; private Country aCountry; private Map aTags = new HashMap<>(); public Student(String pName) { aName =...
Java: modify the given example code to make it possible to create a student object by...
Java: modify the given example code to make it possible to create a student object by only specifying the name, all other info may be absent. it may also be possible to add a tag with an absent value. import java.util.HashMap; import java.util.Map; public class Student { private final String aName; private String aGender; private int aAge; private Country aCountry; private Map<String, String> aTags = new HashMap<>(); public Song(String pName) { aName = pName; } public String getName() { return...
1. Write code in mips that will play battleships. Include comments in code on what each...
1. Write code in mips that will play battleships. Include comments in code on what each part is doing.
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz...
JAVA PROGRAM: INCLUDE COMMENTS EXPLAINING THE CODE PLEASE Given the following information: 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 128GB PCIe-based flash storage 13-inch MacBook Air, 1.6GHz dual-core Intel Core i5 processor, Turbo Boost up to 2.7GHz, Intel HD Graphics 6000, 8GB memory, 256GB PCIe-based flash storage 15.6-inch Dell i3552, 1.6GHz Processor, Intel Pentium N3700, HD Laptop, 4 GB memory, DDR3L SDRAM, Windows 10, Black Drive 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT