In Java   I need to create a 2 new Student objects in a main method.  The first will have name, major, 16 hours completed, and a 3.8 gpa.  The 2nd will have name and major.  they just started scool and have no hours completed or gpa.  I need to change the 2nd students major. I need to update the students information based on hours they took and return a class level.   public class Student {     private String name;     private String major;     private double gpa;     private int hoursCompleted;               /**Constructor      * @param name      *  The student's name      * @param major      *  The student's major      */     public Student(String name, String major)     {         this.name = name;         this.major = major;         this.gpa = 0.0;         hoursCompleted = 0;     }              /**Constructor      * @param name      *  The student's name      * @param major      *  The student's major      * @param gpa      *  The student's cumulative gpa      * @param hoursCompleted      *  Number of credit hours the student has completed      */     public Student(String name, String major, double gpa, int hoursCompleted)     {         this.name = name;         this.major = major;         this.gpa = gpa;         this.hoursCompleted = hoursCompleted;     }          /**      * @return The student's major.      */     public String getMajor()     {         return major;     }     /**      * @param major The major to set.      */     public void setMajor(String major)     {         this.major = major;     }     /**      * @return The student's name.      */     public String getName()     {         return name;     }     /**      * @param name The name to set.      */     public void setName(String name)     {         this.name = name;     }     /**      * @return The student's gpa.      */     public double getGpa()     {         return gpa;     }     /**      * @return The number of credit hours the student has completed.      */     public int getHoursCompleted()     {         return hoursCompleted;     }          /**      * @return The student's class (Freshman, Sophomore, Junior, Senior)      */     public String getClassLevel()     {         String classLevel;         if (hoursCompleted < 30)         {             classLevel = "Freshman";         }         else if (hoursCompleted < 60)         {             classLevel = "Sophomore";         }         else if (hoursCompleted < 90)         {             classLevel = "Junior";         }         else         {             classLevel = "Senior";         }         return classLevel;     }          /**Update student's information to reflect completion of a semester's work      * @param semHours      * Number of credit hours the student has just completed      * @param semGPA      * GPA for the semester just completed      */     public void updateStudent(int semHours, double semGPA)     {         int oldHours = hoursCompleted;         hoursCompleted = oldHours + semHours;         gpa = (oldHours *gpa + semHours * semGPA) / hoursCompleted;     }          /** Print the student's name and class */     public void printClassLevel()     {         System.out.println(name + " is a " + getClassLevel());     }          /**Prints the information about a student in a nice format with       *  appropriate labeling      */     public void print()     {         DecimalFormat fmt = new DecimalFormat("0.000");         System.out.println(name + " is a " + getClassLevel() + " " + major);         System.out.print("who has completed " + hoursCompleted + " hours ");         System.out.println("with a " + fmt.format(gpa) + " gpa.");     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In Java

 

I need to create a 2 new Student objects in a main method.  The first will have name, major, 16 hours completed, and a 3.8 gpa.  The 2nd will have name and major.  they just started scool and have no hours completed or gpa.  I need to change the 2nd students major. I need to update the students information based on hours they took and return a class level.

 

public class Student
{
    private String name;
    private String major;
    private double gpa;
    private int hoursCompleted;
    
    
    /**Constructor
     * @param name
     *  The student's name
     * @param major
     *  The student's major
     */
    public Student(String name, String major)
    {
        this.name = name;
        this.major = major;
        this.gpa = 0.0;
        hoursCompleted = 0;
    }
        
    /**Constructor
     * @param name
     *  The student's name
     * @param major
     *  The student's major
     * @param gpa
     *  The student's cumulative gpa
     * @param hoursCompleted
     *  Number of credit hours the student has completed
     */
    public Student(String name, String major, double gpa, int hoursCompleted)
    {
        this.name = name;
        this.major = major;
        this.gpa = gpa;
        this.hoursCompleted = hoursCompleted;
    }
    
    /**
     * @return The student's major.
     */
    public String getMajor()
    {
        return major;
    }
    /**
     * @param major The major to set.
     */
    public void setMajor(String major)
    {
        this.major = major;
    }
    /**
     * @return The student's name.
     */
    public String getName()
    {
        return name;
    }
    /**
     * @param name The name to set.
     */
    public void setName(String name)
    {
        this.name = name;
    }
    /**
     * @return The student's gpa.
     */
    public double getGpa()
    {
        return gpa;
    }
    /**
     * @return The number of credit hours the student has completed.
     */
    public int getHoursCompleted()
    {
        return hoursCompleted;
    }
    
    /**
     * @return The student's class (Freshman, Sophomore, Junior, Senior)
     */
    public String getClassLevel()
    {
        String classLevel;
        if (hoursCompleted < 30)
        {
            classLevel = "Freshman";
        }
        else if (hoursCompleted < 60)
        {
            classLevel = "Sophomore";
        }
        else if (hoursCompleted < 90)
        {
            classLevel = "Junior";
        }
        else
        {
            classLevel = "Senior";
        }
        return classLevel;
    }
    
    /**Update student's information to reflect completion of a semester's work
     * @param semHours
     * Number of credit hours the student has just completed
     * @param semGPA
     * GPA for the semester just completed
     */
    public void updateStudent(int semHours, double semGPA)
    {
        int oldHours = hoursCompleted;
        hoursCompleted = oldHours + semHours;
        gpa = (oldHours *gpa + semHours * semGPA) / hoursCompleted;
    }
    
    /** Print the student's name and class */
    public void printClassLevel()
    {
        System.out.println(name + " is a " + getClassLevel());
    }
    
    /**Prints the information about a student in a nice format with 
     *  appropriate labeling
     */
    public void print()
    {
        DecimalFormat fmt = new DecimalFormat("0.000");
        System.out.println(name + " is a " + getClassLevel() + " " + major);
        System.out.print("who has completed " + hoursCompleted + " hours ");
        System.out.println("with a " + fmt.format(gpa) + " gpa.");
    }
}

Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education