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...
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...
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...
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...
In java: -Create a class named Animal
In java: -Create a class named Animal
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...
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! 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....
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT