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

  1. 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

1 Expert Approved Answer
Step: 1 Unlock

Following is a java program as per the requirement public class problemfour public static void print... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!