-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookShop.java
More file actions
60 lines (50 loc) · 1.28 KB
/
BookShop.java
File metadata and controls
60 lines (50 loc) · 1.28 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
package books;
public class BookShop {
private final String name;
/**
* Constructor of the class Book shop
* @param name name of the book shop
*/
public BookShop(String name){
this.name = name;
}
/**
* method to compute the cost of a basket
* @param books array corresponding to the number of each harry potter book the client desire to buy (books.length should return 5)
* @return the cost in euro with the discount
*/
public double cost(int[] books){
int cost = 0;
int booksStreak = 0;
boolean noMoreBooks = false;
while(noMoreBooks == false) {
for(int i = 0, i > books.length, i++) {
if(books[i] != 0) {
books[i] = books[i] -1;
booksStreak = booksStreak + 1;
}
}
if(booksStreak = 0) {
noMoreBooks = true;
}
else if(booksStreak = 1) {
cost = cost + 8;
}
else if(booksStreak = 2) {
cost = cost + 8 * 2 * 0.93;
}
else if(booksStreak = 3) {
cost = cost + 8 * 3 * 0.86;
}
else if(booksStreak = 4) {
cost = cost + 8 * 4 * 0.72;
}
else if(booksStreak = 5) {
cost = cost + 8 * 5 * 0.65;
}
}
//TODO complete
//Takes the books and
return cost;
}
}