Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Employee first name Sting last name Sring agent base salary double dressAddress

ID: 3885510 • Letter: E

Question

Employee first name Sting last name Sring agent base salary double dressAddress 1 Address Assignment -streetName Saring city Saring state Saring Taipcode int main Serinon) void printMenuvoid +Employee o +Saring setNameo Saring getSalary +Additess getAddress) void setNameString string) void avoid seAgeGiot void setBase salary double) avoid setAddress string string string int) to Stine0 Saring Address Address string Sarine String int) + void changeAiress(Saring Sains. Starting int - Saring to Sarine0

Explanation / Answer

Assuming you have already implemented Employee and Address classes. I am providing only switch case statements.

package assnmnt4;

import java.util.Scanner;

public class Assignment4

{

public static void main (String[] args)

{

// local variables, can be accessed anywhere from the main method

char choice = 'Q';

String line = new String();

// instantiate a Employee object

Employee e1 = new Employee();

//Create a Scanner object to read user input

Scanner scan = new Scanner(System.in);

do // will ask for user input

{

System.out.print("What action would you like to perform? ");

printMenu();

line = scan.nextLine();

if (line.length() == 1)

{

// get the choice as a character

choice = line.charAt(0);

choice = Character.toUpperCase(choice);

// matches one of the case statement

switch (choice)

{

case 'A': //Add an employee

/*read first_name, last_name, age, address, base salary

then call the appropriate methods of the employee instance e1 to

set those values */

System.out.println("Enter First Name: ");

String fnm=scan.nextLine();

System.out.println("Enter Last Name: ");

String lnm=scan.nextLine();

System.out.println("Enter age: ");

int ag=scan.nextInt();

System.out.println("Enter Street Name: ");

String snm=scan.nextLine();

System.out.println("Enter City Name: ");

String city=scan.nextLine();

System.out.println("Enter State Name: ");

String state=scan.nextLine();

System.out.println("Enter Zipcode: ");

String zip=scan.nextLine();

System.out.println("Enter base salary: ");

double sal=scan.nextDouble();

e1.setFirst_name(fnm);

e1.setLast_name(lnm);

e1.setAge(ag);

e1.setAddress(snm,city,state,zip);

e1.setBaseSalary(sal);

break;

case 'D': //Display Employee

System.out.print(e1);

break;

case 'C': // change address

/* read street name, city, state, zipcode and call appropriate

methods of e1 to change the address */

System.out.println("This is your current Address :");

Address addr=e1.getAddress();

System.out.println("Strret Name: "+addr.getStreetName());

System.out.println("City Name: "+addr.getCity());

System.out.println("State Name: "+addr.getState());

System.out.println("ZipCode: "+addr.getZipcode());

System.out.println("Enter Street Name: ");

snm=scan.nextLine();

System.out.println("Enter City Name: ");

city=scan.nextLine();

System.out.println("Enter State Name: ");

state=scan.nextLine();

System.out.println("Enter Zipcode: ");

zip=scan.nextLine();

e1.setAddress(snm,city,state,zip);

break;

case 'Q': //Quit

break;

case '?': //Display Menu

printMenu();

break;

default:

System.out.print("Unknown action ");

break;

}

}

else

{

System.out.print("Unknown action ");

}

} while (choice != 'Q');

}

/** The method printMenu displays the menu to a user **/

public static void printMenu()

{

System.out.print("Choice Action " +

"------ ------ " +

"A Add an Employee " +

"D Display an Employee Info " +

"C Change Address " +

"Q Quit " +

"? Display Menu Again ");

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote