Question

In: Computer Science

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

Solutions

Expert Solution

Hi,

Hope you doing fine. I have coded the above question in java keeping all the conditions in mind. The code is explained clearly using comments that have been highlighted in bold. Note that I have named my file as Student1.java as I already had another file called Student.java. You may name the file as per your convenience. Also, pleae note that the file name and class name must be same. I have written an additional class called Test (Test.java) which contains main() and is used to show the output of Student1 class.

Program:

Student1.java


public class Student1 {
  
   //declaring instance variables
   int ID;
   int credit_hrs;
   int num_of_pts;
   //considering gpa in double as it is the average
   double gpa;
  
   //method to set ID
   public void setID(int iD) {
       ID = iD;
   }
   //method to set the value of credit_hrs
   public void setCredit_hrs(int credit_hrs) {
       this.credit_hrs = credit_hrs;
   }
   //method to set the value of num_of_pts
   public void setNum_of_pts(int num_of_pts) {
       this.num_of_pts = num_of_pts;
   }
   //method to calculate and set the gpa
   public void calculate_Gpa() {
       //gpa is calculated by dividing the number of pts by the credit hrs earned
       this.gpa=(double)num_of_pts/credit_hrs;
   }
   //method to print value of ID
   public void getID() {
       System.out.println("ID: "+ID);
   }
   //method to print credit_hrs
   public void getCredit_hrs() {
       System.out.println("Credit hours: "+credit_hrs);
   }
   //method to print num_of_pts
   public void getNum_of_pts() {
       System.out.println("Number of points earned: "+num_of_pts);
   }
   //method to print gpa
   public void getGpa() {
       System.out.println("Grade point average: "+gpa);
   }

}

Program:

Test.java

import java.util.Random;

public class Test {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       //creating new object for Student
       Student1 s=new Student1();
       //setting the values of ID, credit_hrs and num_of_pts
       s.setID(1);
       s.setCredit_hrs(3);
       s.setNum_of_pts(12);
       //calculating gpa
       s.calculate_Gpa();
       //displaying all values
       s.getID();
       s.getCredit_hrs();
       s.getNum_of_pts();
       s.getGpa();

   }

}

Executable code snippets:

Student1.java

Test.java

Output:


Related Solutions

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...
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...
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 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()...
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....
Question 1 (10) Create a class Student with public member variables: Student name, student number, contact...
Question 1 (10) Create a class Student with public member variables: Student name, student number, contact number, ID number. The following specifications are required:  Add init() method of the class that initializes string member variables to empty strings and numeric values to 0. (2)  Add the method populate() to the class. The method is used to assign values to the member variables of the class. (2)  Add the method display() to the class. The method is used...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT