vault backup: 2024-03-21 22:58:58

This commit is contained in:
2024-03-21 22:58:58 +00:00
parent 68fa81d02f
commit e241fe8bd6
49 changed files with 1950 additions and 210 deletions

View File

@@ -4,57 +4,22 @@
"type": "split", "type": "split",
"children": [ "children": [
{ {
"id": "74175e978d06be55", "id": "18e28060fe2de0a2",
"type": "tabs", "type": "tabs",
"children": [ "children": [
{ {
"id": "e96e468fb0a709e5", "id": "f5285cbbb611ecba",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "markdown", "type": "markdown",
"state": { "state": {
"file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md", "file": "Semester 2/Programming 2/Week 10 Revision/Q5.md",
"mode": "source", "mode": "source",
"source": false "source": false
} }
} }
},
{
"id": "1dda09aee43b18f4",
"type": "leaf",
"state": {
"type": "full-calendar-view",
"state": {}
}
} }
] ]
},
{
"id": "97b758ffb617daa3",
"type": "tabs",
"children": [
{
"id": "fdb9dea18c7f9c15",
"type": "leaf",
"state": {
"type": "pdf",
"state": {
"file": "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf"
}
}
},
{
"id": "bde983126ec4558f",
"type": "leaf",
"state": {
"type": "pdf",
"state": {
"file": "Semester 2/Database Systems/Exercise Booklet.pdf"
}
}
}
],
"currentTab": 1
} }
], ],
"direction": "vertical" "direction": "vertical"
@@ -105,7 +70,8 @@
} }
], ],
"direction": "horizontal", "direction": "horizontal",
"width": 200 "width": 200,
"collapsed": true
}, },
"right": { "right": {
"id": "ee8f6df41634f71e", "id": "ee8f6df41634f71e",
@@ -121,7 +87,7 @@
"state": { "state": {
"type": "backlink", "type": "backlink",
"state": { "state": {
"file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md", "file": "Semester 2/Programming 2/Week 10 Revision/Q5.md",
"collapseAll": false, "collapseAll": false,
"extraContext": false, "extraContext": false,
"sortOrder": "alphabetical", "sortOrder": "alphabetical",
@@ -138,7 +104,7 @@
"state": { "state": {
"type": "outgoing-link", "type": "outgoing-link",
"state": { "state": {
"file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md", "file": "Semester 2/Programming 2/Week 10 Revision/Q5.md",
"linksCollapsed": false, "linksCollapsed": false,
"unlinkedCollapsed": true "unlinkedCollapsed": true
} }
@@ -161,7 +127,7 @@
"state": { "state": {
"type": "outline", "type": "outline",
"state": { "state": {
"file": "Semester 2/Database Systems/Week 8/Week 8 Database Systems.md" "file": "Semester 2/Programming 2/Week 10 Revision/Q5.md"
} }
} }
}, },
@@ -201,31 +167,42 @@
"switcher:Open quick switcher": false "switcher:Open quick switcher": false
} }
}, },
"active": "e96e468fb0a709e5", "active": "f5285cbbb611ecba",
"lastOpenFiles": [ "lastOpenFiles": [
"images/Pasted image 20240308103937.png", "Semester 2/Programming 2/Assessment 4 Notes",
"images/Pasted image 20240308103720.png", "images/Pasted image 20240319234142.png",
"images/Pasted image 20240308102031.png", "images/Pasted image 20240319225420.png",
"images/Pasted image 20240308101739.png", "Semester 2/Programming 2/Week 10 Revision/Q4.md",
"Semester 2/Programming 2/Project/Part 2/Library.java#", "Semester 2/Programming 2/Week 10 Revision/Q5.md",
"images/Pasted image 20240319224232.png",
"Semester 2/Programming 2/Week 10 Revision/Q3.md",
"Semester 2/Database Systems/Exercise Booklet.pdf", "Semester 2/Database Systems/Exercise Booklet.pdf",
"Semester 2/Database Systems/Week 8/Week 8 Database Systems.md",
"Semester 2/Database Systems/Week 7/Week 7 Database Systems.md",
"Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf", "Semester 2/Database Systems/Booklet of Lecture Slides for Semester Two (2).pdf",
"images/Pasted image 20240305135229.png", "Semester 2/Database Systems/Week 10/Week 10 Database Systems.md",
"images/Pasted image 20240305135043.png", "images/Pasted image 20240319163053.png",
"images/Pasted image 20240305134944.png", "images/Pasted image 20240319162824.png",
"images/Pasted image 20240305134930.png", "images/Pasted image 20240319161202.png",
"images/Pasted image 20240305134835.png", "images/Pasted image 20240319160609.png",
"images/Pasted image 20240305134734.png", "Semester 2/Programming 2/Week 10 Revision/Q1.md",
"images/Pasted image 20240305134506.png", "Semester 2/Programming 2/Week 10 Revision",
"Semester 2/Database Systems/Week 2/Week 2 Database Systems.md",
"Semester 2/Database Systems/Week 1/Week 1 Database Systems.md",
"Semester 1/Database Systems/Week 10/Week 10 Database Systems.md",
"Semester 2/Database Systems/Week 3/Week 3 Database Systems.md",
"Semester 2/Database Systems/Week 4/Week 4 Database Systems.md",
"Semester 2/Database Systems/Week 10",
"Semester 2/Database Systems/Week 9/Week 9 Database Systems.md",
"images/Pasted image 20240312161933.png",
"images/Pasted image 20240312161927.png",
"images/Pasted image 20240312161656.png",
"Semester 2/Database Systems/Week 8/Week 8 Database Systems.md",
"Semester 2/Database Systems/Week 9",
"Semester 2/Untitled",
"Semester 2/Programming 2/Project/Part 2/__SHELL1.class",
"Semester 2/Programming 2/Project/Part 2/__SHELL1.java",
"Semester 2/Programming 2/Project/Part 2/Library.java#",
"Semester 2/Database Systems/Week 7/Week 7 Database Systems.md",
"Semester 2/Programming 2/Project/Part 2/Book.java#", "Semester 2/Programming 2/Project/Part 2/Book.java#",
"Semester 2/Programming 2/Project/Part 2/Periodical.java#",
"Semester 2/Programming 2/Project/Part 2/LibraryItem.java#",
"Semester 2/Programming 2/Project/Part 2/LibraryUser.java#",
"Semester 2/Programming 2/Project/Part 2/CD.java#",
"Semester 2/Programming 2/Project/Part 2/DVD.java#",
"Semester 2/Programming 2/Project/Part 2/AudioVisual.java#",
"Semester 2/Database Systems/Week 6/Week 6 Database Systems.md", "Semester 2/Database Systems/Week 6/Week 6 Database Systems.md",
"Semester 2/Computer Systems Internals & Linux/Week 6/Week 6 Computer Systems Internals.md", "Semester 2/Computer Systems Internals & Linux/Week 6/Week 6 Computer Systems Internals.md",
"Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS3.md", "Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS3.md",
@@ -233,22 +210,11 @@
"Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS2.md", "Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS2.md",
"Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS1.md", "Semester 2/Programming 2/Assessment 3 Revision/Parameter Passing WS1.md",
"Semester 2/Database Systems/Week 5/Week 5 Database Systems.md", "Semester 2/Database Systems/Week 5/Week 5 Database Systems.md",
"Semester 2/Database Systems/Week 4/Week 4 Database Systems.md",
"Semester 2/HCI/Week 2/Week 2 Human Computer Interfaces.md", "Semester 2/HCI/Week 2/Week 2 Human Computer Interfaces.md",
"Semester 2/HCI/Week 3/Week 3 Human Computer Interfaces.md", "Semester 2/HCI/Week 3/Week 3 Human Computer Interfaces.md",
"Semester 1/Database Systems/Week 10/Week 10 Database Systems.md",
"Semester 1/Database Systems/Week 11/Week 11 Database Systems.md", "Semester 1/Database Systems/Week 11/Week 11 Database Systems.md",
"Semester 1/Database Systems/Week 5/Week 5 Database Systems.md", "Semester 1/Database Systems/Week 5/Week 5 Database Systems.md",
"Semester 1/Database Systems/Week 3/Week 3 Database Systems.md", "Semester 1/Database Systems/Week 3/Week 3 Database Systems.md",
"Semester 1/Database Systems/Week 2/Week 2 Database Systems.md",
"Semester 1/Database Systems/Week 9/Week 9 Database Systems.md",
"Semester 1/Database Systems/Week 8/Week 8 Database Systems.md",
"Semester 1/Database Systems/Week 7/Week 7 Database Systems.md",
"Semester 1/Database Systems/Week 4/Week 4 Database Systems - Data Description Language.md",
"Semester 1/Database Systems/Week 6/Week 6 Database Systems.md",
"Semester 2/Database Systems/Week 3/Week 3 Database Systems.md",
"Semester 2/Database Systems/Week 2/Week 2 Database Systems.md",
"CCNA/1 - Networking Today/1.2 - Network Components.md",
"Database Systems/Untitled.canvas", "Database Systems/Untitled.canvas",
"Untitled 1.canvas", "Untitled 1.canvas",
"Untitled.canvas" "Untitled.canvas"

View File

@@ -0,0 +1,77 @@
# Query Optimisation Revision
1. Obtaining the desired information from a database system in a predictable and reliable fashion is Query Processing. Getting these results back in a timely manner deals with the technique of Query Optimization.
2. r(rID, rName, rDescription), 5000 tuples.
tuple header(24b)
rID(6b)
rName(10b)
rDescription(100b)
Disc Block(1024b)
Disc Block Header(24b)
Block Space 1000b
1. (24+6+10+100)=140b
We can fit 7 tuples in 1 block.
5000/7 = 715 blocks required.
2. (24+6+10) = 40b
25 tuples per block
5000/25 = 200 blocks required.
3. Since the projection uses significantly less blocks, we access the disc less in queries compared to using every attribute. 715/200 = 3.6x less disc block accesses.
3. Write relational algebra expressions for the following SQL query.
SELECT lecturers.name, students.name, courses.name
FROM lecturers, students, assessors, courses
WHERE lecturers.lid=assessors.lid
AND students.sid=assessors.sid
AND students.cid=courses.cid
AND courses.cid=“CS”;
π lecturers.name, students.name, courses.name (
σ courses.cid = "CS" (
lecturers ⨝ (
assessors ⨝ (
students ⨝ courses))))
Or,
π lecturers.name, students.name, courses.name
(σ lecturers.lid=assessors.lid
(σ students.sid=accessors.sid
(σ courses.cid=students.did
(σ courses.cid='CS'(courses\*students)
)\* assessors
)\* lecturers
)
1. Draw query tree
4. List heuristics that optimisers apply to reduce cost of optimisation.
- Begin with initial query tree for SQL
- Move SELECT operations down the tree
- Apply more restrictive SELECT operations first ( eg. equalities before range queries )
- Replace Cartesian products followed by selection with theta joins ( eg. *sigma(f) ( RxS )* -> *R theta(f) S* )
- Move PROJECT operations down the query tree ( add project operations as inputs to theta joins ).
5. Draw a near optimal query tree for the following:
SELECT hotels.name
FROM hotels, ratings
WHERE hotels.rid=ratings.rid
AND hotels.hid=10
AND ratings.rating>7;
1. Write relational algebra expressions for this tree
# Precedence Graphs Revision
1. State True / False
1. A transaction in which all steps must be completed successfully or none of them will be completed is called a durable transaction.
False, this is the definition of an atomic transaction
2. Two-phased locking can be used to ensure that transactions are serializable
True
3. Although two transactions may be correct in themselves, interleaving of operations may produce an incorrect result.
True
4. Transactions should be written to the log before they are applied to the database itself.
True
2. Consider the following precedence graph for a non-serial schedule consisting of four transactions. Is the corresponding schedule conflict serializable? Justify your answer. If it is conflict-serializable give a corresponding serial schedule.
![](Pasted%20image%2020240319160609.png)
The following is serialisable, since there are no cycles in the precedence graph. T1, T2, T3, T4.
3. For each of the schedules shown in Table 36.1, draw a precedence graph, determine whether it is conflict serializable and justify your answer.
![](Pasted%20image%2020240319161202.png)
![](Pasted%20image%2020240319162824.png)
Not serialisable, directed cycle in graph.
![](Pasted%20image%2020240319163053.png)
Not serialisable, directed cycle in graph

View File

@@ -0,0 +1,266 @@
# Data Security
## Threats
- Accidental Loss
- Human Error
- Software Failure
- Hardware Failure
- Theft, Fraud, Sabotage
- Improper Data Access
- Loss of privacy ( personal data )
- Loss of confidentiality ( corporate data )
- Loss of data integrity
- Loss of availability
## Non Computer-Based Controls
- Policies, agreements, administrative controls
- Security policies
- Contingency plans
- Personnel Controls
- Secure positioning of equipment
- Maintenance agreements
- Physical access controls
## Computer-Based Controls
- Backup
- Periodical copies of database & journal to offline media.
- Journaling
- Keeping and maintaining a log file / journal of all changes made to database to enable recovery.
- Checkpointing
- Syncro between database and transaction log. Buffers are force-written to storage.
- Integrity
- Prevents data invalidity.
- Encryption
- Encoding of data by algorithm; renders data unreadable without decryption key.
- Authorisation
- Granting of right or privilege, enabling subject legitimate access to a system / object.
- Authentication
- Determines the authenticity of a user.
- Views
- Dynamic result of one or more relational operations on the base relations to produce another relation.
## Authorisation
### Authorisation Types for Schemas
- Resources: allows creation of new relations
- Alteration: allows the addition / deletion of attributes
- Index: allows creation / deletion of indices
- Drop: allows deletion of relations
### Authorisation Types for Data
- Read: allows read only access
- Insert: allows insertion ( not modification ) of new data
- Update: allows modification ( not deletion ) of existing data
- Delete: allows deletion of data.
### Authorisation Grant Graph
- Passage of auth from one user to another may be represented in a grant graph.
- Nodes = users
- Root = db admin
- Edge indicates user granted authorisation for a specific transaction to another user.
- All edges must be part of some path connecting to the db admin.
- ![](Pasted%20image%2020240312131440.png)
If DBA revokes auth from U1:
- Auth must be revoked from U4, since U1 no longer has authorisation.
- Auth must not be revoked from U5, since another auth path exists.
## View
- Alike to a window, through which data is seen.
- Creation of a view does not require significant memory, not a new relation.
- Extremely useful in restricting access to data.
- Users can be given authorisation on views, without being given any authorisation on the relations themselves.
- Ability of views to hide data serves to simplify usage of system, and enhance security by allowing users specific access.
- Combination of relational-level security and view-level security can be used to limit, precisely, user access.
- To create a view, a user must have read auth on all relations the view accesses.
### Example
Suppose a bank clerk needs to know the names of the customers that have a loan and which branch they bank with, but is not authorised to see specific loan information.
1. Deny bank clerk direct access to loan relation
2. Create view to provide necessary information.
```SQL
CREATE VIEW cust-loan AS
SELECT branchname, customer-name
FROM borrower, loan
WHERE borrower.loan-number = loan.loan-num
```
3. Grant bank clerk access to view
The clerk is now authorised to see the result of a query on the view
```SQL
SELECT *
FROM cust-loan
```
If the creator of the cust-loan view has only read auth on borrower and loan, the creator will only have read auth on the view.
## Granting Privileges in SQL
```SQL
GRANT <privilege list>
ON <relation / view name >
TO <user list>
```
- GRANT statement is used to confer authorisation
- Lists the privileges to be granted
- Specifies the relation / view that will be effected
- Stipulates who is being authorised.
- user id
- PUBLIC ( all valid users )
- role
- Granting privilege on a view does not imply privilege on any relation.
- Grantor of privilege must hold the privilege, or be the administrator.
### Types of Privilege
- SELECT: allows read access
- INSERT: allows use of INSERT INTO
- UPDATE: allows use of UPDATE
- DELETE: allows tuples to be deleted
- REFERENCES: allows foreign keys to be declared when creating relations
- ALL PRIVILEGES: used as a short term for all.
### Allowing Granting
- Users can be allowed to pass a privilege on to other users.
```SQL
GRANT SELECT
ON branch
TO U1
WITH GRANT OPTION
```
- This gives U1 the select privilege on branch and allows U1 to grant this privilege to other users.
### Revoking Privilege
- REVOKE is used to remove authorisation
- Lists all privileges to be revokes
- If list contains ALL, all privileges will be removed
- Specifies relation or view that will be effected.
```SQL
REVOKE <privilege list>
ON <relation / view name>
FROM <user list>
[RESTRICT | CASCADE]
```
- If same privilege granted twice to same user by different grantors, user may retain privilege after revoke.
- All privileges that depend solely on privilege being revoked are also revoked.
- If revoking a privilege from a user causes other users to lose that privilege, the revoke is CASCADED.
- Cascading can be prevented by specifying RESTRICT
- With restrict, the revoke command fails if cascading revokes are necessary.
- If \<user list> includes public, all users lose the privilege, except those granted explicitly.
## Roles
Roles permit common privileges for a class of users
Privileges can be granted or revoked from roles
Roles can be assigned to users, and also other roles
### Roles in SQL
```SQL
CREATE ROLE teller;
CREATE ROLE manager;
GRANT SELECT ON branch TO teller;
GRANT UPDATE(balance) ON account TO teller;
GRANT ALL PRIVILEGES ON account TO manager;
GRANT teller to manager;
GRANT teller TO alice, bob;
GRANT manager TO avi;
```
## Limitations of SQL Authorisation
No support for tuple-level authorisation
All end-users of an application may be mapped to a single user.
Task of auth in above cases falls on application program
- Auth must be performed at an application level, rather than SQL.
- Checking for absence of loopholes becomes difficult, since it requires reading a larger amount of code.
# Tutorial
1. Define following terms:
1. Authentication
- The process of verifying the authenticity of a user.
2. Authorisation
- The process of verifying permission / privilege to access a system / object.
3. Roles within SQL
- Permit common privileges for users, allowing groups of user's permissions to be changed.
2. Explain the following parts of an auth grant graph:
1. Nodes
- Nodes represent users
2. Root Node
- Root node represents db admin
3. Edge
- Edges represent permission grants between users.
3. Consider the following:
![](Pasted%20image%2020240312161656.png)
What would be the result of U1 revoking auth from U4?
- U6 would have its privilege revoked, as there is no path to the root node. All other nodes would be unaffected, since they all have a path to the root.
4. Consider the following:
![](Pasted%20image%2020240312161933.png)
What would be the result of DBA revoking auth from U1?
- U2, U4, and U6 all have auth revoked, as here is no path to the root.
5. Suppose a database includes the following relations.
Student(sNo, sName, sAddress, sLevel, sMno, sPerformance)
Module(mNo, mTitle, mLevel, mLecturer)
1. Users are:
- Alfred - Authorised to do anything
- Christian - See and change student details, cannot register or delete
- Robin - Same auth as christian
- George - Same auth as Robin
2. There is another User, Jessica, who can only see final year students and final year modules. Jessica is not authorised to do anything else. Write SQL statements that implement this. Hint: you can use a view to achieve this!
3. Now suppose that George has now moved to another university and, therefore, should no longer have access to the database. Write SQL statements to implement this.
##### Q5 Answers
1. .
```SQL
GRANT ALL PRIVILEGES ON student TO alfred;
GRANT ALL PRIVILEGES ON module TO alfred;
GRANT select, update ON student TO christian, robin, george;
```
1. .
```SQL
CREATE VIEW studentFinal AS
SELECT *
FROM student
WHERE sLevel = 6
CREATE VIEW moduleFinal AS
SELECT *
FROM module
WHERE mLevel = 6;
REVOKE ALL PRIVILEGES ON student, module FROM jessica RESTRICT;
GRANT SELECT ON studentFinal TO jessica;
GRANT SELECT ON moduleFinal TO jessica;
```
1. .
```SQL
REVOKE ALL PRIVILEGES ON * FROM george;
```

View File

@@ -0,0 +1,65 @@
private void readFilmData(String fileName) throws IOException //1
{
File filmFile = new File(filename); //2
Scanner scanner1 = new Scanner( filmFile ); //3
while (scanner1.hasNext() ) //4 could throw a FileNotFoundExcpetion
{
String line = scanner1.nextLine(); //5
Scanner scanner2 = new Scanner(line);
scanner2.useDelimiter("[ ]*(,)[ ]*");
String filmTitle = scanner2.next();
String filmRating = scanner2.next();
int short = scanner2.nextInt();
// other code here to read & store rest of data
scanner2.close();
}
scanner1.close();
}
Citizen ->
English ->
Mancunian,
Londoner
Scots
Citizen person1;
English person2;
Scots person3;
Mancunian person4;
Londoner person5;
person1 = new Londoner();
person1 type Citizen. Legal
person2 = new Mancunian();
person2 type English. Legal
person5 = new English();
person5 type Londoner. Illegal
persona2 = new Scots();
person2 type English. Illegal
factorial(3) ->
x = 2
y = factorial(2)
factorial(2) ->
x = 1
y = factorial(1) -> 1
n*y = 2*1 = 2
n*y = 2*3 = 6
public int countTree(BinTreeNode t)
{
int count;
if (t == null)
count = 0;
else
count = countTree(t.leftChild) + 1 + countTree(t.rightChild);
return count;
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,17 @@
#BlueJ class context
comment0.params=
comment0.target=Diary()
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Diary\n
comment1.params=itemReservation
comment1.target=void\ addReservation(LibraryReservation)
comment1.text=\n\ Method\ for\ adding\ a\ reservation\ to\ the\ diary.\ \n\ @parameter\ itemReservation,\ of\ type\ ItemReservation\ \n
comment2.params=startDate\ endDate
comment2.target=void\ printEntries(java.util.Date,\ java.util.Date)
comment2.text=\n\ Method\ for\ displaying\ the\ reservations\ between\ specified\ dates.\ \n\n\ @parameter\ \ \ \ \ startDate,\ of\ type\ Date\n\ @parameter\ \ \ \ \ endDate,\ of\ type\ Date\n
comment3.params=itemReservation
comment3.target=void\ deleteReservation(LibraryReservation)
comment3.text=\n\ Method\ for\ deleting\ a\ reservation\ from\ the\ diary.\ \n\ @parameter\ itemReservation,\ of\ type\ ItemReservation\ \n
comment4.params=date
comment4.target=LibraryReservation[]\ getReservations(java.util.Date)
comment4.text=\n\ Accessor\ method\ for\ returning\ all\ reservations\ that\ have\ entries\ \n\ in\ the\ diary\ for\ a\ particular\ date.\ \n\n\ @parameter\ \ \ \ \ date,\ of\ type\ Date\ \n\ @return\ \ \ \ \ \ \ \ an\ array\ of\ reservations,\ or\ null\ if\ no\ entry\ for\ that\ date\n
numComments=5

View File

@@ -0,0 +1,205 @@
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.ArrayList;
/**
* A class Diary that represents a "diary" of library item reservations.
*
* The diary is structured as a Map of entries in which each entry corresponds
* to a specific day. As the map is not accessed in a sequential fashion, it
* doesn't matter whether the actual map class is a TreeMap or a HashMap.
*
* @author D E Newton
*
*/
public class Diary
{
private Map<Date, DayInDiary> dayInDiaryMap;
/**
* Constructor for objects of class Diary
*/
public Diary()
{
// create diary as a map
dayInDiaryMap = new HashMap<Date, DayInDiary>();
}
/**
* Method for adding a reservation to the diary.
* @parameter itemReservation, of type ItemReservation
*/
public void addReservation(LibraryReservation itemReservation)
{
Date date = itemReservation.getStartDate();
for(int day=1; day<=itemReservation.getNoOfDays(); day++)
{
if( !dayInDiaryMap.containsKey(date) )
{
// add new day to diary if no previous entries for this day
dayInDiaryMap.put(date, new DayInDiary(date));
}
dayInDiaryMap.get(date).addEntry(itemReservation, day);
date = DateUtil.nextDate(date);
}
}
/**
* Method for displaying the reservations between specified dates.
*
* @parameter startDate, of type Date
* @parameter endDate, of type Date
*/
public void printEntries(Date startDate, Date endDate)
{
if( DateUtil.daysBetween(startDate, endDate)<0 )
{
// startDate after endDate
System.out.println("*** Error in method displayEntries(): The specified end date is before the start date ***");
}
else
{
System.out.println("\n\nDiary: Reservations for period " + DateUtil.convertDateToShortString(startDate)
+ " to " + DateUtil.convertDateToShortString(endDate) + " inclusive");
System.out.println("=================================================================");
for(Date date=startDate; date.compareTo(endDate)<=0; date = DateUtil.nextDate(date))
{
String longDate = DateUtil.convertDateToLongString(date);
System.out.print(longDate + ":");
if( dayInDiaryMap.containsKey(date) )
{
DayInDiary dayInDiary = dayInDiaryMap.get(date);
dayInDiary.printEntries();
}
else
System.out.println(" No reservations\n");
}
}
}
/**
* Method for deleting a reservation from the diary.
* @parameter itemReservation, of type ItemReservation
*/
public void deleteReservation(LibraryReservation itemReservation)
{
Date date = itemReservation.getStartDate();
for(int day=1; day<=itemReservation.getNoOfDays(); day++)
{
DayInDiary dayInDiary = dayInDiaryMap.get(date);
dayInDiary.deleteEntry(itemReservation);
if( dayInDiary.getDaysEntries().size()==0 )
dayInDiaryMap.remove(date);
date = DateUtil.nextDate(date);
}
}
/**
* Accessor method for returning all reservations that have entries
* in the diary for a particular date.
*
* @parameter date, of type Date
* @return an array of reservations, or null if no entry for that date
*/
public LibraryReservation[] getReservations(Date date)
{
DayInDiary dayinDiary = dayInDiaryMap.get(date);
if( dayinDiary==null )
return null;
else
return dayinDiary.getReservations();
}
// inner class, only needed in the Diary class
private class DayInDiary
{
// reservations for the day
private ArrayList<Entry> daysEntries;
private Date date;
/*
* Constructor for objects of class DayInDiary
*/
private DayInDiary(Date date)
{
this.date = date;
daysEntries = new ArrayList<Entry>();
}
private ArrayList<Entry> getDaysEntries()
{
return daysEntries;
}
private LibraryReservation[] getReservations()
{
int noOfEntries = daysEntries.size();
LibraryReservation[] itemReservations = new LibraryReservation[noOfEntries];
for(int i=0; i<noOfEntries; i++)
itemReservations[i] = daysEntries.get(i).getReservation();
return itemReservations;
}
private void addEntry(LibraryReservation itemReservation, int dayNo)
{
daysEntries.add(new Entry(itemReservation, dayNo));
}
private void deleteEntry(LibraryReservation itemReservation)
{
// find the entry for this reservation and delete it
Entry toBeDeletedEntry = null;
for(Entry entry : daysEntries)
{
if( entry.getReservation()==itemReservation ) // in this situation, this is better than using "equals()"
{
toBeDeletedEntry = entry;
break;
}
}
daysEntries.remove(toBeDeletedEntry);
}
private void printEntries()
{
int size = daysEntries.size();
if( size>0 )
{
System.out.println(" " + size + " reservation(s)");
for( Entry entry: daysEntries )
{
LibraryReservation itemReservation = entry.getReservation();
int reservationDay = DateUtil.daysBetween(itemReservation.getStartDate(), date) + 1;;
System.out.println(" " + itemReservation + ", day " + reservationDay + " of " + itemReservation.getNoOfDays());
}
}
else
{
System.out.println("*** Unexpected error in displayEntries() ***");
System.out.println("*** No entries for this date so it should not be in the diary ***");
}
System.out.println();
}
// an inner class of the DaysDiary class
private class Entry
{
private LibraryReservation itemReservation;
private int reservationDay; // e.g. second day is day 2 of 4 for a reservation spanning 4 days
private Entry(LibraryReservation itemReservation, int reservationDay)
{
this.itemReservation = itemReservation;
this.reservationDay = reservationDay;
}
private LibraryReservation getReservation()
{
return itemReservation;
}
}
}
}

View File

@@ -5,22 +5,41 @@ comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Library\n
comment1.params=item comment1.params=item
comment1.target=void\ storeItem(LibraryItem) comment1.target=void\ storeItem(LibraryItem)
comment1.text=\n\ Inserts\ object\ value\ item\ alongside\ key\ of\ @itemCode\ into\ @itemsMap.\n comment1.text=\n\ Inserts\ object\ value\ item\ alongside\ key\ of\ @itemCode\ into\ @itemsMap.\n
comment10.params=
comment10.target=void\ writeUserData()
comment10.text=\n\ A\ method\ to\ output\ all\ user\ data\ to\ a\ file\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ \n
comment11.params=
comment11.target=void\ readLibraryReservationData()
comment11.text=\n\ Read\ Library\ Reservation\ Data\ from\ a\ file\ specified\ by\ the\ user.\n
comment12.params=
comment12.target=void\ readData()
comment12.text=\n\ A\ method\ to\ read\ all\ data\ from\ files\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ This\ will\ create\ the\ corresponding\ objects\ depending\ on\ flags\ contained\ in\ the\ file\n\ and\ populate\ it's\ fields.\n\ \n\ Default\ flag\ value\:\ "book",\ to\ support\ legacy\ files.\ This\ will\ not\ interfere\ with\ \n\ files\ of\ different\ flag\ orders.\n
comment13.params=userID\ itemCode\ startDate\ noOfDays
comment13.target=boolean\ makeLibraryReservation(java.lang.String,\ java.lang.String,\ java.lang.String,\ int)
comment13.text=\n\ Create\ a\ reservation\ to\ allow\ a\ user\ to\ reserve\ an\ item\ from\ the\ library.\n
comment14.params=reservationNo
comment14.target=void\ deleteLibraryReservation(java.lang.String)
comment2.params=user comment2.params=user
comment2.target=void\ storeUser(LibraryUser) comment2.target=void\ storeUser(LibraryUser)
comment2.text=\n\ Inserts\ object\ value\ user\ alongside\ key\ of\ @userID\ into\ @customerMap.\n\ If\ the\ userID\ is\ set\ to\ unknown,\ it\ will\ call\ @generateUserID.\n comment2.text=\n\ Inserts\ object\ value\ user\ alongside\ key\ of\ @userID\ into\ @customerMap.\n\ If\ the\ userID\ is\ set\ to\ unknown,\ it\ will\ call\ @generateUserID.\n
comment3.params=reservation comment3.params=reservation
comment3.target=void\ storeLibraryReservation(LibraryReservation) comment3.target=void\ storeLibraryReservation(LibraryReservation)
comment3.text=\n\ Inserts\ object\ value\ reservation\ alongside\ key\ of\ @reservationNo\ into\ @libraryReservationMap.\n comment3.text=\n\ Inserts\ object\ value\ reservation\ alongside\ key\ of\ @reservationNo\ into\ @libraryReservationMap.\n
comment4.params=prefix\ length comment4.params=
comment4.target=java.lang.String\ generateUserID(java.lang.String,\ int) comment4.target=java.lang.String\ generateReservationNo()
comment4.text=\n\ Returns\ a\ random\ unique\ user\ ID\ by\ specifying\ \n\ @prefix\ -\ arbitrary\ alphanumeric\ prefix\n\ @length\ -\ length\ of\ numeric\ ID\n\ and\ returning\ a\ unique\ user\ id\n\ @uuid\ -\ a\ unique\ string\ starting\ with\ @prefix,\ and\ concat.\ with\ a\ random\ number\n\ \n\ Example\:\ length\ \=\ 6,\ expected\ result\ should\ be\ under\ 999,999\ and\ above\ 99,999.\n\ If\ we\ just\ use\ 10^(length),\ this\ would\ generate\ any\ number\ under\ 1,000,000.\n\ This\ is\ an\ issue\ since\ any\ integers\ below\ 100,000\ can\ be\ used,\ which\ would\ be\ incorrect.\n\ By\ using\ the\ offset\ of\ a\ factor\ of\ 10\ below\ the\ desired\ length\ we\ can\ generate\ between\ 0\ and\ 899,999.\n\ After\ this,\ we\ can\ add\ 100,000\ back\ to\ the\ number\ to\ ensure\ a\ baseline\ length\ is\ maintained.\n\ \n\ Note\:\ I\ am\ aware\ that\ this\ is\ overengineered,\ and\ that\ several\ random\ integers\ of\ amount\ @length\ could\ be\ used,\ \n\ but\ this\ is\ considerably\ more\ efficient\ since\ there\ is\ no\ iteration\ involved\ in\ the\ creation\ of\ the\ ID.\ O(1)\n comment4.text=\n\ Generate\ a\ sequential\ reservation\ number.\ Since\ Maps\ do\ not\ have\ an\ index,\ we\ cannot\ simply\ get\ the\ last\ value,\ \n\ and\ recursion\ would\ be\ too\ intensive\ for\ this\ application.\ As\ a\ placeholder\ for\ the\ file\ output,\ a\ field\ variable\n\ is\ used\ to\ hold\ the\ last\ highest\ value\ for\ the\ reservation\ number.\ Unlike\ @generateUserID,\ this\ has\ a\ maximum\ value\n\ hardcoded\ to\ the\ spec.\ This\ likely\ will\ not\ be\ an\ issue\ since\ we\ can\ still\ have\ 1,000,000\ reservations.\n
comment5.params= comment5.params=prefix\ length
comment5.target=void\ writeUserData() comment5.target=java.lang.String\ generateUserID(java.lang.String,\ int)
comment5.text=\n\ A\ method\ to\ output\ all\ user\ data\ to\ a\ file\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ \n\ Note\:\ Potentially\ could\ implement\ the\ HashSet\ made\ for\ GenerateUserID\ to\ avoid\ unnecessary\ recursion.\n comment5.text=\n\ Returns\ a\ random\ unique\ user\ ID\ by\ specifying\ \n\ @prefix\ -\ arbitrary\ alphanumeric\ prefix\n\ @length\ -\ length\ of\ numeric\ ID\n\ and\ returning\ a\ unique\ user\ id\n\ @uuid\ -\ a\ unique\ string\ starting\ with\ @prefix,\ and\ concat.\ with\ a\ random\ number\n\ \n\ Example\:\ length\ \=\ 6,\ expected\ result\ should\ be\ under\ 999,999\ and\ above\ 99,999.\n\ If\ we\ just\ use\ 10^(length),\ this\ would\ generate\ any\ number\ under\ 1,000,000.\n\ This\ is\ an\ issue\ since\ any\ integers\ below\ 100,000\ can\ be\ used,\ which\ would\ be\ incorrect.\n\ By\ using\ the\ offset\ of\ a\ factor\ of\ 10\ below\ the\ desired\ length\ we\ can\ generate\ between\ 0\ and\ 899,999.\n\ After\ this,\ we\ can\ add\ 100,000\ back\ to\ the\ number\ to\ ensure\ a\ baseline\ length\ is\ maintained.\n\ \n\ Note\:\ I\ am\ aware\ that\ this\ is\ overengineered,\ and\ that\ several\ random\ integers\ of\ amount\ @length\ could\ be\ used,\ \n\ but\ this\ is\ considerably\ more\ efficient\ since\ there\ is\ no\ iteration\ involved\ in\ the\ creation\ of\ the\ ID.\ O(1)\n
comment6.params= comment6.params=
comment6.target=void\ printAll() comment6.target=void\ printLibraryReservations()
comment6.text=\n\ Prints\ to\ the\ terminal,\ in\ a\ human-readable\ format,\ all\ items\ in\ the\ itemList\n\ \n\ Contains\ a\ marker\ at\ the\ start\ and\ end\ to\ visualise\ in\ terminal\ output.\n comment6.text=\n\ Prints\ to\ the\ terminal,\ in\ a\ human-readable\ format,\ library\ reservation\ in\ the\ itemList\n\ \n\ Contains\ a\ marker\ at\ the\ start\ and\ end\ to\ visualise\ in\ terminal\ output.\n
comment7.params= comment7.params=
comment7.target=void\ readData() comment7.target=void\ printAll()
comment7.text=\n\ A\ method\ to\ read\ all\ data\ from\ files\ using\ a\ fileDialog\ to\ specify\ file\ location.\n\ This\ will\ create\ the\ corresponding\ objects\ depending\ on\ flags\ contained\ in\ the\ file\n\ and\ populate\ it's\ fields.\n\ \n\ Default\ flag\ value\:\ "book",\ to\ support\ legacy\ files.\ This\ will\ not\ interfere\ with\ \n\ files\ of\ different\ flag\ orders.\n comment7.text=\n\ Prints\ to\ the\ terminal,\ in\ a\ human-readable\ format,\ all\ items\ in\ the\ itemList\n\ \n\ Contains\ a\ marker\ at\ the\ start\ and\ end\ to\ visualise\ in\ terminal\ output.\n
numComments=8 comment8.params=start\ end
comment8.target=void\ printDiaryEntries(java.lang.String,\ java.lang.String)
comment9.params=
comment9.target=void\ writeLibraryReservationData()
comment9.text=\n\ Write\ all\ current\ library\ reservations\ to\ a\ file\ specified\ by\ the\ user.\n
numComments=15

View File

@@ -1,11 +1,3 @@
/**
* Class to create objects of a Library, which can hold and report on assets held within
*
* @George Wilkinson
* @3.0
*/
// Import all required libraries. Not using .* as it is not good practice due to potential conflicts. // Import all required libraries. Not using .* as it is not good practice due to potential conflicts.
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
@@ -14,21 +6,33 @@ import java.util.Scanner;
import java.util.Random; import java.util.Random;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Date;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.awt.FileDialog; import java.awt.FileDialog;
import java.awt.Frame; import java.awt.Frame;
import java.io.PrintWriter; import java.io.PrintWriter;
/**
* Class to create objects of a Library, which can hold and report on assets held within
*
* @author George Wilkinson
* @version 3.0
*/
public class Library public class Library
{ {
// private List<LibraryItem> itemList; // Initialise an ArrayList of name itemList to store Library Items // private List<LibraryItem> itemList; // Initialise an ArrayList of name itemList to store Library Items
// private List<LibraryUser> userList; // Initialise an ArrayList of name userList to store Library Users // private List<LibraryUser> userList; // Initialise an ArrayList of name userList to store Library Users
/* No longer needed, as we can use the keys of customerMap.
private HashSet<String> uuidSet; // Initialise a Hash Set of name uuidSet ( unique user identifier ) to store unique user IDs for efficient O(1) searching private HashSet<String> uuidSet; // Initialise a Hash Set of name uuidSet ( unique user identifier ) to store unique user IDs for efficient O(1) searching
*/
private Map<String, LibraryUser> customerMap; private Map<String, LibraryUser> customerMap;
private Map<String, LibraryItem> itemsMap; private Map<String, LibraryItem> itemsMap;
private Map<String, LibraryReservation> libraryReservationMap; private Map<String, LibraryReservation> libraryReservationMap;
private Diary diary;
/* /*
* Constructor for objects of class Library * Constructor for objects of class Library
*/ */
@@ -36,17 +40,26 @@ public class Library
{ {
// itemList = new ArrayList<LibraryItem>(); // itemList = new ArrayList<LibraryItem>();
// userList = new ArrayList<LibraryUser>(); // userList = new ArrayList<LibraryUser>();
/* No longer needed, can use keys of customerMap.
uuidSet = new HashSet<String>(); uuidSet = new HashSet<String>();
*/
customerMap = new HashMap<String, LibraryUser>(); customerMap = new HashMap<String, LibraryUser>();
itemsMap = new HashMap<String, LibraryItem>(); itemsMap = new HashMap<String, LibraryItem>();
libraryReservationMap = new HashMap<String, LibraryReservation>(); libraryReservationMap = new HashMap<String, LibraryReservation>();
diary = new Diary();
} }
/**
* Storing Objects Start
*/
/* /*
* Inserts object value item alongside key of @itemCode into @itemsMap. * Inserts object value item alongside key of @itemCode into @itemsMap.
*/ */
public void storeItem( LibraryItem item ) private void storeItem( LibraryItem item )
{ {
// itemList.add( item ); // itemList.add( item );
itemsMap.put( item.getItemCode(), item ); itemsMap.put( item.getItemCode(), item );
@@ -56,31 +69,55 @@ public class Library
* Inserts object value user alongside key of @userID into @customerMap. * Inserts object value user alongside key of @userID into @customerMap.
* If the userID is set to unknown, it will call @generateUserID. * If the userID is set to unknown, it will call @generateUserID.
*/ */
public void storeUser( LibraryUser user ) private void storeUser( LibraryUser user )
{ {
// userList.add( user ); // userList.add( user );
System.out.println( "User Storing: " + user.getFirstName() );
if ( user.getUserID().equals( "unknown" ) ) if ( user.getUserID().equals( "unknown" ) )
{ {
user.setUserID( generateUserID( "AB-", 6 ) ); user.setUserID( generateUserID( "AB-", 6 ) );
} }
customerMap.put( user.getUserID(), user ); customerMap.put( user.getUserID(), user ); // Store the user along with the userID.
} }
/* /*
* Inserts object value reservation alongside key of @reservationNo into @libraryReservationMap. * Inserts object value reservation alongside key of @reservationNo into @libraryReservationMap.
*/ */
public void storeLibraryReservation( LibraryReservation reservation ) private void storeLibraryReservation( LibraryReservation reservation )
{ {
libraryReservationMap.put( reservation.getReservationNo(), reservation ); libraryReservationMap.put( reservation.getReservationNo(), reservation );
diary.addReservation( reservation );
} }
public void generateReservationNo() /**
* Storing Objects End
*/
/**
* Generate IDs Start
*/
/*
* Generate a sequential reservation number. Since Maps do not have an index, we cannot simply get the last value,
* and recursion would be too intensive for this application. As a placeholder for the file output, a field variable
* is used to hold the last highest value for the reservation number. Unlike @generateUserID, this has a maximum value
* hardcoded to the spec. This likely will not be an issue since we can still have 1,000,000 reservations.
*/
public String generateReservationNo()
{ {
if( libraryReservationMap.values() = null ) /*
return "000001"; * Originally, I did not check if the number was already taken, however the last part of step 4 introduced deletion.
* When a reservation is deleted that does not have the highest reservation number, conflicting reservation numbers are generated.
* e.g. 5 reservations, reservation 3 ID: 000003 is deleted. The next reservation number would be 000004, as the size + 1 = 4
*/
String candidateNo = String.format("%06d", libraryReservationMap.size() + 1);
for ( int i = 1; libraryReservationMap.containsKey( candidateNo ); i++ )
{
candidateNo = String.format( "%06d", libraryReservationMap.size() + i );
} }
return candidateNo;
}
/* /*
* Returns a random unique user ID by specifying * Returns a random unique user ID by specifying
* @prefix - arbitrary alphanumeric prefix * @prefix - arbitrary alphanumeric prefix
@@ -97,13 +134,13 @@ public class Library
* Note: I am aware that this is overengineered, and that several random integers of amount @length could be used, * Note: I am aware that this is overengineered, and that several random integers of amount @length could be used,
* but this is considerably more efficient since there is no iteration involved in the creation of the ID. O(1) * but this is considerably more efficient since there is no iteration involved in the creation of the ID. O(1)
*/ */
public String generateUserID( String prefix, int length ) private String generateUserID( String prefix, int length )
{ {
Random random = new Random(); Random random = new Random();
final int offset = (int) Math.pow( 10, (length-1) ); // Static integer equal to 10^(length-1) lower than length. This will allow for the factor to be consistent. final int offset = (int) Math.pow( 10, (length-1) ); // Static integer equal to 10^(length-1) lower than length. This will allow for the factor to be consistent.
int intLength = (int) ( Math.pow( 10, length ) ) - offset ; // Integer equal to 10^(length) minus the offset. This creates a ceiling for the ID range. int intLength = (int) ( Math.pow( 10, length ) ) - offset ; // Integer equal to 10^(length) minus the offset. This creates a ceiling for the ID range.
if ( uuidSet.size() > ( intLength - 1 ) ) { // No idea why I get an error for equals FIX LATER if ( customerMap.size() == intLength ) {
System.out.println("Too many user IDs delegated for current range, increasing ID range by a factor of 10"); System.out.println("Too many user IDs delegated for current range, increasing ID range by a factor of 10");
return generateUserID( prefix, length+1 ); return generateUserID( prefix, length+1 );
/* /*
@@ -118,19 +155,100 @@ public class Library
* Add the offset to a random number, to create a floor to the ID range. * Add the offset to a random number, to create a floor to the ID range.
*/ */
if ( uuidSet.contains( uuid ) ) if ( customerMap.containsKey( uuid ) ) // Previously uuidSet.contains, replaced to de-dupe held data.
{ {
generateUserID( prefix, length ); // If the ID generated is already contained in the hashset, the method should be called again. generateUserID( prefix, length ); // If the ID generated is already contained in the hashset, the method should be called again.
} }
uuidSet.add( uuid ); // Add the UUID to the hash set so it cannot be returned from this method more than once. /* No longer needed, as we add the user and the ID to the customerMap when storing.
* uuidSet.add( uuid )
*/
return uuid; return uuid;
} }
/**
* Generate IDs End
*/
/**
* Print Object Details Start
*/
/*
* Prints to the terminal, in a human-readable format, library reservation in the itemList
*
* Contains a marker at the start and end to visualise in terminal output.
*/
public void printLibraryReservations() {
System.out.println( "Reservation Details Start" );
for ( LibraryReservation reservation : libraryReservationMap.values() ){
System.out.println("---------------");
reservation.printDetails();
}
System.out.println( "---------------\nReservation Details End\n" );
}
/*
* Prints to the terminal, in a human-readable format, all items in the itemList
*
* Contains a marker at the start and end to visualise in terminal output.
*/
public void printAll()
{
System.out.println("\n\nItem Details Start");
for( LibraryItem item : itemsMap.values() )
{
System.out.println("---------------");
item.printDetails();
}
System.out.println("---------------");
System.out.println("Items Details End\n\n---------------\n\nUser Details Start\n");
for ( LibraryUser user : customerMap.values() )
{
System.out.println("---------------");
user.printDetails();
}
System.out.println("---------------\nUser Details End\n");
printLibraryReservations();
}
public void printDiaryEntries( String start, String end )
{
diary.printEntries( DateUtil.convertStringToDate( start ), DateUtil.convertStringToDate( end ) );
}
/**
* Print Object Details End
*/
/**
* Write Files Start
*/
/*
* Write all current library reservations to a file specified by the user.
*/
public void writeLibraryReservationData()
{
try {
Frame frame = null; // Initialise null frame
FileDialog fileBox = new FileDialog( frame, "Save", FileDialog.SAVE ); // Initialise file dialog box to save written data.
fileBox.setVisible( true );
PrintWriter writer = new PrintWriter( new File( fileBox.getDirectory() + fileBox.getFile() ) );
for ( LibraryReservation reservation : libraryReservationMap.values() ) {
reservation.writeData( writer );
}
writer.close();
}
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
}
}
/* /*
* A method to output all user data to a file using a fileDialog to specify file location. * A method to output all user data to a file using a fileDialog to specify file location.
* *
* Note: Potentially could implement the HashSet made for GenerateUserID to avoid unnecessary recursion.
*/ */
public void writeUserData() public void writeUserData()
{ {
@@ -140,6 +258,7 @@ public class Library
fileBox.setVisible( true ); fileBox.setVisible( true );
PrintWriter writer = new PrintWriter( new File( fileBox.getDirectory() + fileBox.getFile() ) ); PrintWriter writer = new PrintWriter( new File( fileBox.getDirectory() + fileBox.getFile() ) );
// for ( LibraryUser user : userList ){ // for ( LibraryUser user : userList ){
writer.println("[Library User data]");
for ( LibraryUser user : customerMap.values() ) { for ( LibraryUser user : customerMap.values() ) {
user.writeData( writer ); user.writeData( writer );
} }
@@ -150,20 +269,37 @@ public class Library
} }
} }
/* /**
* Prints to the terminal, in a human-readable format, all items in the itemList * Write Files End
*
* Contains a marker at the start and end to visualise in terminal output.
*/ */
public void printAll()
/**
* Read Files Start
*/
/*
* Read Library Reservation Data from a file specified by the user.
*/
public void readLibraryReservationData()
{ {
System.out.println("\n\nStart Detail Print"); try {
for( LibraryItem item : itemsMap.values() ) Frame frame = null; // Initialise null frame
FileDialog fileBox = new FileDialog( frame, "Load", FileDialog.LOAD ); // Initialise file dialog box to save written data.
fileBox.setVisible( true );
Scanner reservationScanner = new Scanner ( new File( fileBox.getDirectory() + fileBox.getFile() ) );
while ( reservationScanner.hasNextLine() )
{ {
System.out.println("---------------"); Scanner detailScanner = new Scanner( reservationScanner.nextLine() ).useDelimiter(",");
item.printDetails(); LibraryReservation reservation = new LibraryReservation();
reservation.readData( detailScanner );
storeLibraryReservation( reservation );
detailScanner.close();
}
reservationScanner.close(); // Close Scanner
}
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
} }
System.out.println("End Detail Print\n");
} }
/* /*
@@ -211,54 +347,116 @@ public class Library
} }
// Could be a switch case to be more efficient // Unfortunately cannot use switch case with string comparisons in Java 8.
// Check current flag for data processing. // Check current flag for data processing.
else { else {
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list
LibraryItem item = null; // Initialise LibraryItem object. Java compiler was being cautious here, so I have to assign the value null.
if ( typeFlag.equals( "book" ) ) { if ( typeFlag.equals( "book" ) ) {
// Process Book Data // Process Book Data
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list item = new Book();
LibraryItem book = new Book();
book.readItemData( detailScanner );
storeItem( book ); // Store the new LibraryItem in the itemList
} }
else if ( typeFlag.equals( "periodical" ) ) { else if ( typeFlag.equals( "periodical" ) ) {
// Process Periodic Data // Process Periodic Data
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); item = new Periodical();
LibraryItem periodical = new Periodical();
periodical.readItemData( detailScanner );
storeItem( periodical );
} }
else if ( typeFlag.equals( "cd" ) ) { else if ( typeFlag.equals( "cd" ) ) {
//Process CD Data //Process CD Data
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); item = new CD();
LibraryItem cd = new CD();
cd.readItemData( detailScanner );
storeItem( cd );
} }
else if ( typeFlag.equals( "dvd" ) ) { else if ( typeFlag.equals( "dvd" ) ) {
//Process DVD Data //Process DVD Data
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); item = new DVD();
LibraryItem dvd = new DVD();
dvd.readItemData( detailScanner );
storeItem( dvd );
} }
else if ( typeFlag.equals( "user" ) ) { else if ( typeFlag.equals( "user" ) ) {
//Process User Data //Process User Data
System.out.println( "User: " + lineItem );
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(",");
LibraryUser user = new LibraryUser(); LibraryUser user = new LibraryUser();
user.readData( detailScanner ); user.readData( detailScanner );
storeUser( user ); storeUser( user );
continue;
} }
else if ( typeFlag.equals( "generic" ) ) { else if ( typeFlag.equals( "generic" ) ) {
// Output unaccepted lines to terminal // Output unaccepted lines to terminal
System.out.println( lineItem ); System.out.println( lineItem );
continue;
}
item.readItemData( detailScanner );
storeItem( item );
detailScanner.close();
} }
} }
} fileScanner.close();
} }
catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection. catch( IOException e ) { // Catch any IO Exceptions that may occur from improper file selection.
System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." ); System.err.println( "Caught IOException: " + e.getMessage() + "\nAn I/O Exception has occurred, please check file is readable and correct format." );
} }
} }
/**
* Read Files End
*/
/**
* Other Methods
*/
/*
* Create a reservation to allow a user to reserve an item from the library.
*/
public boolean makeLibraryReservation( String userID, String itemCode, String startDate, int noOfDays )
{
if ( !customerMap.containsKey( userID ) )
{
System.out.println( "User does not exist" );
return false;
}
if ( !itemsMap.containsKey( itemCode ) )
{
System.out.println( "Item does not exist in library" );
return false;
}
if ( !DateUtil.isValidDateString( startDate ) )
{
System.out.println( "Date is not valid" );
return false;
}
if ( !(noOfDays > 0) )
{
System.out.println( "Reservation must be more than 0 days" );
return false;
}
Date start = DateUtil.convertStringToDate( startDate );
/*
* Unneeded, since addReservations returns any item currently on loan. Dates do not need to be checked for every day in loan.
* Date end = DateUtil.incrementDate( start, noOfDays-1 );
*/
String rID = generateReservationNo();
LibraryReservation reservation = new LibraryReservation( rID, itemCode, userID, startDate, noOfDays );
/** Instead of the following For loop, I could've implemented
* Arrays.asList( diary.getReservation( start, end ).contains( reservation )
* Although this would've been easier, this implementation is more in the scope of what we have learned.
**/
for ( LibraryReservation diaryReservation : diary.getReservations( start ) )
{
if ( diaryReservation.toString().equals( reservation.toString() ) )
{
return false;
}
}
storeLibraryReservation( reservation );
return true;
}
public void deleteLibraryReservation( String reservationNo )
{
if ( libraryReservationMap.containsKey( reservationNo ) )
{
diary.deleteReservation( libraryReservationMap.get( reservationNo ) );
libraryReservationMap.remove( reservationNo );
}
}
} }

View File

@@ -1,15 +1,13 @@
/**
* Superclass of items / assets stored in a Library.
*
* @George Wilkinson
* @3.1
*/
import java.util.Scanner; import java.util.Scanner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
/**
* Superclass of items / assets stored in a Library.
*
* @author George Wilkinson
* @version 3.1
*/
public abstract class LibraryItem public abstract class LibraryItem
{ {
// instance variables // instance variables

View File

@@ -3,33 +3,44 @@ comment0.params=reservationNo\ itemCode\ userID\ startDate\ noOfDays
comment0.target=LibraryReservation(java.lang.String,\ java.lang.String,\ java.lang.String,\ java.lang.String,\ int) comment0.target=LibraryReservation(java.lang.String,\ java.lang.String,\ java.lang.String,\ java.lang.String,\ int)
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryReservation\n comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryReservation\n
comment1.params= comment1.params=
comment1.target=java.lang.String\ getReservationNo() comment1.target=LibraryReservation()
comment1.text=\n\ Return\ value\ of\ @reservationNo\n comment10.params=
comment10.params=noOfDays comment10.target=int\ getNoOfDays()
comment10.target=void\ setNoOfDays(int) comment10.text=\n\ Return\ value\ of\ @noOfDays\n
comment10.text=\n\ Set\ @noOfDays\ to\ a\ new\ value\n comment11.params=reservationNo
comment11.target=void\ setReservationNo(java.lang.String)
comment11.text=\n\ Set\ @reservationNo\ to\ a\ new\ value\n
comment12.params=itemCode
comment12.target=void\ setItemCode(java.lang.String)
comment12.text=\n\ Set\ @itemCode\ to\ a\ new\ value\n
comment13.params=userID
comment13.target=void\ setUserID(java.lang.String)
comment13.text=\n\ Set\ @userID\ to\ a\ new\ value\n
comment14.params=startDate
comment14.target=void\ setStartDate(java.lang.String)
comment14.text=\n\ Set\ @startDate\ to\ a\ new\ value\n
comment15.params=noOfDays
comment15.target=void\ setNoOfDays(int)
comment15.text=\n\ Set\ @noOfDays\ to\ a\ new\ value\n
comment2.params= comment2.params=
comment2.target=java.lang.String\ getItemCode() comment2.target=java.lang.String\ toString()
comment2.text=\n\ Return\ value\ of\ @itemCode\n
comment3.params= comment3.params=
comment3.target=java.lang.String\ getUserID() comment3.target=void\ printDetails()
comment3.text=\n\ Return\ value\ of\ @userID\n comment3.text=\n\ Prints\ to\ terminal,\ the\ details\ of\ the\ reservation.\n
comment4.params= comment4.params=writer
comment4.target=java.util.Date\ getStartDate() comment4.target=void\ writeData(java.io.PrintWriter)
comment4.text=\n\ Return\ value\ of\ @startDate\n comment5.params=detailScanner
comment5.params= comment5.target=void\ readData(java.util.Scanner)
comment5.target=int\ getNoOfDays() comment6.params=
comment5.text=\n\ Return\ value\ of\ @noOfDays\n comment6.target=java.lang.String\ getReservationNo()
comment6.params=reservationNo comment6.text=\n\ Return\ value\ of\ @reservationNo\n
comment6.target=void\ setReservationNo(java.lang.String) comment7.params=
comment6.text=\n\ Set\ @reservationNo\ to\ a\ new\ value\n comment7.target=java.lang.String\ getItemCode()
comment7.params=itemCode comment7.text=\n\ Return\ value\ of\ @itemCode\n
comment7.target=void\ setItemCode(java.lang.String) comment8.params=
comment7.text=\n\ Set\ @itemCode\ to\ a\ new\ value\n comment8.target=java.lang.String\ getUserID()
comment8.params=userID comment8.text=\n\ Return\ value\ of\ @userID\n
comment8.target=void\ setUserID(java.lang.String) comment9.params=
comment8.text=\n\ Set\ @userID\ to\ a\ new\ value\n comment9.target=java.util.Date\ getStartDate()
comment9.params=startDate comment9.text=\n\ Return\ value\ of\ @startDate\n
comment9.target=void\ setStartDate(java.lang.String) numComments=16
comment9.text=\n\ Set\ @startDate\ to\ a\ new\ value\n
numComments=11

View File

@@ -7,6 +7,8 @@
*/ */
import java.util.Date; import java.util.Date;
import java.io.PrintWriter;
import java.util.Scanner;
public class LibraryReservation public class LibraryReservation
{ {
@@ -29,6 +31,42 @@ public class LibraryReservation
this.noOfDays = noOfDays; this.noOfDays = noOfDays;
} }
public LibraryReservation(){}
public String toString()
{
return reservationNo + " " + userID + " " + itemCode;
}
/*
* Prints to terminal, the details of the reservation.
*/
public void printDetails()
{
System.out.println( "Reservation Number: " + reservationNo +
"\nItem Code: " + itemCode +
"\nUser ID: " + userID +
"\nDate Commencing: " + DateUtil.convertDateToShortString( startDate ) +
"\nDuration: " + noOfDays + " days" );
}
public void writeData( PrintWriter writer )
{
writer.print( reservationNo + "," + itemCode + "," + userID + "," + DateUtil.convertDateToShortString( startDate ) + "," + noOfDays );
writer.flush();
}
public void readData( Scanner detailScanner )
{
if ( detailScanner != null ) {
this.reservationNo = detailScanner.next().trim();
this.itemCode = detailScanner.next().trim();
this.userID = detailScanner.next().trim();
this.startDate = DateUtil.convertStringToDate( detailScanner.next().trim() );
this.noOfDays = Integer.parseInt( detailScanner.next().trim() );
}
}
/* /*
* Start Accessor * Start Accessor
*/ */

View File

@@ -1,7 +1,7 @@
#BlueJ class context #BlueJ class context
comment0.params= comment0.params=
comment0.target=LibraryUser() comment0.target=LibraryUser()
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser\n comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryUser.\ As\ fields\ \n
comment1.params= comment1.params=
comment1.target=java.lang.String\ getUserID() comment1.target=java.lang.String\ getUserID()
comment1.text=\n\ Accessor\ start\ -\ return\ values\ of\ corresponding\ variables.\n comment1.text=\n\ Accessor\ start\ -\ return\ values\ of\ corresponding\ variables.\n

View File

@@ -15,7 +15,7 @@ public class LibraryUser
private String userID, surname, firstName, otherInitials, title; private String userID, surname, firstName, otherInitials, title;
/** /**
* Constructor for objects of class LibraryUser * Constructor for objects of class LibraryUser. As fields
*/ */
public LibraryUser(){} public LibraryUser(){}

View File

@@ -0,0 +1 @@
0,LM005002,AB-217000,24-03-2024,3

View File

@@ -1,4 +1,5 @@
AB-906182, Smith, Sara, C, Ms [Library User data]
AB-241496, Evans, David, , Dr AB-217000, Gregson, Brian, R T, Mr
AB-769390, Newton, David, E, Dr AB-711612, Smith, Sara, C, Ms
AB-396038, Gregson, Brian, R T, Mr AB-861906, Evans, David, , Dr
AB-573164, Newton, David, E, Dr

View File

@@ -0,0 +1,379 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
DateUtil
</TITLE>
<META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="DateUtil";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
Class DateUtil</H2>
<PRE>
java.lang.Object
<IMG SRC="./resources/inherit.gif" ALT="extended by "><B>DateUtil</B>
</PRE>
<HR>
<DL>
<DT><PRE>public class <B>DateUtil</B><DT>extends java.lang.Object</DL>
</PRE>
<P>
A class DateUtil with the following methods for dealing with dates.
public static String convertDateToLongString(Date date)
public static String convertDateToShortString(Date date)
public static Date convertStringToDate(String dateString)
public static int daysBetween(Date startDate, Date endDate)
public static Date incrementDate(Date date, int noOfDays)
public static boolean isLeapYear(int year)
public static boolean isValidDateString(String dateString)
public static Date nextDate(Date date)
<P>
<P>
<DL>
<DT><B>Author:</B></DT>
<DD>D E Newton</DD>
</DL>
<HR>
<P>
<!-- =========== FIELD SUMMARY =========== -->
<A NAME="field_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Field Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.text.SimpleDateFormat</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#dateFormatter">dateFormatter</A></B></CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
</TABLE>
&nbsp;
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="DateUtil.html#DateUtil()">DateUtil</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#convertDateToLongString(java.util.Date)">convertDateToLongString</A></B>(java.util.Date&nbsp;date)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Converts a Date object to a corresponding String in
the long date pattern style "Saturday, 25 March 2023".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.lang.String</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#convertDateToShortString(java.util.Date)">convertDateToShortString</A></B>(java.util.Date&nbsp;date)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Converts a Date object to a corresponding String in
the short date pattern style "25-03-2023".</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.util.Date</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#convertStringToDate(java.lang.String)">convertStringToDate</A></B>(java.lang.String&nbsp;dateString)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Converts a string in the short date pattern style "25-03-2023"
to a corresponding Date object.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#daysBetween(java.util.Date, java.util.Date)">daysBetween</A></B>(java.util.Date&nbsp;startDate,
java.util.Date&nbsp;endDate)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Calculates the number of days between two given dates, startDate and endDate.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.util.Date</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#incrementDate(java.util.Date, int)">incrementDate</A></B>(java.util.Date&nbsp;date,
int&nbsp;noOfDays)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Given date, a Date object, and noOfDays, an int, the method returns
a Date object corresponding to noOfDays later than date.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#isLeapYear(int)">isLeapYear</A></B>(int&nbsp;year)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Given year, an int, the method checks to see if the year
is a leap year.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#isValidDateString(java.lang.String)">isValidDateString</A></B>(java.lang.String&nbsp;dateString)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Given dateString, a String, the method checks to see if string
corresponds to a valid shortDatePattern.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static&nbsp;java.util.Date</CODE></FONT></TD>
<TD><CODE><B><A HREF="DateUtil.html#nextDate(java.util.Date)">nextDate</A></B>(java.util.Date&nbsp;date)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Given date, a Date object, the method returns
a Date object corresponding to the next day.</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ============ FIELD DETAIL =========== -->
<A NAME="field_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Field Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="dateFormatter"><!-- --></A><H3>
dateFormatter</H3>
<PRE>
public static java.text.SimpleDateFormat <B>dateFormatter</B></PRE>
<DL>
<DL>
</DL>
</DL>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="DateUtil()"><!-- --></A><H3>
DateUtil</H3>
<PRE>
public <B>DateUtil</B>()</PRE>
<DL>
</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="convertDateToLongString(java.util.Date)"><!-- --></A><H3>
convertDateToLongString</H3>
<PRE>
public static java.lang.String <B>convertDateToLongString</B>(java.util.Date&nbsp;date)</PRE>
<DL>
<DD>Converts a Date object to a corresponding String in
the long date pattern style "Saturday, 25 March 2023".
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>date</CODE> - a Date object
<DT><B>Returns:</B><DD>a String, containing a long date pattern</DL>
</DD>
</DL>
<HR>
<A NAME="convertDateToShortString(java.util.Date)"><!-- --></A><H3>
convertDateToShortString</H3>
<PRE>
public static java.lang.String <B>convertDateToShortString</B>(java.util.Date&nbsp;date)</PRE>
<DL>
<DD>Converts a Date object to a corresponding String in
the short date pattern style "25-03-2023".
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>date</CODE> - a Date object
<DT><B>Returns:</B><DD>a String, containing a short date pattern</DL>
</DD>
</DL>
<HR>
<A NAME="convertStringToDate(java.lang.String)"><!-- --></A><H3>
convertStringToDate</H3>
<PRE>
public static java.util.Date <B>convertStringToDate</B>(java.lang.String&nbsp;dateString)</PRE>
<DL>
<DD>Converts a string in the short date pattern style "25-03-2023"
to a corresponding Date object.
Any leading or trailing spaces are first removed from the date string.
The String parameter that represent a date as a string must be in the
format dd-mm-yyy (e.g. 25-03-2023 or 25-3-2023) where dd represents
one or two digits representing the day in the month, similarly for
mm representing the month in the year and yyyy represents the four
digits for the year.
A RuntimeException is thrown if the date string is not recognised as
a valid date. Such exceptions do not need to be caught or thrown as
they are unchecked exceptions, but can be caught if necessary.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>dateString</CODE> - a Date object
<DT><B>Returns:</B><DD>the Date object</DL>
</DD>
</DL>
<HR>
<A NAME="daysBetween(java.util.Date, java.util.Date)"><!-- --></A><H3>
daysBetween</H3>
<PRE>
public static int <B>daysBetween</B>(java.util.Date&nbsp;startDate,
java.util.Date&nbsp;endDate)</PRE>
<DL>
<DD>Calculates the number of days between two given dates, startDate and endDate.
If startDate is after endDate then the number of days returned will be negative.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>startDate</CODE> - a Date object<DD><CODE>endDate</CODE> - a Date object
<DT><B>Returns:</B><DD>an int, number of days between the dates</DL>
</DD>
</DL>
<HR>
<A NAME="incrementDate(java.util.Date, int)"><!-- --></A><H3>
incrementDate</H3>
<PRE>
public static java.util.Date <B>incrementDate</B>(java.util.Date&nbsp;date,
int&nbsp;noOfDays)</PRE>
<DL>
<DD>Given date, a Date object, and noOfDays, an int, the method returns
a Date object corresponding to noOfDays later than date.
If noOfDays is negative, the resulting Date object will be before date.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>date</CODE> - a Date object<DD><CODE>noOfDays</CODE> - an int
<DT><B>Returns:</B><DD>a Date</DL>
</DD>
</DL>
<HR>
<A NAME="isLeapYear(int)"><!-- --></A><H3>
isLeapYear</H3>
<PRE>
public static boolean <B>isLeapYear</B>(int&nbsp;year)</PRE>
<DL>
<DD>Given year, an int, the method checks to see if the year
is a leap year.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>year,</CODE> - an int
<DT><B>Returns:</B><DD>a boolean, true only if the year is a leap year.</DL>
</DD>
</DL>
<HR>
<A NAME="isValidDateString(java.lang.String)"><!-- --></A><H3>
isValidDateString</H3>
<PRE>
public static boolean <B>isValidDateString</B>(java.lang.String&nbsp;dateString)</PRE>
<DL>
<DD>Given dateString, a String, the method checks to see if string
corresponds to a valid shortDatePattern.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>dateString,</CODE> - a String
<DT><B>Returns:</B><DD>a boolean, true only if the dateString is a valid pattern</DL>
</DD>
</DL>
<HR>
<A NAME="nextDate(java.util.Date)"><!-- --></A><H3>
nextDate</H3>
<PRE>
public static java.util.Date <B>nextDate</B>(java.util.Date&nbsp;date)</PRE>
<DL>
<DD>Given date, a Date object, the method returns
a Date object corresponding to the next day.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>noOfDays</CODE> - an int
<DT><B>Returns:</B><DD>a Date</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<HR>
</BODY>
</HTML>

View File

@@ -0,0 +1,220 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 21:31:47 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
Diary
</TITLE>
<META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Diary";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
Class Diary</H2>
<PRE>
java.lang.Object
<IMG SRC="./resources/inherit.gif" ALT="extended by "><B>Diary</B>
</PRE>
<HR>
<DL>
<DT><PRE>public class <B>Diary</B><DT>extends java.lang.Object</DL>
</PRE>
<P>
A class Diary that represents a "diary" of library item reservations.
The diary is structured as a Map of entries in which each entry corresponds
to a specific day. As the map is not accessed in a sequential fashion, it
doesn't matter whether the actual map class is a TreeMap or a HashMap.
<P>
<P>
<DL>
<DT><B>Author:</B></DT>
<DD>D E Newton</DD>
</DL>
<HR>
<P>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="Diary.html#Diary()">Diary</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor for objects of class Diary</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="Diary.html#addReservation(LibraryReservation)">addReservation</A></B>(LibraryReservation&nbsp;itemReservation)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Method for adding a reservation to the diary.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="Diary.html#deleteReservation(LibraryReservation)">deleteReservation</A></B>(LibraryReservation&nbsp;itemReservation)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Method for deleting a reservation from the diary.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;LibraryReservation[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="Diary.html#getReservations(java.util.Date)">getReservations</A></B>(java.util.Date&nbsp;date)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accessor method for returning all reservations that have entries
in the diary for a particular date.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="Diary.html#printEntries(java.util.Date, java.util.Date)">printEntries</A></B>(java.util.Date&nbsp;startDate,
java.util.Date&nbsp;endDate)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Method for displaying the reservations between specified dates.</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="Diary()"><!-- --></A><H3>
Diary</H3>
<PRE>
public <B>Diary</B>()</PRE>
<DL>
<DD>Constructor for objects of class Diary
<P>
</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="addReservation(LibraryReservation)"><!-- --></A><H3>
addReservation</H3>
<PRE>
public void <B>addReservation</B>(LibraryReservation&nbsp;itemReservation)</PRE>
<DL>
<DD>Method for adding a reservation to the diary.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="deleteReservation(LibraryReservation)"><!-- --></A><H3>
deleteReservation</H3>
<PRE>
public void <B>deleteReservation</B>(LibraryReservation&nbsp;itemReservation)</PRE>
<DL>
<DD>Method for deleting a reservation from the diary.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="getReservations(java.util.Date)"><!-- --></A><H3>
getReservations</H3>
<PRE>
public LibraryReservation[] <B>getReservations</B>(java.util.Date&nbsp;date)</PRE>
<DL>
<DD>Accessor method for returning all reservations that have entries
in the diary for a particular date.
<P>
<DD><DL>
<DT><B>Returns:</B><DD>an array of reservations, or null if no entry for that date</DL>
</DD>
</DL>
<HR>
<A NAME="printEntries(java.util.Date, java.util.Date)"><!-- --></A><H3>
printEntries</H3>
<PRE>
public void <B>printEntries</B>(java.util.Date&nbsp;startDate,
java.util.Date&nbsp;endDate)</PRE>
<DL>
<DD>Method for displaying the reservations between specified dates.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<HR>
</BODY>
</HTML>

View File

@@ -0,0 +1,174 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 11:36:09 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
Library
</TITLE>
<META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Library";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
Class Library</H2>
<PRE>
java.lang.Object
<IMG SRC="./resources/inherit.gif" ALT="extended by "><B>Library</B>
</PRE>
<HR>
<DL>
<DT><PRE>public class <B>Library</B><DT>extends java.lang.Object</DL>
</PRE>
<P>
<HR>
<P>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="Library.html#Library()">Library</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
</TABLE>
&nbsp;
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="Library.html#printAll()">printAll</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="Library.html#readData()">readData</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="Library.html#writeUserData()">writeUserData</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
</TABLE>
&nbsp;<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="Library()"><!-- --></A><H3>
Library</H3>
<PRE>
public <B>Library</B>()</PRE>
<DL>
</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="printAll()"><!-- --></A><H3>
printAll</H3>
<PRE>
public void <B>printAll</B>()</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="readData()"><!-- --></A><H3>
readData</H3>
<PRE>
public void <B>readData</B>()</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="writeUserData()"><!-- --></A><H3>
writeUserData</H3>
<PRE>
public void <B>writeUserData</B>()</PRE>
<DL>
<DD><DL>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<HR>
</BODY>
</HTML>

View File

@@ -2,13 +2,13 @@
<!--NewPage--> <!--NewPage-->
<HTML> <HTML>
<HEAD> <HEAD>
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 --> <!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE> <TITLE>
All Classes All Classes
</TITLE> </TITLE>
<META NAME="date" CONTENT="2024-02-29"> <META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"> <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
@@ -22,7 +22,7 @@ All Classes
<TABLE BORDER="0" WIDTH="100%" SUMMARY=""> <TABLE BORDER="0" WIDTH="100%" SUMMARY="">
<TR> <TR>
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="Book.html" title="class in &lt;Unnamed&gt;" target="classFrame">Book</A> <TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="DateUtil.html" title="class in &lt;Unnamed&gt;" target="classFrame">DateUtil</A>
<BR> <BR>
</FONT></TD> </FONT></TD>
</TR> </TR>

View File

@@ -2,13 +2,13 @@
<!--NewPage--> <!--NewPage-->
<HTML> <HTML>
<HEAD> <HEAD>
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 --> <!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE> <TITLE>
All Classes All Classes
</TITLE> </TITLE>
<META NAME="date" CONTENT="2024-02-29"> <META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"> <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
@@ -22,7 +22,7 @@ All Classes
<TABLE BORDER="0" WIDTH="100%" SUMMARY=""> <TABLE BORDER="0" WIDTH="100%" SUMMARY="">
<TR> <TR>
<TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="Book.html" title="class in &lt;Unnamed&gt;">Book</A> <TD NOWRAP><FONT CLASS="FrameItemFont"><A HREF="DateUtil.html" title="class in &lt;Unnamed&gt;">DateUtil</A>
<BR> <BR>
</FONT></TD> </FONT></TD>
</TR> </TR>

View File

@@ -2,13 +2,13 @@
<!--NewPage--> <!--NewPage-->
<HTML> <HTML>
<HEAD> <HEAD>
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 --> <!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE> <TITLE>
Constant Field Values Constant Field Values
</TITLE> </TITLE>
<META NAME="date" CONTENT="2024-02-29"> <META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"> <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">

View File

@@ -2,7 +2,7 @@
<!--NewPage--> <!--NewPage-->
<HTML> <HTML>
<HEAD> <HEAD>
<!-- Generated by javadoc on Thu Feb 29 11:54:14 GMT 2024--> <!-- Generated by javadoc on Thu Mar 21 22:06:18 GMT 2024-->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE> <TITLE>
Generated Documentation (Untitled) Generated Documentation (Untitled)
@@ -23,7 +23,7 @@ Generated Documentation (Untitled)
</HEAD> </HEAD>
<FRAMESET cols="20%,80%" title="" onLoad="top.loadFrames()"> <FRAMESET cols="20%,80%" title="" onLoad="top.loadFrames()">
<FRAME src="allclasses-frame.html" name="packageFrame" title="All classes and interfaces (except non-static nested types)"> <FRAME src="allclasses-frame.html" name="packageFrame" title="All classes and interfaces (except non-static nested types)">
<FRAME src="Book.html" name="classFrame" title="Package, class and interface descriptions" scrolling="yes"> <FRAME src="DateUtil.html" name="classFrame" title="Package, class and interface descriptions" scrolling="yes">
<NOFRAMES> <NOFRAMES>
<H2> <H2>
Frame Alert</H2> Frame Alert</H2>
@@ -31,7 +31,7 @@ Frame Alert</H2>
<P> <P>
This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client.
<BR> <BR>
Link to<A HREF="Book.html">Non-frame version.</A> Link to<A HREF="DateUtil.html">Non-frame version.</A>
</NOFRAMES> </NOFRAMES>
</FRAMESET> </FRAMESET>
</HTML> </HTML>

View File

@@ -23,13 +23,16 @@ UTF-8
/usr/share/bluej/bjdoclet.jar /usr/share/bluej/bjdoclet.jar
-doclet -doclet
bluej.doclet.doclets.formats.html.HtmlDoclet bluej.doclet.doclets.formats.html.HtmlDoclet
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/Book.java /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java
<---- end of javadoc command ----> <---- end of javadoc command ---->
Loading source file /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/Book.java... Loading source file /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java...
Constructing Javadoc information... Constructing Javadoc information...
Standard Doclet version 1.8.0_392 Standard Doclet version 1.8.0_402
Building tree for all the packages and classes... Building tree for all the packages and classes...
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/Book.html... Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/DateUtil.html...
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java:224: warning - @param argument "year," is not a parameter name.
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java:238: warning - @param argument "dateString," is not a parameter name.
/home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/DateUtil.java:259: warning - @param argument "noOfDays" is not a parameter name.
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/package-frame.html... Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/package-frame.html...
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/package-summary.html... Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/package-summary.html...
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/constant-values.html... Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/constant-values.html...
@@ -39,3 +42,4 @@ Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/allclasses-noframe.html... Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/allclasses-noframe.html...
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/index.html... Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/index.html...
Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/stylesheet.css... Generating /home/boris/OneDrive/Computer Science Year 1/Semester 2/Programming 2/Project/Part 2/doc/stylesheet.css...
3 warnings

View File

@@ -2,13 +2,13 @@
<!--NewPage--> <!--NewPage-->
<HTML> <HTML>
<HEAD> <HEAD>
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 --> <!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE> <TITLE>
&lt;Unnamed&gt; &lt;Unnamed&gt;
</TITLE> </TITLE>
<META NAME="date" CONTENT="2024-02-29"> <META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"> <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
@@ -24,7 +24,7 @@
Classes</FONT>&nbsp; Classes</FONT>&nbsp;
<FONT CLASS="FrameItemFont"> <FONT CLASS="FrameItemFont">
<BR> <BR>
<A HREF="Book.html" title="class in &lt;Unnamed&gt;" target="classFrame">Book</A></FONT></TD> <A HREF="DateUtil.html" title="class in &lt;Unnamed&gt;" target="classFrame">DateUtil</A></FONT></TD>
</TR> </TR>
</TABLE> </TABLE>

View File

@@ -2,13 +2,13 @@
<!--NewPage--> <!--NewPage-->
<HTML> <HTML>
<HEAD> <HEAD>
<!-- Generated by javadoc (build 1.8.0_392) on Thu Feb 29 11:54:14 GMT 2024 --> <!-- Generated by javadoc (build 1.8.0_402) on Thu Mar 21 22:06:18 GMT 2024 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE> <TITLE>
</TITLE> </TITLE>
<META NAME="date" CONTENT="2024-02-29"> <META NAME="date" CONTENT="2024-03-21">
<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style"> <LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
@@ -29,8 +29,8 @@ Package &lt;Unnamed&gt;
<B>Class Summary</B></FONT></TH> <B>Class Summary</B></FONT></TH>
</TR> </TR>
<TR BGCOLOR="white" CLASS="TableRowColor"> <TR BGCOLOR="white" CLASS="TableRowColor">
<TD WIDTH="15%"><B><A HREF="Book.html" title="class in &lt;Unnamed&gt;">Book</A></B></TD> <TD WIDTH="15%"><B><A HREF="DateUtil.html" title="class in &lt;Unnamed&gt;">DateUtil</A></B></TD>
<TD>&nbsp;</TD> <TD>A class DateUtil with the following methods for dealing with dates.</TD>
</TR> </TR>
</TABLE> </TABLE>
&nbsp; &nbsp;

View File

@@ -1,4 +1 @@
AB-906182, Smith, Sara, C, Ms [Library User data]
AB-241496, Evans, David, , Dr
AB-769390, Newton, David, E, Dr
AB-396038, Gregson, Brian, R T, Mr

View File

@@ -165,7 +165,7 @@ target8.width=80
target8.x=70 target8.x=70
target8.y=10 target8.y=10
target9.editor.height=1049 target9.editor.height=1049
target9.editor.width=960 target9.editor.width=1920
target9.editor.x=0 target9.editor.x=0
target9.editor.y=31 target9.editor.y=31
target9.height=50 target9.height=50

View File

@@ -0,0 +1 @@
File Input / Output

View File

@@ -0,0 +1,15 @@
Recursion via factorial function
```java
int fact(int n)
{
int result;
if(n==0 || n==1)
return 1;
result = fact(n-1) * n;
return result;
}
```
Since factorial(0) or factorial(1) is just 1, we return 1 in these scenarios
If we have factorial(2), we would do factorial(1)\*2 = 2
fact(5) = factorial(4) \* 5 = 5\*4\*3\*2\*1 = 120

View File

@@ -0,0 +1,35 @@
```java
public class IntNode
{
public int info;
public IntNode next;
}
```
![](Pasted%20image%2020240319224232.png)
a) Write code to add 50 to the appropriate field of the node pointed to by temp.
```java
temp.info += 50;
```
b) Write code to remove from the list the item after temp.
```java
temp.next = temp.next.next;
```
c) Write the code to remove from the list temp.
```java
temp.info = temp.next.info; // Assign the next node's value to temp - this will overwrite temp's value.
temp.next = temp.next.next; // Set the pointer for temp's next node to the node after the value taken for temp - this effectively clones temp.next and replaces temp.
```
d) Write code to go through the list and to sum all the values within the list. You may assume the existence of head, a reference to the start of the list.
```java
IntNode current = head;
int sum = 0;
while ( current != null ) {
sum += current.info;
current = current.next;
}
```

View File

@@ -0,0 +1,53 @@
a) List the order in which the nodes are visited in:
post-order.
![](Pasted%20image%2020240319225420.png)
D,B,F,G,E,C,A
pre-order
A,B,D,C,E,F,G
in-order
D,B,F,E,G,C,A
b)
```java
public class BinTreeNode
{
public String info;
public BinTreeNode leftChild, rightChild;
}
```
```java
public void postTraverse( BinTreeNode node )
{
if ( node != null )
{
postTraverse( node.leftNode );
postTraverse( node.rightNode );
System.out.println( node.info );
}
}
```
c) The following method counts the number of nodes in the tree
```java
public int countTree(BinTreeNode t)
{
int count;
if (t == null)
count = 0
else
count = countTree(t.leftChild)+countTree(t.rightChild)+1;
return count;
}
```
![](Pasted%20image%2020240319234142.png)
countTree(root)
-> count = countTree(t.leftChild) + countTree(t.rightChild+1)
countTree(t.leftChild)
-> return 1, since left and right child null
countTree(t.rightChild)
-> return 1, since left and right child null
count = 1 + 1 + 1 = 3

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB