multiple prompting in java

Solutions on MaxInterview for multiple prompting in java by the best coders in the world

showing results for - "multiple prompting in java"
Frida
20 Oct 2018
1import java.io.Console;
2
3public class App {
4  public static void main(String[] args) {
5    Console myConsole = System.console();
6
7    Vehicle hatchback = new Vehicle(1994, "Subaru", "Legacy", 170000, 4000);
8    Vehicle suv = new Vehicle(2002, "Ford", "Explorer", 100000, 7000);
9    Vehicle sedan = new Vehicle(2015, "Toyota", "Camry", 50000, 30000);
10    Vehicle truck = new Vehicle(1999, "Ford", "Ranger", 100000, 4000);
11    Vehicle crossover = new Vehicle(1998, "Toyota", "Rav-4", 200000, 3500);
12
13    Vehicle[] allVehicles = {hatchback, suv, sedan, truck, crossover};
14
15    System.out.println("Welcome to our car dealership. What would you like to do?
16                                      Enter one of the following options: All Vehicles or Search Price");
17
18    String navigationChoice = myConsole.readLine();
19
20    if (navigationChoice.equals("All Vehicles")){
21      for ( Vehicle individualVehicle : allVehicles ) {
22          System.out.println( "----------------------" );
23          System.out.println( individualVehicle.mYear );
24          System.out.println( individualVehicle.mBrand );
25          System.out.println( individualVehicle.mModel );
26          System.out.println( individualVehicle.mMiles );
27          System.out.println( individualVehicle.mPrice );
28      }
29    } else if (navigationChoice.equals("Search Price")){
30        System.out.println("What is your maximum budget for a vehicle?");
31        String stringUserMaxBudget = myConsole.readLine();
32        int userMaxBudget = Integer.parseInt(stringUserMaxBudget);
33        System.out.println("Alright, here's what we have in your price range:");
34        for ( Vehicle individualVehicle : allVehicles ) {
35          if (individualVehicle.worthBuying(userMaxBudget)){
36            System.out.println( "----------------------" );
37            System.out.println( individualVehicle.mYear );
38            System.out.println( individualVehicle.mBrand );
39            System.out.println( individualVehicle.mModel );
40            System.out.println( individualVehicle.mMiles );
41            System.out.println( individualVehicle.mPrice );
42          }
43        }
44    } else {
45      System.out.println("I'm sorry, we don't recognize your input");
46    }
47  }
48}
49
50
similar questions
queries leading to this page
multiple prompting in java