I wrote a switch statement that I have to put with another but I'm not sure how to. This is the one I'm trying to put with the other switch statement.
import java.util.Scanner;
public class Main
public static void main(String[] args) {
String input;
char name;
Scanner keyboard = new Scanner(System.in);
System.out.println("Are you a Customer or Owner?");
System.out.print("Press C for customer or O for owner:");
input = keyboard.nextLine();
name = input.charAt(0);
switch (name)
{
case 'C':
System.out.println("You entered customer.");
System.out.println("Welcome!");
break;
case 'O':
System.out.println("You entered owner.");
System.out.println("What would you like to do?");
break;
default:
System.out.println("That's not Customer or Owner");
}
}
}
I'm trying to put in this class
import java.util.Scanner;
public class Menu {
private Inventory database;
private char menuItem;
private Scanner input;
public Menu(Inventory database)
{
this.database = database;
menuItem = 'N';
input = new Scanner(System.in);
}
private void showMenu()
{
System.out.println();
System.out.println("------------------");
System.out.println("Display Movies : D");
System.out.println("Rent a Movie : R");
System.out.println("Reserve a Movie: S");
System.out.println("Exit : E");
System.out.println("------------------");
System.out.println();
System.out.print("Please make your selection: ");
}
private void rentMovie(int productID)
{
int index = database.getIndex(productID);
if( index == -1)
{
System.out.println("There is not such a code.");
}
else
{
if( database.getMovie(index).getIsRented())
{
System.out.println("You cannot rent " + database.getMovie(index).getTitle() + ". It is already rented.");
}
else
{
database.getMovie(index).setIsRented(true);
System.out.println("Please take your movie.");
}
}
}
private void reserveMovie(int productID)
{
int index = database.getIndex(productID);
if( index == -1)
{
System.out.println("There is not such a code.");
}
else
{
if( database.getMovie(index).getIsReserved() )
{
System.out.println("You cannot reserve " + database.getMovie(index).getTitle() + ". It is already reserved.");
}
else
{
if( database.getMovie(index).getIsRented())
{
database.getMovie(index).setIsReserved(true);
System.out.println( database.getMovie(index).getTitle() + " is reserved for you." );
}
else
{
System.out.println( database.getMovie(index).getTitle() + " is available. You can rent it if you like.");
}
}
}
}
public void run()
{
while(true)
{
switch(menuItem)
{
case 'N':
showMenu();
menuItem = input.next().charAt(0);
break;
case 'D':
database.print();
showMenu();
menuItem = input.next().charAt(0);
break;
case 'R':
System.out.print("Please enter product code:");
rentMovie( input.nextInt() );
showMenu();
menuItem = input.next().charAt(0);
break;
case 'S':
System.out.print("Please enter product code:");
reserveMovie( input.nextInt() );
showMenu();
menuItem = input.next().charAt(0);
break;
case 'E':
System.out.print("Program terminated.");
System.exit(0);
break;
default :
showMenu();
menuItem = input.next().charAt(0);
}
}
}
}