Question #26341

Write a program that determines the class of the ship depending on it's class id(identifiers).

Expert's answer

import java.util.Scanner;
public class App {
publicstatic void main(String[] args) {
System.out.print("Entership class id: ");
Scannerscanner = new Scanner(System.in);
Stringinput = scanner.next().toLowerCase();
charclassId = input.charAt(0);

switch(classId) {
case'b':
System.out.println("Battleship");
break;
case'c':
System.out.println("Cruiser");
break;
case'd':
System.out.println("Destroyer");
break;
case'f':
System.out.println("Fregate");
break;
default:
System.out.println("Unknownclass of the ship");
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS