Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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: // Major: // Grade Points: // Credits: // Change just the student's major to "International Affairs" // by calling the changeMajor method //--> // Print out the following for the first student: // has changed majors to //--> ///print out the information for the second student //the output should look like this: // FIRST STUDENT INFORMATION // Name: // Major: // Grade Points: // Credits: System.out.println("STUDENT HELPER FUNCTIONS"); System.out.println("Iterate from 1 till 30 with 3 steps and find sum"); studenti. loopHelper (1, 30, 3); System.out.println("Iterate from 5 till 28 with 2 steps and find sum student2.loopHelper(5, 28, 2); Step 7: Sample Output ASU Home My ASU College Below is an example of what your output should roughly look like when this lab is completed. All text in bold red represents user input. Sample Run: ENTER FIRST STUDENT INFORMATION Enter first name: John Enter last name: Terry FIRST STUDENT INFORMATION Name: Jonh Terry Major: General Studies Grade Points: 0 Credits: 0 Jonh Terry has changed majors to International Affairs ENTER FIRST STUDENT INFORMATION Enter first name: Ada Enter last name: Lovelace Enter your major: Electrical Engineering Enter your grade Points: 100 Enter your total credits: 345 SECOND STUDENT INFORMATION Name: Ada Lovelace Major: Electrical Engineering Grade Points: 100 Credits: 345 STUDENT HELPER FUNCTIONS Iterate from 1 till 30 with 3 steps and find sum 1 4 7 10 13 16 19 22 25 28 Sum is 145 ASU HOTTE IVY ASULUllege STUDENT HELPER FUNCTIONS Iterate from 1 till 30 with 3 steps and find sum 1 4 7 10 13 16 19 22 25 28 Sum is 145 Iterate from 5 till 28 with 2 steps and find sum 5 7 9 11 13 15 17 19 21 23 25 27 Sum is 192 Last Step: Submit your work by the end of lab by following the instructions below: 1. Upload and submit vour Lab8.java file here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What was the positive value of Max Weber's model of "bureaucracy?"

Answered: 1 week ago