Step 1 Getting Started Load your previous Studentjava file f

Step 1: Getting Started: Load your previous Student.java file from your previous Lab7 java. If you do not have th Student class or did not complete Lab 7, you can download the Lab 7 solution from the Blackboard a d use the Student class provided therein as your starting point. Step 2: Add Setter methods and remove the constructor Inside the class, we have declared some data members: an integer variable called student/D, a String variable called studentMajor, a String variable firstName, a String variable lastName, an int called studentCredits, and an int called studentPoints You need to supply the following setter methods: setid(int id) to set the ID of the Student object. setMajor(String major) to set the major of the Student object setGradepoints (int points) to set the number of points of the Student object setCredits(int credits) to set the total credits of the Student object setLastName(String IName) to set the last name of the Student setFirstName(String fName) to set the first name of the student . Remember to make these setter methods void. These methods do not return any value. Hint: public void setiD(int id) These method contains a line of code that returns the desired variable value(id, major...). II write a line of code sets the id to the student\'s id public void setMajor(String major)

Solution

import java.util.*;

class Student
{
    int studentID;
    String studentMajor;
    String firstName;
    String lastName;
    int studentCredits;
    int studentPoints;
    static int numOfStudents;
  
    public void setID(int id)
    {
        studentID=id;
    }
    public void setMajor(String major)
    {
        studentMajor=major;
    }
    public void setGradePoints(int points)
    {
        studentPoints=points;
    }
    public void setCredits(int credits)
    {
        studentCredits=credits;
    }
    public void setFirstName(String fName)
    {
        firstName=fName;
    }
    public void setLastName(String lName)
    {
        lastName=lName;
    }
  
    public int getID()
    {
        return studentID;
    }
    public String getMajor()
    {
        return studentMajor;
    }
    public int getGradePoints()
    {
       return studentPoints;
    }
    public int getCredits()
    {
        return studentCredits;
    }
    public String getFullName()
    {
        return firstName+\" \"+lastName;
    }

    public void increment()
    {
        numOfStudents++;
    }
  
}  
    public class HelloWorld{

     public static void main(String []args){
       
         //variables to hold data collected form user
         String firstName,lastName,major;
         int id,credits,points;
         Student student1=new Student();
         Scanner read=new Scanner(System.in);
       
         //prompt the user to collect the details of student
         System.out.println(\"Enter first name\");
         firstName=read.next();
         System.out.println(\"Enter last name\");
         lastName=read.next();
         System.out.println(\"Enter student id\");
         id=read.nextInt();
         System.out.println(\"Enter student major\");
         major=read.next();
         System.out.println(\"Enter the number of credits entered by the student\");
         credits=read.nextInt();
         System.out.println(\"Enter student\'s number of points\");
         points=read.nextInt();
       
         //call setter of student class to set values
         student1.setFirstName(firstName);
         student1.setLastName(lastName);
         student1.setMajor(major);
         student1.setCredits(credits);
         student1.setGradePoints(points);
         student1.setID(id);
         student1.increment();
       
         //display student info.
       
         System.out.println(\"STUDENT INFORMTAION\ \");
         System.out.println(\"The name of student is :\"+student1.getFullName());
         System.out.println(\"The student id number is :\"+student1.getID());
         System.out.println(\"Major is :\"+student1.getMajor());
         System.out.println(\"The student\'s number of points is :\"+student1.getGradePoints());
         System.out.println(\"Number of earned credits is :\"+student1.getCredits());
       
         //call increment() on all objects
         Student student2=new Student();
         student2.increment();
         Student student3=new Student();
         student3.increment();
       
         //display numofStudent variable on different objects
         System.out.println(\"\ \");
         System.out.println(\"Student1: number of students= \"+student1.numOfStudents);
         System.out.println(\"Student2: number of students= \"+student2.numOfStudents);
         System.out.println(\"Student3: number of students= \"+student3.numOfStudents);
       
       
     }
}

 Step 1: Getting Started: Load your previous Student.java file from your previous Lab7 java. If you do not have th Student class or did not complete Lab 7, you
 Step 1: Getting Started: Load your previous Student.java file from your previous Lab7 java. If you do not have th Student class or did not complete Lab 7, you
 Step 1: Getting Started: Load your previous Student.java file from your previous Lab7 java. If you do not have th Student class or did not complete Lab 7, you

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site