-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
44 lines (34 loc) · 1.21 KB
/
Main.java
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int kilometer, pricePerKilometer = 10, total, age;
boolean isReturnIncluded;
// Prompt the user to enter the distance
System.out.print("Enter the distance: ");
kilometer = scanner.nextInt();
// Prompt the user to enter whether return is included
System.out.print("Is return included? (true/false): ");
isReturnIncluded = scanner.nextBoolean();
total = kilometer * pricePerKilometer;
// Multiply the total by 2 if return is included
if (isReturnIncluded) {
total *= 2;
}
// Prompt the user to enter their age
System.out.print("Enter your age: ");
age = scanner.nextInt();
// Apply discount based on age
if (age < 12) {
total *= 0.5;
} else if (age < 24) {
total *= 0.9;
} else if (age > 65) {
total *= 0.7;
}
// Output the total price
System.out.println("Total: " + total + " TL");
// Close the scanner to release resources
scanner.close();
}
}