Question

Graded Exercise Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and numbe

0 3
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

import java.util.Scanner;

class Student {
   private String ID;
   private int numberOfCredits;
   private int points;
   private double gradePoint;

   public Student() {
   }

   // constructor to initialize the values
   public Student(String aID, int aNumberOfCredits, int aPoints) {
       super();
       ID = aID;
       numberOfCredits = aNumberOfCredits;
       points = aPoints;
       calculateGradePoint();
   }

   // getters and setters
   public String getID() {
       return ID;
   }

   public void setID(String aID) {
       ID = aID;
   }

   public int getNumberOfCredits() {
       return numberOfCredits;
   }

   public void setNumberOfCredits(int aNumberOfCredits) {
       numberOfCredits = aNumberOfCredits;
   }

   public int getPoints() {
       return points;
   }

   public void setPoints(int aPoints) {
       points = aPoints;
   }

   // to return object in String representation form
   @Override
   public String toString() {
       return "ID : " + ID + " NumberOfCredits : " + numberOfCredits + " Points : " + points + " Grade Point : "
               + gradePoint;
   }

   // method to find gradePoint
   public void calculateGradePoint() {
       gradePoint = points / (double) numberOfCredits;
   }
}

public class ShowStudent2 {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter Id");
       String Id = sc.next();
       System.out.println("Enter number of credits: ");
       int cs = sc.nextInt();
       System.out.println("Enter number of points: ");
       int p = sc.nextInt();
       Student s = new Student(Id, cs, p);
       System.out.println(s);
   }
}

Enter Id 123 Enter number of credits: 4 Enter number of points: 12 ID 123 NumberOfCredits : 4 Points : 12 Grade Point : 3.0

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Graded Exercise Create a class named Student. A Student has fields for an ID number, number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Create a class named Student, where each Student consists of a student id (a number between...

    Create a class named Student, where each Student consists of a student id (a number between 0 and 99999), grade level (1-12), and a full name. Include set and get methods for all fields. Save this as Student.java. Then, write an application that declares a Student object and prompts the user for the three required pieces of information, one at a time. For student id, keep prompting until the user enters a valid number (0-99999). Likewise, keep prompting for a...

  • Create a class named Book that contains data fields for the title and number of pages....

    Create a class named Book that contains data fields for the title and number of pages. Include get and set methods for these fields. Next, create a subclass named Textbook, which contains an additional field that holds a grade level for the Textbook and additional methods to get and set the grade level field. Write an application that demonstrates using objects of each class. Save the files as Book.java, Textbook.java, and DemoBook.java.

  • 1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and...

    1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and onion) and price. include a constructor fhay requires arguments for borh fields ans a method to diplay the data. Create a subclass names DelicedPizza that inherits from Pizza bit adds a delivery fee and a delicery address. The description, price, and delicery address are required as arguments to the constructor. The delivery fee is $3 if the pizza ordered cost more that $15; otherwise...

  • Create an abstract Student class for Parker University. The class contains fields for student ID number,...

    Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for...

  • a) Create an abstract class Student. The class contains fields for student Id number, name, and...

    a) Create an abstract class Student. The class contains fields for student Id number, name, and tuition. Includes a constructor that requires parameters for the ID number and name. Include get and set method for each field; setTuition() method is abstract. b) The Student class should throw an exception named InvalidNameException when it receives an invalid student name (student name is invalid if it contains digits). c) Create three student subclasses named UndergradStudent, GradeStudent, and StudentAtLarge, each with a unique...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 21...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...

    C++ Visul Studio Create a class named Vehicle. The class has the following five member variables: • Vehicle Name • Vehicle number • Sale Tax • Unit price • Total price Include set (mutator) and get (accessor) functions for each field except the total price field. The set function prompt the user for values for each field. This class also needs a function named computePrice() to compute the total price (quantity times unit price + salesTax) and a function to...

  • a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number,...

    a. 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. "XXX", the apartment number to O, 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...

  • Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email...

    Create a Business class: Instance variables: Student id 1000 - 9999 Student name Present Student email address Present Number of hours 3.5 - 18 Two constructors should be coded, one that accepts no arguments and sets every field to its default value, and one that accepts all four fields, and assigns the passed values into the instance variables. For each instance variable create two methods; a getter and a setter. Add a static method to the class that will accept...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT