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

  • Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d();...

    Correct the mistakes public class customer { public static void main(String[] args) { D customer=new d(); d.employee(56,”ali”); d.department(7,8.6,9); } public void employee(String name, int age) { System.out.println("Your name is"+name); System.out.println(“Age is”+age); } public int department(double d, double t, int a) { System.out.println("I have java exam at 3:00"); Return(1.1); } } V. PROGRAMMING. Write a complete JAVA program to implement the following. 1. Create a class named Exponent. Its main() method accepts an integer value from a user at the keyboard,...

  • 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 a base class named Book. Data fields include title and author; functions include those that...

    Create a base class named Book. Data fields include title and author; functions include those that can set and display the fields. Derive two classes from the Book class: Fiction, which also contains a numeric grade reading level, and NonFiction, which contains a variable to hold the number of pages. The functions that set and display data field values for the subclasses should call the appropriate parent class functions to set and display the common fields, and include specific code...

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

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