Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem Description: For this Lab you have to implement a class Student. Student class should have instance variables student Major, firstName, lastName, studentCredits, and studentPoints.
Problem Description: For this Lab you have to implement a class Student. Student class should have instance variables student Major, firstName, lastName, studentCredits, and studentPoints. For Student class, supply two constructors and the following methods: getMajor(), getGradepoints(), getCredits(), getFullName(), loopHelper(int start, int end, int incy). Step 1: Getting Started Create a class called Lab8. Use the same setup for setting up your class and main method as you did in previous labs and assignments. Be sure to name your file Lab8.java. Assignment Documentation: At the beginning of each programming assignment you must have a comment block with the following information: // ---------- // AUTHOR: your name // FILENAME: title of the source file // SPECIFICATION: description of the program // FOR: CSE 110- Lab #8 // TIME SPENT: how long it took you to complete the assignment //-------- - - -- Step 2: Create a Separate Student.java file and define a Student Class ASU Home My ASU College Examining the problem, we need to create a Student class, declare Student class as follows public class Student{ Inside the class, declare some data members: a String variable called studentMajor, a String variable firstName, a String variable lastName, an int called studentCredits, and an int called studentPoints. // declare instance variables... // a string called studentMajor //--> // an int called studentCredits //--> // an int called studentPoints //--> // a string called firstName //--> // a string called lastName //--> ASU Home My ASU College Step 3: Defining the constructors: Remember the constructor with arguments assigns input data to the data members. In this case, we have an example of constructors overloading. If user provides only first name and last name, then Constructor 1 is being called and rest of variables are initialized to default values, if user provides all variables, then Java calls Constructor 2 Constructor 1: public Student (String fName, String lName) { // write code that assigns fName and Lname to appropriate instance variables. //-> // The rest of variables are initialized to default values this.studentMajor = "General Studies"; this.studentPoints = 0; this.studentCredits = 0; Constructor 2 public Student (String major, int credits, int points, String fName, String IName) { // write code that assigns input data to the data members //-> Step 4: Supply the methods ASU Home My ASU College: You need to supply the following get methods: getMajor() to get the major of the Student object. getGradepoints() to get the number of points of the Student object. getCredits() to get the total credits of the Student object. getFullName() to get the full name of the Student. changeMajor(String new Major) to change the student's major loopHelper(int start, int end, int incBy) to print sequence of number with given starting point, end point and increment integer. Hint: Getter methods generally contain a line of code that returns the desired value, which is often stored in a private instance variable value. public String getMajor() { // write a line of code that returns the student major //-> public int getGradepoints () { // write a line of code that returns the student grade points //-> public int getCredits() { // write a line of code that returns the student total credits //-> public String getFullName() { ASU Home My ASU College public String getFullName() { // write a line of code that returns the full name. //-> Also, you should have a changeMajor method. The method will take only a string and will change the Student object's major variable to the new input. public void changeMajor (String newMajor) { // Change the value of the Student object's major // variable to the new input's value. //-> you should have a loopHelper method. Given a start integer, end integer and incBy integer, it will print sequence starting from start till end, incremented by given incBy integer. See example below. public void loopHelper(int start, int end, int incBy) { int sum = 0; // write a for loop that uses given parameters (start and end) // and prints a sequence of numbers and summation // For Example: Calling studenti.loopHelper(1, 10, 3); where start is 1, end is 10 and increment by 3, // We print the following: // 1 4 7 10 // Sum is 22 Step 5: Calling the constructor of Student class from the main method. ASU Home My ASU Colleg Your Lab8 class will have the main method. You will instantiate and use a Student class object. public class Lab8 { public static void main(String[] args) { //declare variables where you will store //inputs from user //--> // declare and instantiate a Scanner object //--> //prompt the user for inputs for first student //firstName and lastName // store the input in the declared variables //--> //call the constructor with two arguments //to instantiate a brand-new Student object //and assign this object to a variable named called Student1 //--> //prompt the user for inputs for second student //studentMajor, studentCredits, studentGradePoints, firstName, and lastName //--> //store the input in the declared variables //--> //call the constructor that takes 5 arguments //to create a brand-new Student object //and assign this object to a variable named called Student2 //--> Step 6: Calling Student class methods and display the output ASU Home My ASU College Do the following in the main method of your Lab8 class. //print out the information for the first student //the output should look like this: // FIRST STUDENT INFORMATION // Name:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started