$25
This lab is for practicing the object oriented programming, and you need to implement a Student Class and implement a simple system to modify and view user information. Use the following Coding Guidelines:
• When declaring a variable, you usually want to initialize it.
• Use white space to make your program more readable.
• Use comments after the ending brace of classes, methods, and blocks to identify to which block
Second, create a class called Lab7. Use the same setup for setting up your class and main method as you did for the previous assignments. Be sure to name your file Lab7.java. Hints
Please replace //--> with the correct program to finish the task according to the corresponding comment. Please replace ??? with the correct program to enable the program to run as required.
//import anything you need
//-->
//declare the class Lab7
//-->
//declare the main method
//-->
//Declare a scanner
//-->
// Declare a String username and an integer age for 2 different student objects //-->
// Ask user to input a username for student 1
//-->
//Scan the input to username for student 1
//-->
// Ask user to input an age for student 1
//-->>
//read the integer to age for student 1
String temp = scan.nextLine(); age = Integer.parseInt(temp);
// Repeat the above for Student 2
// Instantiate 2 Student objects using its constructor method
//-->
// Declare Constant integers Print = 0, Modify_Username = 1, Modify_Age = 2, Quit = 3
// Create an integer variable named choice.
//-->
// Create a do-while loop that exits only when the user chooses quit (choice = QUIT) // Have the do-statement here ??
{
// Print the following options:
// "This proram does the following:"
//-->
// "0. Print information:"
//-->
// "1. Modify username:"
//-->
// "2. Modify age:"
//-->
// "3. Quit"
//-->
// Read the value the user enters and store it in an integer variable <choice> temp = scan.nextLine(); choice = Integer.parseInt(temp);
// Create a switch statement with <choice> as input for the 3 cases switch(???) { case ???:
//print the String returned by toString() method of Student for student 1 //-->
//print the String returned by toString() method of Student for student 2 //-->
//After each case, don't forget to terminate it using break
//--> case ???:
//define a String variable <newName>
//-->
//Print “Enter the student number that you wish to midify: (1/2)?”
//-->
//scan the input integer and assign it to <stu_num> (based on this input you will modify the particular student’s info)
//-- >
// Print "Please input the new name:"
//-->
//scan the String and assign it to <newName>
//-->
//call setName() method of student to replace the name with new input name
//--> case mAge:
//Print “Enter the student number that you wish to midify: (1/2)?”
//-->
//scan the input integer and assign it to <stu_num> (based on this input you will modify the particular student’s info)
// -- >
//define an int variable <newAge>
//-->
// Print "Please input the new age:"
//-->
//scan the next integer and assign it to <newAge>
//-->
//call setAge() method of student to replace the name with new input name
//--> case QUIT:
// Print "You choose to quit"
//--> default:
// Print "Please choose again"
//--> } }???
}
}
Sample output:
Please input a username for student 1 wuliang
Please input an age for student 1
18
Please input a username for student 2
Lee
Please input an age for student 2
21
This program does the following:
0. Print information:
1. Modify username:
2. Modify age:
3. Quit
0
Name is :wuliang
Age is :18
Name is :Lee
Age is :21
This program does the following:
0. Print information:
1. Modify username:
2. Modify age:
3. Quit
1
Enter the student number that you wish to midify: (1/2)?: 1 Please input the new name:yoshi This proram does the following:
0. Print information:
1. Modify username:
2. Modify age:
3. Quit
0
Name is :yoshi
Age is :18
Name is :Lee
Age is :21
This proram does the following:
0. Print information:
1. Modify username:
2. Modify age:
3. Quit
2
Enter the student number that you wish to midify: (1/2)?: 2 Please input the new age:22 This proram does the following:
0. Print information:
1. Modify username:
2. Modify age: 3. Quit
0
Name is :yoshi
Age is :18
Name is :Lee
Age is :22
This proram does the following:
0. Print information:
1. Modify username:
2. Modify age: 3. Quit 5 Please choose again
This proram does the following:
0. Print information:
1. Modify username:
2. Modify age: 3. Quit 3
You choose to quit