Skip to content

Commit 95db046

Browse files
author
Jin Guo
committed
Initial commit
0 parents  commit 95db046

14 files changed

+192
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Project exclude paths
2+
/out/

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab1.iml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<orderEntry type="module-library">
11+
<library>
12+
<CLASSES>
13+
<root url="file://$MODULE_DIR$/junit5" />
14+
</CLASSES>
15+
<JAVADOC />
16+
<SOURCES />
17+
<jarDirectory url="file://$MODULE_DIR$/junit5" recursive="false" />
18+
</library>
19+
</orderEntry>
20+
</component>
21+
</module>

junit5/junit-jupiter-5.5.2.jar

6.02 KB
Binary file not shown.

junit5/junit-jupiter-api-5.5.2.jar

138 KB
Binary file not shown.

junit5/junit-jupiter-engine-5.5.2.jar

214 KB
Binary file not shown.
25.5 KB
Binary file not shown.

junit5/junit-jupiter-params-5.5.2.jar

537 KB
Binary file not shown.

src/Book.java

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
/**
3+
* A Book Item:
4+
*/
5+
public class Book
6+
{
7+
private final String aTitle;
8+
private final String aAuthor;
9+
private final BookType aType;
10+
private final int aPrice; // In cents: 100 = one dollar
11+
12+
/**
13+
* Creates a new book item.
14+
* @param pTitle The title of the book.
15+
* @param pAuthor The name of the author
16+
* @param pType The category of the book
17+
* @param pPrice The price of the item in cents
18+
*/
19+
public Book(String pTitle, String pAuthor, BookType pType, int pPrice)
20+
{
21+
aTitle = pTitle;
22+
aAuthor = pAuthor;
23+
aType = pType;
24+
aPrice = pPrice;
25+
}
26+
27+
/**
28+
* @return The title of the book
29+
*/
30+
public String getTitle()
31+
{
32+
return aTitle;
33+
}
34+
35+
/**
36+
* @return The name of the Author.
37+
*/
38+
public String getAuthor()
39+
{
40+
return aAuthor;
41+
}
42+
43+
/**
44+
* @return The category of the book
45+
*/
46+
public BookType getType()
47+
{
48+
return aType;
49+
}
50+
51+
/**
52+
* @return The price of the book in cents
53+
*/
54+
public int getPrice()
55+
{
56+
return aPrice;
57+
}
58+
}

src/BookType.java

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public enum BookType {
2+
FICTION, NONFICTION, TEXTBOOK, COMIC, OTHER
3+
}

src/Bookstore.java

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
import java.util.HashMap;
3+
import java.util.Iterator;
4+
5+
/**
6+
* Represents the inventory of books in one bookstore
7+
*/
8+
public class Bookstore
9+
{
10+
private final String aName; // Unique
11+
private final HashMap<Book, Integer> aInventory = new HashMap<>();
12+
13+
/**
14+
* Creates a new bookstore with no books in it,
15+
* and identified uniquely with pName.
16+
* @param pName A unique identifier for the bookstore.
17+
*/
18+
public Bookstore(String pName)
19+
{
20+
aName = pName;
21+
}
22+
23+
/**
24+
* @return The unique name of the bookstore.
25+
*/
26+
public String getName()
27+
{
28+
return aName;
29+
}
30+
31+
}

src/Driver.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.Random;
2+
3+
/**
4+
* Utility class with a driver program and some
5+
* sample books, stores, and staffs.
6+
*/
7+
public final class Driver
8+
{
9+
10+
private static final Book BOOK1= new Book("The Time Machine", "H. G. Wells", BookType.FICTION, 500);
11+
private static final Book BOOK2 = new Book("Introduction to Software Design with Java", "Martin P. Robillard", BookType.TEXTBOOK, 3999);
12+
private static final Book BOOK3 = new Book("The Moomins and the Great Flood", "Tove Jansson", BookType.COMIC, 1695);
13+
14+
private static final Book[] Books = { BOOK1, BOOK2, BOOK3 };
15+
16+
private Driver() {}
17+
18+
/**
19+
* @param pArgs Not used
20+
*/
21+
public static void main(String[] pArgs)
22+
{
23+
Bookstore bookstore1 = new Bookstore("Paragraph");
24+
Bookstore bookstore2 = new Bookstore("The Word");
25+
}
26+
}

src/Staff.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
/**
5+
* Represents a staff member working in a bookstore
6+
*/
7+
public class Staff {
8+
9+
final private String aName;
10+
private Bookstore aStore;
11+
private List<Book> aBookRecommendation;
12+
13+
/**
14+
* Creates a new staff with an unique name,
15+
* associated with one bookstore.
16+
* @param pName A unique identifier for the staff.
17+
* @param pStore The bookstore the staff current works at.
18+
*/
19+
public Staff(String pName, Bookstore pStore) {
20+
aName = pName;
21+
aStore = pStore;
22+
aBookRecommendation = new ArrayList<>();
23+
}
24+
25+
/**
26+
* Change the staff to a different bookstore
27+
* @param pStore The new bookstore at which the staff will work
28+
*/
29+
public void changeBookstore(Bookstore pStore)
30+
{
31+
aStore = pStore;
32+
}
33+
34+
35+
36+
37+
}

0 commit comments

Comments
 (0)