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
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...
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...
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...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT