-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrarySystem.java
More file actions
73 lines (57 loc) · 2.69 KB
/
LibrarySystem.java
File metadata and controls
73 lines (57 loc) · 2.69 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.Scanner;
public class LibrarySystem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] books = {"Java", "Python", "C++", "HTML", "CSS", "JS"};
double[] prices = {300.0, 250.0, 200.0, 150.0, 100.0, 50.0};
int[] stocks = {5, 0, 3, 2, 1, 0};
System.out.println("Welcome to Elramly Library");
System.out.print("Please enter the book name: ");
String bookName = input.nextLine();
for (int i = 0; i < books.length; i++) {
if (books[i].equalsIgnoreCase(bookName)) {
System.out.println("The book exists. Original price: " + prices[i]);
if (stocks[i] == 0) {
System.out.println("Sorry, the book is currently not available.");
input.close();
return;
}
double finalPrice = prices[i] * 0.9;
System.out.println("Price after 10% discount: " + finalPrice);
System.out.print("Do you want delivery? Yes -> 1, No -> 0: ");
int delivery = input.nextInt();
if (delivery == 1) {
finalPrice += 50;
System.out.println("Delivery fees have been added.");
}
System.out.println("Final price: " + finalPrice + "$");
System.out.print("Do you want to buy a song? Yes -> 1, No -> 0: ");
int accept = input.nextInt();
if (accept == 1) {
System.out.println("Which song do you want?");
System.out.println("1. Amr Diab - 20$");
System.out.println("2. Tamer Hosny - 30$");
System.out.println("3. George Wassouf - 50$");
int choice = input.nextInt();
if (choice == 1) {
System.out.println("Your choice is Amr Diab.");
finalPrice += 20;
} else if (choice == 2) {
System.out.println("Your choice is Tamer Hosny.");
finalPrice += 30;
} else if (choice == 3) {
System.out.println("Your choice is George Wassouf.");
finalPrice += 50;
} else {
System.out.println("Invalid song choice.");
}
System.out.println("Final price including selected song: " + finalPrice);
}
input.close();
return;
}
}
System.out.println("Sorry, invalid book name.");
input.close();
}
}