Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Following is a java program as per the requirement public class problemfour public static void print... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Structures and Algorithms in Java

Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

6th edition

1118771334, 1118771338, 978-1118771334

Students also viewed these Programming questions

Question

c. Are there any prerequisites for the course?

Answered: 1 week ago