Question

Add additional information to the student class below such as name, address, major, and contact information...

Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static void main (String args[]) { Student pupil = new Student(); // We need a new student named pupil pupil.setIDnumber(234); // We are setting pupil's ID number to 234 pupil.setPoints(47); // We are setting pupil's points to 47 pupil.setHours(15); // We are setting pupil's hours to 15 pupil.showIDnumber(); // We are showing pupil's ID number pupil.showPoints(); // We are showing pupil's points pupil.showHours(); // We are showing pupil's hourse System.out.println("The grade point average is " + pupil.getGradePoint()); // we are calculating pupil's GPA } } class Student // this is the student class { // the private data members private int idNumber; private int hours; private int points; // Constructor creates a new student Student() { idNumber = 9999; // a max ID points = 12; // starting out assuming 12 points hours = 3; // starting out assuming 3 hours } // end of constructor // the public get and set methods fro pulil specific information public void setIDnumber(int number) // pass in a number { idNumber = number; // assign the number } public int getIDnumber() // return a student ID { return idNumber; } public void setHours(int number) // pass in a number { hours = number; // assign the number to hours } public int getHours() // return the student's hours { return hours; } public void setPoints(int number) // pass in a number { points = number; // assign number to points } public int getPoints() // return the points { return points; } // methods to display the fields public void showIDnumber() { System.out.println("ID Number is: " + idNumber); } public void showHours() { System.out.println("Credit Hours: " + hours); } public void showPoints() { System.out.println("Points Earned: " + points); } public double getGradePoint() // calculate the GPA with internal data { return (points * 1.0 / hours); // simple integer division will truncate the decimal places } } pls answer the stratery, code I can do but about statregy I dont know how

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

check out the solution and let me know if any doubts/changes required through COMMENTS.

------------------------------

// ShowStudent.java

class Student { // this is the student class
// the private data members
private int idNumber;
private int hours;
private int points;
// additional information are added as below
private String name;
private String address;
private String major;
private int contact;
  
// Constructor creates a new student
Student() {
idNumber = 9999; // a max ID
points = 12; // starting out assuming 12 points
hours = 3; // starting out assuming 3 hours
// additional information added
name = ""; // assuming blank
address = "";
major = "M1"; // assuming major as "M1"
contact = 000; // default contact number
} // end of constructor
// the public get and set methods fro pulil specific information
public void setIDnumber(int number) { // pass in a number
idNumber = number; // assign the number
}
public int getIDnumber() { // return a student ID
return idNumber;
}
public void setHours(int number) { // pass in a number
hours = number; // assign the number to hours
}
public int getHours() { // return the student's hours
return hours;
}
public void setPoints(int number) { // pass in a number
points = number; // assign number to points
}
public int getPoints() { // return the points
return points;
}
// methods to display the fields
public void showIDnumber() {
System.out.println("ID Number is: " + idNumber);
}
public void showHours() {
System.out.println("Credit Hours: " + hours);
}
public void showPoints() {
System.out.println("Points Earned: " + points);
}
public double getGradePoint() { // calculate the GPA with internal data
return (points * 1.0 / hours); // simple integer division will truncate the decimal places
}
// setters and getters of addtional information
public void setName(String n) { // pass in a string
name = n; // assign that string to name
}
public String getName() { // return the name
return name;
}
public void setAddress(String addr) { // pass in a string
address = addr; // assign string to address
}
public String getAddress() { // return the address
return address;
}
public void setMajor(String mjr) { // pass in a string
major = mjr; // assign string to major
}
public String getMajor() { // return the major
return major;
}
public void setContact(int phone) { // pass in a number
contact = phone; // assign number to contact
}
public int getContact() { // return the contact
return contact;
}
} // class student ends

// client to test the Student class
public class ShowStudent {
public static void main (String args[]) {
Student pupil = new Student(); // We need a new student named pupil
pupil.setIDnumber(234); // We are setting pupil's ID number to 234
pupil.setPoints(47); // We are setting pupil's points to 47
pupil.setHours(15); // We are setting pupil's hours to 15 pupil.
  
// addition info method calls using the student object 'pupil'
// setters
pupil.setName("abc");
pupil.setAddress("Add1");
pupil.setMajor("M3");
pupil.setContact(1234567890);
// getters
System.out.println("Name : " + pupil.getName());
System.out.println("Address : " + pupil.getAddress());
System.out.println("Major : " + pupil.getMajor());
System.out.println("Contact number : " + pupil.getContact());
  
pupil.showIDnumber(); // We are showing pupil's ID number
pupil.showPoints(); // We are showing pupil's points
pupil.showHours(); // We are showing pupil's hourse
// truncated the result by 3 decimal digits after decimal point using 'printf' and format specifier '%.3f'
System.out.printf("The grade point average is %.3f", pupil.getGradePoint()); // we are calculating pupil's GPA
}
}
-----------------------------------

--------------

OUTPUT ::

Add a comment
Know the answer?
Add Answer to:
Add additional information to the student class below such as name, address, major, and contact information...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Add additional information to the student class below such as name, address, major, and contact information...

    Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...

  • Write a program in Java that prompts a user for Name and id number. and then...

    Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main {    public static void main(String[] args) {                       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);        String name = thedata;        Student pupil = new Student(name);                   //add code here       ...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • Given a class called Student and a class called Course that contains an ArrayList of Student....

    Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{     /** collection of Students */     private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...

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

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • Classes A Customer Points class maintains information about a customer. This information is the customer name...

    Classes A Customer Points class maintains information about a customer. This information is the customer name (entire name as a String) and the amount of points (as an int) the customer has accrued. Methods: Constructor: Receives a name and sets the name field to the received name and sets the points field to 0 (zero). getName: Returns the customer's name getPoints: Returns the customer's current points toString: Returns a String representation of the current state in the form-name points, i.e....

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