Given the following program that takes as input the first name of a person and using a
Question:
- Given the following program that takes as input the first name of a person and using a switch statement, prints the first and last name together if a match has been found.
publicclass problemOne {
publicstaticvoid main(String[]args) {
//TODO Auto-generated method stub
name = "Maya";
switch(name) {
case"Krishna" : System.out.println(name +" Kadiyala");
break;
case"Jason": System.out.println(name +" More");
break;
case"Maya": System.out.println(name +" Angie");
break;
case"Fred": System.out.println(name +" Simpson");
break;
case"Michael" : System.out.println(name +" Douglas");
break;
case"Winnie" : System.out.println(name +" The Pooh");
break;
}
Now, re-write the above program such that I pass the variable "name" as an argument to the method printName(). The printName() method will receive the input and use the same exact switch statement to print the first and last names together. You can use the following code as the started code but complete the method header, method body and how the method is called in main:
publicclass problemfour {
publicstatic______ printLastname( ) {
}
}
publicstaticvoid main(String[]args) {
//TODO Auto-generated method stub
name = "Maya";
printLastname( );
}
}
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser