vault backup: 2024-02-20 13:05:19
This commit is contained in:
129
Semester 2/Programming 2/Project/Part 2/LibraryItem.java
Normal file
129
Semester 2/Programming 2/Project/Part 2/LibraryItem.java
Normal file
@@ -0,0 +1,129 @@
|
||||
|
||||
/**
|
||||
* Emulates an Item in a Library (
|
||||
*
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
|
||||
import java.util.Scanner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public abstract 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;
|
||||
private int noOfPages;
|
||||
private String publisher;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
public int getNoOfPages()
|
||||
{
|
||||
return noOfPages;
|
||||
}
|
||||
|
||||
public String getPublisher()
|
||||
{
|
||||
return publisher;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
public void setNoOfPages( int noOfPages )
|
||||
{
|
||||
this.noOfPages = noOfPages;
|
||||
}
|
||||
|
||||
public void setPublisher( String publisher )
|
||||
{
|
||||
this.publisher = publisher;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 readItemData( Scanner detailScanner ) {
|
||||
|
||||
if ( detailScanner != null ) {
|
||||
this.noOfPages = Integer.parseInt( detailScanner.next().trim() );
|
||||
this.publisher = detailScanner.next().trim();
|
||||
this.title = detailScanner.next().trim();
|
||||
this.itemCode = detailScanner.next().trim();
|
||||
this.cost = Integer.parseInt( detailScanner.next().trim() );
|
||||
this.timesBorrowed = Integer.parseInt( detailScanner.next().trim() );
|
||||
this.onLoan = Boolean.parseBoolean( detailScanner.next().trim() );
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user