Question

In: Computer Science

Create a class named Student. Student has fields for an ID number, number of credit hours...

Create a class named Student. Student 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. 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. Save this class as Student.java

Write a class named ShowStudent that instantiates a Student object from the class you created and assigns values to its fields. Compute the Student grade point average, and then display all the values associated with the Student. Save the application as ShowStudent.java

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. Save the application as ShowStudent2.java

Solutions

Expert Solution

Hey mate, the Java code for above program is provided below with sample output. Here, I have attached 3 Java classes saved in same package with their file name same as their class name. If you are going to run these codes in your system then ensure that all these files are saved in same folder. Do refer the screenshot of each code for proper indentation and error free execution.

Student.java

public class Student{
    int idNumber, creditHours, pointsEarned;
    float pointAverage;

    //constructor for the Student class
    public Student()
    {
        this.idNumber=9999;
        this.creditHours=3;
        this.pointsEarned=12;
    }
    
    //methods to assign values to all fields
    void setId(int id)   
    {
        this.idNumber=id;
    }

    void setCredit(int credit)
    {
        this.creditHours=credit;
    }

    void setPoints(int points)
    {
        this.pointsEarned=points;
    }
    
    //method to compute the grade point average
    void avg()  
    {
        this.pointAverage=(this.pointsEarned/this.creditHours);
    }

    //methods to display the values in each Student field
    void dispId()   
    {
        System.out.println("ID number : "+this.idNumber);
    }

    void dispCredit()
    {
        System.out.println("Number of credit hours earned : "+this.creditHours);
    }

    void dispPoints()
    {
        System.out.println("Number of points earned. : "+this.pointsEarned);
    }

    void dispAverage()
    {
        System.out.println("Grade point average : "+this.pointAverage);
    }

}

ShowStudent.java

class ShowStudent{
    public static void main(String[] args)
    {
        Student Jack=new Student();     // Jack is Student class object
        Jack.setId(2321);
        Jack.setCredit(2);
        Jack.setPoints(10);
        Jack.avg();
        Jack.dispId();
        Jack.dispCredit();
        Jack.dispPoints();
        Jack.dispAverage();
    }
}

ShowStudent2.java

class ShowStudent2{
    public static void main(String[] args)
    {
        Student Sam=new Student();     // Sam is another Student class object 
        Sam.avg();
        Sam.dispId();
        Sam.dispCredit();
        Sam.dispPoints();
        Sam.dispAverage();
    }
}

OUTPUT -

1. When ShowStudent.java is executed

2. When ShowStudent2.java is executed


Related Solutions

Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
In java, create a class named Contacts that has fields for a person’s name, phone number...
In java, create a class named Contacts that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five Contact objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. Include javadoc...
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...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color,...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly...
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 rent value and calls a static method named explainPetPolicy()...
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
Using SQL create a new database called school_app. Create a student table with fields id (auto...
Using SQL create a new database called school_app. Create a student table with fields id (auto increment), first_name, last_name. Create a course table with fields id (auto increment), course code (such as ITC or MTH), and course number (such as 100 or 295). Note that the relationship between student and course is many-to-many (n:m). Create a join table called student_course that implements the n:m relationship with fields id (auto increment), student_id, course_id, and grade (which has values 0, 1, 2,...
In Chapter 8, you created a Salesperson class with fields for an ID number and sales...
In Chapter 8, you created a Salesperson class with fields for an ID number and sales values. Now, create an application that allows a user to enter values for an array of seven Salesperson objects. Offer the user the choice of displaying the objects in order by either (I)D number or (S)ales value. ----------------------- Salesperson.java public class Salesperson {    private int id;    private double sales;    Salesperson(int idNum, double amt)    {       id = idNum;       sales = amt;    }    public int getId()...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner;...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT