130 lines
2.9 KiB
Java
130 lines
2.9 KiB
Java
|
|
/**
|
|
* Write a description of class LibraryItem here.
|
|
*
|
|
* @author (your name)
|
|
* @version (a version number or a date)
|
|
*/
|
|
|
|
import java.util.Scanner;
|
|
import java.util.ArrayList;
|
|
import java.util.NoSuchElementException;
|
|
|
|
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;
|
|
}
|
|
|
|
/*
|
|
* Default constructor for object of class LibraryItem
|
|
*/
|
|
public LibraryItem()
|
|
{
|
|
title = "";
|
|
itemCode = "";
|
|
cost = 0;
|
|
timesBorrowed = 0;
|
|
onLoan = false;
|
|
}
|
|
|
|
/*
|
|
* 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.\n" );
|
|
else
|
|
System.out.println( "This item is at present not on loan and when new cost " + cost + " pence.\n" );
|
|
}
|
|
|
|
public void readData( Scanner detailScanner ) {
|
|
|
|
if ( detailScanner != null ) {
|
|
this.title = detailScanner.next().trim();
|
|
this.itemCode = detailScanner.next().trim();
|
|
this.cost = Integer.parseInt( detailScanner.next() );
|
|
this.timesBorrowed = Integer.parseInt( detailScanner.next() );
|
|
this.onLoan = Boolean.parseBoolean( detailScanner.next() );
|
|
}
|
|
}
|
|
}
|