fork download
  1. import java.util.Scanner;
  2. class Car{
  3. void RedCar(){
  4. System.out.println("You choosed : Ferrari");
  5. }
  6. void BlueCar(){
  7. System.out.println("You choosed : BMW");
  8. }
  9. public static void main(String[] args){
  10. Scanner scanner = new Scanner(System.in);
  11. Car AllCar = new Car();
  12. //System.out.println("Which car do you want? (red / blue): ");
  13. String option = scanner.nextLine();
  14. if(option.equalsIgnoreCase("red")){
  15. AllCar.RedCar();
  16. }else if(option.equalsIgnoreCase("blue")){
  17. AllCar.BlueCar();
  18. }else{
  19. System.out.println("Invalid choice. Please type 'red' or 'blue'.");
  20. }
  21. scanner.close();
  22. }
  23. }
Success #stdin #stdout 0.12s 56680KB
stdin
blue
stdout
You choosed : BMW