diff --git a/Semester 2/Programming 2/Project/Part 1/Library.class b/Semester 2/Programming 2/Project/Part 1/Library.class new file mode 100644 index 0000000..3c64091 Binary files /dev/null and b/Semester 2/Programming 2/Project/Part 1/Library.class differ diff --git a/Semester 2/Programming 2/Project/Part 1/Library.ctxt b/Semester 2/Programming 2/Project/Part 1/Library.ctxt new file mode 100644 index 0000000..1765720 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 1/Library.ctxt @@ -0,0 +1,9 @@ +#BlueJ class context +comment0.params= +comment0.target=Library() +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Library\n +comment1.params=item +comment1.target=void\ storeItem(LibraryItem) +comment2.params= +comment2.target=void\ printAllItems() +numComments=3 diff --git a/Semester 2/Programming 2/Project/Part 1/Library.java b/Semester 2/Programming 2/Project/Part 1/Library.java new file mode 100644 index 0000000..a3d3270 --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 1/Library.java @@ -0,0 +1,36 @@ + +/** + * Write a description of class Library here. + * + * @author (your name) + * @version (a version number or a date) + */ + +import java.util.ArrayList; + +public class Library +{ + private ArrayList itemList; + + /** + * Constructor for objects of class Library + */ + public Library() + { + itemList = new ArrayList(); + } + + public void storeItem( LibraryItem item ) + { + itemList.add( item ); + } + + public void printAllItems() + { + for( LibraryItem item : itemList ) + { + item.printDetails(); + } + } + +} diff --git a/Semester 2/Programming 2/Project/Part 1/LibraryItem.class b/Semester 2/Programming 2/Project/Part 1/LibraryItem.class new file mode 100644 index 0000000..fb1a52e Binary files /dev/null and b/Semester 2/Programming 2/Project/Part 1/LibraryItem.class differ diff --git a/Semester 2/Programming 2/Project/Part 1/LibraryItem.ctxt b/Semester 2/Programming 2/Project/Part 1/LibraryItem.ctxt new file mode 100644 index 0000000..80e21ca --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 1/LibraryItem.ctxt @@ -0,0 +1,30 @@ +#BlueJ class context +comment0.params=title\ itemCode\ cost\ timesBorrowed\ onLoan +comment0.target=LibraryItem(java.lang.String,\ java.lang.String,\ int,\ int,\ boolean) +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ LibraryItem\n +comment1.params= +comment1.target=java.lang.String\ getTitle() +comment1.text=\n\ Field\ Accessor\ Start\n +comment10.params=onLoan +comment10.target=void\ setOnLoan(boolean) +comment11.params= +comment11.target=void\ printDetails() +comment11.text=\n\ Field\ Mutator\ End\n +comment2.params= +comment2.target=java.lang.String\ getItemCode() +comment3.params= +comment3.target=int\ getCost() +comment4.params= +comment4.target=int\ getTimesBorrowed() +comment5.params= +comment5.target=boolean\ getOnLoan() +comment6.params=title +comment6.target=void\ setTitle(java.lang.String) +comment6.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n +comment7.params=itemCode +comment7.target=void\ setItemCode(java.lang.String) +comment8.params=cost +comment8.target=void\ setCost(int) +comment9.params=timesBorrowed +comment9.target=void\ setTimesBorrowed(int) +numComments=12 diff --git a/Semester 2/Programming 2/Project/Part 1/LibraryItem.java b/Semester 2/Programming 2/Project/Part 1/LibraryItem.java new file mode 100644 index 0000000..c63edab --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 1/LibraryItem.java @@ -0,0 +1,103 @@ + +/** + * Write a description of class LibraryItem here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class LibraryItem +{ + // instance variables - replace the example below with your own + private String title; + private String itemCode; + private int cost; + private int timesBorrowed; + private boolean onLoan; + + /** + * Constructor for objects of class LibraryItem + */ + public LibraryItem( String title, String itemCode, int cost, int timesBorrowed, boolean onLoan) + { + this.title = title; + this.itemCode = itemCode; + this.cost = cost; + this.timesBorrowed = timesBorrowed; + this.onLoan = onLoan; + } + + /* + * Field Accessor Start + */ + public String getTitle() + { + return title; + } + + public String getItemCode() + { + return itemCode; + } + + public int getCost() + { + return cost; + } + + public int getTimesBorrowed() + { + return timesBorrowed; + } + + public boolean getOnLoan() + { + return onLoan; + } + + /* + * Field Accessor End + * + * Field Mutator Start + */ + + public void setTitle( String title ) + { + this.title = title; + } + + public void setItemCode( String itemCode ) + { + this.itemCode = itemCode; + } + + public void setCost( int cost ) + { + this.cost = cost; + } + + public void setTimesBorrowed( int timesBorrowed ) + { + this.timesBorrowed = timesBorrowed; + } + + public void setOnLoan( boolean onLoan ) + { + this.onLoan = onLoan; + } + + /* + * Field Mutator End + */ + + // Output to console the details of the fields in a human-readable format. + public void printDetails() + { + System.out.println( title + " with an item code " + itemCode + " has been borrowed " + timesBorrowed + " times."); + if( onLoan ) + System.out.println( "This item is at present on loan and when new cost " + cost + " pence." ); + else + System.out.println( "This item is at present not on loan and when new cost " + cost + " pence." ); + } + + +} diff --git a/Semester 2/Programming 2/Project/Part 1/README.TXT b/Semester 2/Programming 2/Project/Part 1/README.TXT new file mode 100644 index 0000000..2bea2dd --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 1/README.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------ +This is the project README file. Here, you should describe your project. +Tell the reader (someone who does not know anything about this project) +all he/she needs to know. The comments should usually include at least: +------------------------------------------------------------------------ + +PROJECT TITLE: +PURPOSE OF PROJECT: +VERSION or DATE: +HOW TO START THIS PROJECT: +AUTHORS: +USER INSTRUCTIONS: diff --git a/Semester 2/Programming 2/Project/Part 1/package.bluej b/Semester 2/Programming 2/Project/Part 1/package.bluej new file mode 100644 index 0000000..dba651c --- /dev/null +++ b/Semester 2/Programming 2/Project/Part 1/package.bluej @@ -0,0 +1,3 @@ +#BlueJ package file +#Fri Feb 02 12:26:48 GMT 2024 +project.charset=UTF-8