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
- 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( );
}
}
Step by Step Solution
3.45 Rating (164 Votes )
There are 3 Steps involved in it
Step: 1
Following is a java program as per the requirement public class problemfour public static void print...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started