vault backup: 2024-02-06 13:09:16
This commit is contained in:
@@ -0,0 +1 @@
|
||||
#
|
Binary file not shown.
@@ -4,6 +4,10 @@ comment0.target=Library()
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Library\n
|
||||
comment1.params=item
|
||||
comment1.target=void\ storeItem(LibraryItem)
|
||||
comment1.text=\n\ Appends\ a\ LibraryItem\ to\ the\ itemList.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ printAllItems()
|
||||
numComments=3
|
||||
comment2.text=\n\ Prints\ to\ the\ terminal\ all\ items\ in\ the\ itemList\n
|
||||
comment3.params=
|
||||
comment3.target=void\ readItemData()
|
||||
numComments=4
|
||||
|
@@ -6,13 +6,21 @@
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
|
||||
// Import all required libraries. Not using .* as it is not good practice due to potential conflicts.
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.IOException;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
|
||||
public class Library
|
||||
{
|
||||
private ArrayList<LibraryItem> itemList;
|
||||
private ArrayList<LibraryItem> itemList; // Initialise an ArrayList of name itemList to store LibraryItems
|
||||
|
||||
/**
|
||||
/*
|
||||
* Constructor for objects of class Library
|
||||
*/
|
||||
public Library()
|
||||
@@ -20,11 +28,17 @@ public class Library
|
||||
itemList = new ArrayList<LibraryItem>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Appends a LibraryItem to the itemList.
|
||||
*/
|
||||
public void storeItem( LibraryItem item )
|
||||
{
|
||||
itemList.add( item );
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints to the terminal all items in the itemList
|
||||
*/
|
||||
public void printAllItems()
|
||||
{
|
||||
for( LibraryItem item : itemList )
|
||||
@@ -33,4 +47,34 @@ public class Library
|
||||
}
|
||||
}
|
||||
|
||||
public void readItemData() //throws IOException
|
||||
{
|
||||
try {
|
||||
Frame frame = null; // Initialise a null frame
|
||||
FileDialog fileBox = new FileDialog( frame, "Open", FileDialog.LOAD ); // Initialise filebox with the null frame pointer
|
||||
fileBox.setVisible( true ); // Open a file selection dialog to the user.
|
||||
|
||||
Scanner fileScanner = new Scanner( new File( fileBox.getDirectory() + fileBox.getFile() ) );
|
||||
|
||||
while( fileScanner.hasNextLine() )
|
||||
{
|
||||
|
||||
String lineItem = fileScanner.nextLine();
|
||||
|
||||
if ( !lineItem.contains( "//" ) && !lineItem.trim().isEmpty() ) { // Ensure no comments or empty lines are included
|
||||
|
||||
Scanner detailScanner = new Scanner ( lineItem ).useDelimiter(","); // Create a new scanner to grab the values in a comma separated list
|
||||
|
||||
LibraryItem libraryItem = new LibraryItem();
|
||||
libraryItem.readData( detailScanner );
|
||||
|
||||
storeItem( libraryItem ); // Store the new LibraryItem in the itemList
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
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." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@@ -3,28 +3,33 @@ 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
|
||||
comment1.target=LibraryItem()
|
||||
comment1.text=\n\ Default\ constructor\ for\ object\ of\ class\ LibraryItem\n
|
||||
comment10.params=timesBorrowed
|
||||
comment10.target=void\ setTimesBorrowed(int)
|
||||
comment11.params=onLoan
|
||||
comment11.target=void\ setOnLoan(boolean)
|
||||
comment12.params=
|
||||
comment12.target=void\ printDetails()
|
||||
comment12.text=\n\ Field\ Mutator\ End\n
|
||||
comment13.params=detailScanner
|
||||
comment13.target=void\ readData(java.util.Scanner)
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getItemCode()
|
||||
comment2.target=java.lang.String\ getTitle()
|
||||
comment2.text=\n\ Field\ Accessor\ Start\n
|
||||
comment3.params=
|
||||
comment3.target=int\ getCost()
|
||||
comment3.target=java.lang.String\ getItemCode()
|
||||
comment4.params=
|
||||
comment4.target=int\ getTimesBorrowed()
|
||||
comment4.target=int\ getCost()
|
||||
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
|
||||
comment5.target=int\ getTimesBorrowed()
|
||||
comment6.params=
|
||||
comment6.target=boolean\ getOnLoan()
|
||||
comment7.params=title
|
||||
comment7.target=void\ setTitle(java.lang.String)
|
||||
comment7.text=\n\ Field\ Accessor\ End\n\ \n\ Field\ Mutator\ Start\n
|
||||
comment8.params=itemCode
|
||||
comment8.target=void\ setItemCode(java.lang.String)
|
||||
comment9.params=cost
|
||||
comment9.target=void\ setCost(int)
|
||||
numComments=14
|
||||
|
@@ -5,6 +5,10 @@
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LibraryItem
|
||||
{
|
||||
// instance variables - replace the example below with your own
|
||||
@@ -26,6 +30,18 @@ public class LibraryItem
|
||||
this.onLoan = onLoan;
|
||||
}
|
||||
|
||||
/*
|
||||
* Default constructor for object of class LibraryItem
|
||||
*/
|
||||
public LibraryItem()
|
||||
{
|
||||
title = "";
|
||||
itemCode = "";
|
||||
cost = 0;
|
||||
timesBorrowed = 0;
|
||||
onLoan = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Field Accessor Start
|
||||
*/
|
||||
@@ -94,10 +110,16 @@ public class LibraryItem
|
||||
{
|
||||
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." );
|
||||
System.out.println( "This item is at present on loan and when new cost " + cost + " pence.\n" );
|
||||
else
|
||||
System.out.println( "This item is at present not on loan and when new cost " + cost + " pence." );
|
||||
System.out.println( "This item is at present not on loan and when new cost " + cost + " pence.\n" );
|
||||
}
|
||||
|
||||
|
||||
public void readData( Scanner detailScanner ) {
|
||||
this.title = detailScanner.next();
|
||||
this.itemCode = detailScanner.next();
|
||||
this.cost = Integer.parseInt( detailScanner.next() );
|
||||
this.timesBorrowed = Integer.parseInt( detailScanner.next() );
|
||||
this.onLoan = Boolean.parseBoolean( detailScanner.next() );
|
||||
}
|
||||
}
|
||||
|
12
Semester 2/Programming 2/Project/Part 1/item_data_1.txt
Normal file
12
Semester 2/Programming 2/Project/Part 1/item_data_1.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
// this is a comment, any lines that start with //
|
||||
// (and blank lines) should be ignored
|
||||
|
||||
|
||||
// data is title, itemCode, cost, timesBorrowed, onLoan
|
||||
Objects First with Java, LM002411,3989,781,true
|
||||
Compilers: Principles Techniques and Tools, LM002711,599,0,FALSE
|
||||
C# How to Program, LM002876,4599,45,TRUE
|
||||
Unix Made Easy: The Basics and Beyond (Made Easy), LM002468,6395,0,TRUE
|
||||
Galerkin Finite Element Methods for Parabolic Problems, LM002153,4554,0,FALSE
|
||||
|
||||
|
@@ -1,3 +1,41 @@
|
||||
#BlueJ package file
|
||||
#Fri Feb 02 12:26:48 GMT 2024
|
||||
dependency1.from=Library
|
||||
dependency1.to=LibraryItem
|
||||
dependency1.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=1900
|
||||
package.editor.height=874
|
||||
package.editor.width=1774
|
||||
package.editor.x=0
|
||||
package.editor.y=31
|
||||
package.numDependencies=1
|
||||
package.numTargets=2
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
target1.editor.height=1049
|
||||
target1.editor.width=960
|
||||
target1.editor.x=0
|
||||
target1.editor.y=31
|
||||
target1.height=50
|
||||
target1.name=LibraryItem
|
||||
target1.naviview.expanded=true
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=100
|
||||
target1.x=70
|
||||
target1.y=10
|
||||
target2.editor.height=1049
|
||||
target2.editor.width=960
|
||||
target2.editor.x=960
|
||||
target2.editor.y=31
|
||||
target2.height=50
|
||||
target2.name=Library
|
||||
target2.naviview.expanded=true
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.typeParameters=
|
||||
target2.width=80
|
||||
target2.x=170
|
||||
target2.y=60
|
||||
|
@@ -6,11 +6,11 @@ dependency2.from=ZooApp
|
||||
dependency2.to=Zoo
|
||||
dependency2.type=UsesDependency
|
||||
objectbench.height=76
|
||||
objectbench.width=686
|
||||
package.editor.height=400
|
||||
package.editor.width=560
|
||||
package.editor.x=774
|
||||
package.editor.y=277
|
||||
objectbench.width=1900
|
||||
package.editor.height=874
|
||||
package.editor.width=1774
|
||||
package.editor.x=0
|
||||
package.editor.y=31
|
||||
package.numDependencies=2
|
||||
package.numTargets=3
|
||||
package.showExtends=true
|
||||
|
Reference in New Issue
Block a user