Skip to content

Commit 9ea7333

Browse files
author
Sarah Akinkunmi
committed
tryout
1 parent 7afbaa7 commit 9ea7333

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
package chapter11.beansbusiness;
22

33
public class BuyBeans {
4-
public BuyBeans() {
4+
private int quantity;
5+
private double amount;
56

7+
public BuyBeans() {}
8+
9+
public BuyBeans(int quantity, double amount) {
10+
this.quantity = quantity;
11+
this.amount = amount;
612
}
713

8-
public BuyBeans(int quantity, int amount, boolean hasFakeMoney, boolean has ) {
14+
public int getQuantity() {
15+
return quantity;
16+
}
917

18+
public void setQuantity(int quantity) {
19+
this.quantity = quantity;
1020
}
1121

22+
public double getAmount() {
23+
return amount;
24+
}
1225

26+
public void setAmount(double amount) {
27+
this.amount = amount;
28+
}
1329
}
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
package chapter11.beansbusiness;
22

3+
import java.util.Scanner;
4+
35
public class ClientCode {
46
public static void main(String[] args) {
5-
BuyBeans buyBeans = new BuyBeans();
6-
Messenger michael = new Messenger();
7+
Scanner scanner = new Scanner(System.in);
8+
System.out.println("""
9+
Enter 1 for full pack
10+
Enter 2 for half pack
11+
""");
12+
int quantity = scanner.nextInt();
13+
if(quantity < 1 || quantity > 2) {
14+
throw new IllegalArgumentException("Beans amount should be either 1 or 2");
15+
}
16+
17+
double fullPackEstimate = 300;
18+
double halfPackEstimate = 150;
19+
20+
BuyBeans buyBeans = new BuyBeans(quantity, 0);
21+
22+
if(quantity == 1) {
23+
buyBeans.setAmount(fullPackEstimate);
24+
} else buyBeans.setAmount(halfPackEstimate);
25+
26+
Messenger michael = new Messenger(0);
27+
michael.setAmount(buyBeans.getAmount());
28+
michael.isMoneySufficient();
729
}
830
}
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
package chapter11.beansbusiness;
22

3+
import chapter11.beansbusiness.exceptions.MoneyException;
4+
5+
import java.util.Scanner;
6+
37
public class Messenger {
4-
public Messenger() {
8+
private double amount;
9+
10+
public Messenger(double amount) {
11+
this.amount = amount;
12+
}
13+
14+
public double getAmount() {
15+
return amount;
16+
}
517

18+
public void setAmount(double amount) {
19+
this.amount = amount;
620
}
7-
public Messenger(int amount, boolean hasPack) {
821

22+
public void isMoneySufficient() {
23+
Scanner scanner = new Scanner(System.in);
24+
System.out.println("How much beans will fill this pack?");
25+
double fillPack = scanner.nextDouble();
26+
if(fillPack <= amount) {
27+
System.out.println("Your hot beans is here!");
28+
} else throw new MoneyException("Money was not enough!");
929
}
1030
}

0 commit comments

Comments
 (0)