Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88dd364

Browse files
committed
Collections & Binary Search
1 parent db19c3e commit 88dd364

File tree

19 files changed

+572
-0
lines changed

19 files changed

+572
-0
lines changed

‎CODE/070_Collections/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎CODE/070_Collections/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎CODE/070_Collections/.idea/workspace.xml

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎CODE/070_Collections/src/Main.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
Theatre theatre = new Theatre("Olympian", 8, 12);
4+
// theatre.getSeats();
5+
if(theatre.reserveSeat("H11")) {
6+
System.out.println("Please pay");
7+
} else {
8+
System.out.println("Sorry, seat is taken");
9+
}
10+
if(theatre.reserveSeat("H11")) {
11+
System.out.println("Please pay");
12+
} else {
13+
System.out.println("Sorry, seat is taken");
14+
}
15+
}
16+
}

‎CODE/070_Collections/src/Theatre.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
public class Theatre {
5+
private final String theatreName;
6+
private List<Seat> seats = new ArrayList<>();
7+
8+
public Theatre(String theatreName, int numRows, int seatsPerRow) {
9+
this.theatreName = theatreName;
10+
11+
int lastRow = 'A' + (numRows -1);
12+
for (char row = 'A'; row <= lastRow; row++) {
13+
for(int seatNum = 1; seatNum <= seatsPerRow; seatNum++) {
14+
Seat seat = new Seat(row + String.format("%02d", seatNum));
15+
seats.add(seat);
16+
}
17+
}
18+
}
19+
20+
public String getTheatreName() {
21+
return theatreName;
22+
}
23+
24+
public boolean reserveSeat(String seatNumber) {
25+
Seat requestedSeat = null;
26+
for(Seat seat : seats) {
27+
if(seat.getSeatNumber().equals(seatNumber)) {
28+
requestedSeat = seat;
29+
break;
30+
}
31+
}
32+
33+
if(requestedSeat == null) {
34+
System.out.println("There is no seat " + seatNumber);
35+
return false;
36+
}
37+
38+
return requestedSeat.reserve();
39+
}
40+
41+
// for testing
42+
public void getSeats() {
43+
for(Seat seat : seats) {
44+
System.out.println(seat.getSeatNumber());
45+
}
46+
}
47+
48+
private class Seat {
49+
private final String seatNumber;
50+
private boolean reserved = false;
51+
52+
public Seat(String seatNumber) {
53+
this.seatNumber = seatNumber;
54+
}
55+
56+
public boolean reserve() {
57+
if(!this.reserved) {
58+
this.reserved = true;
59+
System.out.println("Seat " + seatNumber + " reserved");
60+
return true;
61+
} else {
62+
return false;
63+
}
64+
}
65+
66+
public boolean cancel() {
67+
if(this.reserved) {
68+
this.reserved = false;
69+
System.out.println("Reservation of seat " + seatNumber + " cancelled");
70+
return true;
71+
} else {
72+
return false;
73+
}
74+
}
75+
76+
public String getSeatNumber() {
77+
return seatNumber;
78+
}
79+
}
80+
81+
82+
83+
}

‎CODE/071_BinarySearch/.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /