Question

In: Computer Science

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 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.

b. Write a class named ShowStudent that instantiates a Student object from the class you created and assign 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.

c. 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

A) Student.java

import.java.util.*;

Public class Student

{

int sid;

int credithours;

int point;

double averagegarde;

//constructor to assign intial values

public student()

{

this.sid = 9999;

this.credithours = 3;

this.points=12;

}

//method to assign values to all fields

public void setCredithours (int credithours)

{

this. credithours =credithours;

}

public void setPoints (int points)

{

this. points =points;

}

public void setSid (int sid)

{

this. sid=sid;

}

//method to compute the grade point average field by dividing points by credit hours earned

public void compute Averagegrade()

{

this.averagegrade = this.points/ this.credithourse;

}

// method to display the values in each student filed

public void showSid()

{

System.out.println("Student id is : " + this.sid);

}

public void showPoints()

{

System.out.println("Number of points earned : " + this.points);

}

public void showCredithours()

{

System.out.println("Number of credithours earned : " + this.credithours);

}

public void showAveragegrade()

{

System.out.println("Averagegrade point: " + this.averagegrade);

}

}

B)ShowStudent.java.

import.java.util.*;

public class ShowStudent

{

public static void main(String[ ] args)

{

//create student object

Student student1 = new Student();

//set student parameters

student1. setCredits(4);

student1.setID(1);

student1.setPoints(4);

//calculate GPA and assign to variable

double gradepoint = student1.calculateGPA( student1.getPoints(), student1.getCredits());

System.out.println("Student ID: " +student1.getID());

System.out.println("Number of credits: " +student1.getCredits());

System.out.println("Number of points: " +student1.getPoints());

System.out.println("GPA: " + gradepoint);

}

}

C)ShowStudent2.java.

// here's the student class

import.java.util.*;

public class Student

{

private int ID;

private int creditHours;

private int pointsEarned;

double GPA;

public Student()

{

}

public Student(int id, int hrs, int pts)

{

ID=id;

creditHours=hrs;

pointsEarned=pts;

}

public double getGPA()

{

return GPA;

}

public void setGPA()

{

GPA = (double)pointsEarned / creditHours;

}

public void setID(int number)

{

ID = number;

}

public int getID()

{

return ID;

}

public void setCreditHours(int hours)

{

creditHours = hours;

}

public int getcreditHours()

{

return creditHours;

}

public void setPointsEarned(int points)

{

pointsEarned points;

}

public int getPointsEarned()

{

return pointEarned;

}

}


Related Solutions

PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP i am getting an error messge a. Create a...
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP i am getting an error messge a. Create a class named Sandwich. Data fields include a String for the main ingredient (such as tuna), a String for bread type (such as wheat), and a double for price (such as 4.99). Include methods to get and set values for each of these fields. Save the class as Sandwich.java. b. Create an application named TestSandwich that instantiates one Sandwich object and demonstrates the use of...
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...
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 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...
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
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...
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
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...
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...
In java: -Create a class named Animal
In java: -Create a class named Animal
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT