Skip to content

Commit fafa803

Browse files
committed
add files for cycle-chronicles task
1 parent 290dafb commit fafa803

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This represents the student support code for the [Cycle Chronicles task].
1212

1313
This [work] by [Carsten Gips] and [contributors] is licensed under [MIT].
1414

15-
[Cycle Chronicles task]: https://github.com/Programmiermethoden-CampusMinden/Prog2-Lecture/blob/master/homework/b07.md
15+
[Cycle Chronicles task]: https://github.com/Programmiermethoden-CampusMinden/Prog2-Lecture/blob/master/homework/b08.md
1616
[work]: https://github.com/Programmiermethoden-CampusMinden/prog2_ybel_cyclechronicles
1717
[Carsten Gips]: https://github.com/cagix
1818
[contributors]: https://github.com/Programmiermethoden-CampusMinden/prog2_ybel_cyclechronicles/graphs/contributors
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cyclechronicles;
2+
3+
/** An order for a bike shop. */
4+
public class Order {
5+
/**
6+
* Determine the type of bike to be repaired.
7+
*
8+
* @return type of bicycle
9+
*/
10+
public Type getBicycleType() {
11+
throw new UnsupportedOperationException();
12+
}
13+
14+
/**
15+
* Determine the customer who placed this order.
16+
*
17+
* @return name of customer
18+
*/
19+
public String getCustomer() {
20+
throw new UnsupportedOperationException();
21+
}
22+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package cyclechronicles;
2+
3+
import java.util.*;
4+
5+
/** A small bike shop. */
6+
public class Shop {
7+
private Queue<Order> pendingOrders = new LinkedList<>();
8+
private Set<Order> completedOrders = new HashSet<>();
9+
10+
/**
11+
* Accept a repair order.
12+
*
13+
* <p>The order will only be accepted if all conditions are met:
14+
*
15+
* <ul>
16+
* <li>Gravel bikes cannot be repaired in this shop.
17+
* <li>E-bikes cannot be repaired in this shop.
18+
* <li>There can be no more than one pending order per customer.
19+
* <li>There can be no more than five pending orders at any time.
20+
* </ul>
21+
*
22+
* <p>Implementation note: Accepted orders are added to the end of {@code pendingOrders}.
23+
*
24+
* @param o order to be accepted
25+
* @return {@code true} if all conditions are met and the order has been accepted, {@code false}
26+
* otherwise
27+
*/
28+
public boolean accept(Order o) {
29+
if (o.getBicycleType() == Type.GRAVEL) return false;
30+
if (o.getBicycleType() == Type.EBIKE) return false;
31+
if (pendingOrders.stream().filter(x -> x.getCustomer().equals(o.getCustomer())).count() > 0)
32+
return false;
33+
if (pendingOrders.size() > 4) return false;
34+
35+
return pendingOrders.add(o);
36+
}
37+
38+
/**
39+
* Take the oldest pending order and repair this bike.
40+
*
41+
* <p>Implementation note: Take the top element from {@code pendingOrders}, "repair" the bicycle
42+
* and put this order in {@code completedOrders}.
43+
*
44+
* @return finished order
45+
*/
46+
public Optional<Order> repair() {
47+
throw new UnsupportedOperationException();
48+
}
49+
50+
/**
51+
* Deliver a repaired bike to a customer.
52+
*
53+
* <p>Implementation note: Find any order in {@code completedOrders} with matching customer and
54+
* deliver this order. Will remove the order from {@code completedOrders}.
55+
*
56+
* @param c search for any completed orders of this customer
57+
* @return any finished order for given customer, {@code Optional.empty()} if none found
58+
*/
59+
public Optional<Order> deliver(String c) {
60+
throw new UnsupportedOperationException();
61+
}
62+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cyclechronicles;
2+
3+
/** Different types of bicycles. */
4+
public enum Type {
5+
/** Road bike - for fast cycling. */
6+
RACE,
7+
/** Single speed bike - like fixie, but with freewheel. */
8+
SINGLE_SPEED,
9+
/** Fixed gear bike - like single speed, but with fix gear. */
10+
FIXIE,
11+
/** Gravel bike - wants to be everything, can't do anything right. */
12+
GRAVEL,
13+
/** E-bike - no comment. */
14+
EBIKE
15+
}

0 commit comments

Comments
 (0)