CSE 110 – Lab 7
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 it belongs.
Assignments Documentation:
At the beginning of each programming assignment you must have a comment block with the
following information:
/*—————————————————————————
// AUTHOR:
// FILENAME:
// SPECIFICATION:
// You need to develop the setName() method of Student Class and construct a simple system // that can manage a student’s name and age
// LAB LETTER: (Put your Lab Letter here) //————————————————————————- */
Getting Started
This lab is different from the previous ones. You are asked to use two Java files. First make Student class. The following is a template to make a class.
(Put your name here) Lab7.java
This program is for practicing the object oriented programming.
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
Age is
Name is
Age is
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 Age is Name is Age is
:yoshi :18
:Lee
:21
:wuliang :18
:Lee
: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
Age is
Name is
Age is
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
:yoshi :18
:Lee
:22






