-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDealership.java
More file actions
51 lines (45 loc) · 2.38 KB
/
Dealership.java
File metadata and controls
51 lines (45 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Dealership {
public static void main(String []arg){
Scanner scan = new Scanner (System.in);
//a simple application that uses switch statements and if-else statments for car dealership
//show options available
System.out.println("Welcome to the Java Dealership");
System.out.println("-Select option 'a' to buy a car");
System.out.println("-Select option 'b' to sell a car");
//take user input
String option = scan.nextLine();
switch (option){
//to buy a car
case "a" :System.out.println("What is your budget?");
int budget = scan.nextInt();
if(budget >= 30000){
System.out.println("Great! A Dodge charger is available");
System.out.println("\nDo you have an insurance? Write 'Yes' or 'No'");
scan.nextLine();
String insurance = scan.nextLine();
System.out.println("\nDo you have a driver's licence? 'Yes' or 'no'");
String licence = scan.nextLine();
System.out.println("\nWhat is your credit score?");
int creditScore = scan.nextInt();
if(insurance.equals("yes") && licence.equals("yes") && creditScore > 660){
System.out.println("\nSold! Pleasure doing business with you");
} else {
System.out.println("We're sorry. You are not eligible.");
}
}break;
//to sell a car
case "b" :System.out.println("\nWhat is your car valued at?");
int value = scan.nextInt();
System.out.println("\nWhat is you selling price?");
int price = scan.nextInt();
if (value > price && price < 30000){
System.out.println("\nWe will buy your car. Pleasure doing business with you!");
} else {
System.out.println("\nSorry, we are not interested.");;
}break;
default :System.out.println("Invalid option");
}
scan.close();
}
}