Question

In: Computer Science

This is 1 java question with its parts. Thanks so much! Create a class named Student...

This is 1 java question with its parts. Thanks so much!

  1. Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point average field by dividing points by credit hours earned. Write methods to display the values in each Student field.

  2. Use class named ShowStudent that instantiates a Student object to test your class. Compute the Student grade point average, and then display all the values associated with the Student.

  3. Create a constructor for the Student class you created. The constructor should initialize each Student’s ID number to 9999, his or her points earned to 12, and credit hours to 3 (resulting in a grade point average of 4.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values.

Solutions

Expert Solution

Source code

Student class

public class Student {
    //instance variables declaration to hold student information
    private int IdNumber;
    private int noCreditsHours;
    private double noPointsEarned;
    private double gradePointAverage;
    //Non parameterized constructor
    public Student() {
        IdNumber = 9999;
        noCreditsHours = 3;
        noPointsEarned = 12;
    }
    //display methods for each student field
    public void displayIdNumber() {
        System.out.println("Student ID: "+IdNumber);
    }

    public void displayNoCreditsHours() {
        System.out.println("Number of credit hours earned: "+noCreditsHours);
    }

    public void displayNoPointsEarned() {
        System.out.println("Number of points earned: "+noPointsEarned) ;
    }

    public void displayGradePointAverage() {
        System.out.println("Grade point average: "+gradePointAverage);
    }
    //setter method for each student field
    public void setIdNumber(int idNumber) {
        IdNumber = idNumber;
    }

    public void setNoCreditsHours(int noCreditsHours) {
        this.noCreditsHours = noCreditsHours;
    }

    public void setNoPointsEarned(double noPointsEarned) {
        this.noPointsEarned = noPointsEarned;
    }
    //method to calculate grade point average
    public double computeGradePointAvg()
    {
        gradePointAverage =noPointsEarned/noCreditsHours;
        return gradePointAverage;
    }
}

ShowStudent class

public class ShowStudent {
    public static void main(String[] args) {
        //instance of student s1 is created
        Student s1 = new Student();
        //setting its fields
        s1.setIdNumber(5456);
        s1.setNoCreditsHours(4);
        s1.setNoPointsEarned(12);
        //computing grade point average
        s1.computeGradePointAvg();
        System.out.println("\nStudent s1 information: ");
        //displaying student s1 fields
        s1.displayIdNumber();
        s1.displayNoCreditsHours();
        s1.displayNoPointsEarned();
        s1.displayGradePointAverage();

        //instance of student s2 is created using default constructor
        Student s2 = new Student();
        //computing grade point average
        s2.computeGradePointAvg();
        System.out.println("\nStudent s2 information: ");
        //displaying student s2 fields
        s2.displayIdNumber();
        s2.displayNoCreditsHours();
        s2.displayNoPointsEarned();
        s2.displayGradePointAverage();
    }
}

Screen shot of the code

Screen shot of the output


Related Solutions

This is 1 java question with its parts. Thanks! Create a class named Lease with fields...
This is 1 java question with its parts. Thanks! Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name to “XXX”, the apartment number to 0, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly...
This is 1 java question with 3 parts/codes called student.java, ShowStudent.java, ShowStudent2.java. Thanks so much! Create...
This is 1 java question with 3 parts/codes called student.java, ShowStudent.java, ShowStudent2.java. Thanks so much! Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field...
Java Create a Project named Chap4b 1. Create a Student class with instance data as follows:...
Java Create a Project named Chap4b 1. Create a Student class with instance data as follows: student id, test1, test2, and test3. 2. Create one constructor with parameter values for all instance data fields. 3. Create getters and setters for all instance data fields. 4. Provide a method called calcAverage that computes and returns the average test score for an object to the driver program. 5. Create a displayInfo method that receives the average from the driver program and displays...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make...
Java Question Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the Date class to create an object for date hired. A faculty member has office hours and a rank. A...
In java: -Create a class named Animal
In java: -Create a class named Animal
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
In C# please and thanks so much, Create an Employee class with five fields: first name,...
In C# please and thanks so much, Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP a. Create a class named Student that has fields...
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP a. Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT