public abstract class Person
{
private String firstName;
private String lastName;
private static String title;
private String dateOfBirth;
private String homeAddress;
private String phoneNumber;
public static final String MR = "Mr";
public static final String MISS = "Miss";
public static final String MS = "Ms";
public static final String MRS = "Mrs";
public static final String DR = "DR";
public static final String PROF = "Prof";
public Person(){
homeAddress = "123 Default Street";
phoneNumber = "000-0000";
}
public Person(String firstName, String lastName, String title, String dateOfBirth,
String homeAddress, String phoneNumber){
this.firstName=firstName;
this.lastName=lastName;
this.title=title;
this.dateOfBirth=dateOfBirth;
this.homeAddress=homeAddress;
this.phoneNumber=phoneNumber;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String getTitle(){
return title;
}
public String getBirthDate(){
return dateOfBirth;
}
public String getAddress(){
return homeAddress;
}
public String getNumber(){
return phoneNumber;
}
public void setNumber(String phoneNumber){
this.phoneNumber=phoneNumber;
}
public String allDetails()
{
String persDetails = "First Name: " + firstName +"\n" +
"Last Name: " + lastName +"\n" +
"Title: " + title +"\n" +
"D.O.B: " + dateOfBirth +"\n" +
"Address: " + homeAddress +"\n" +
"Contact Number: " + phoneNumber + "\n";
return persDetails;
}
public String toString()
{
String persDetails = "First Name: " + firstName +"\n" +
"Last Name: " + lastName +"\n";
return persDetails;
}
}
I then have a abstract subclass of this called Borrower
public abstract class Borrower extends Person{
public LibraryItem [] itemsBorrowed;
private double currentFine;
private int barCode;
public LibraryItem [] getItemsBorrowed()
{
return itemsBorrowed;
}
public double getCurrentFine()
{
return currentFine;
}
public int getBarCode()
{
return barCode;
}
public void incrementFine(double addFine)
{
currentFine = currentFine+addFine;
}
public void decrementFine(double reduceFine)
{
currentFine = currentFine-reduceFine;
}
public abstract void addItem();
public void removeItem(LibraryItem[] item, int index)
{
for(int i =0; i <item.length; i ++)
{
item[index]= null;
}
}
public String toString()
{
String borDetails = "Bar code: " + barCode +"\n" +
"Items borrowed: " + itemsBorrowed +"\n";
return borDetails;
}
}
Now the Borrower class has an abstract method getItem(), which is implimented in Borrowers sub class, StudentBorrower
import java.util.Scanner;
public class StudentBorrower extends Borrower
{
private final int maxItems = 7;
private final double maxFine = 5.00;
private String studentId;
public void setId(String studentId)
{
this.studentId=studentId;
}
public int getMaxItems()
{
return maxItems;
}
public double getMaxFine()
{
return maxFine;
}
public String getID()
{
return studentId;
}
public void addItem()
{
if(maxItems>7)
{
System.out.println("The maximum number of items allowed is 7" + "\n" + "You currently have " + maxItems +
"out at the moment");
}
else if(maxFine>5.00)
{
System.out.println("The maximum fine allowed is 5.00" + "\n" + "You currently have " + maxFine +
"worth of fines");
}
else
{
}
}
}
Now this addItem method is supposed to add an LibraryItem which is another abstract class.
public abstract class LibraryItem{
private String itemCode;
private Date dueDate;
private String homeLibrary;
private String title;
public LibraryItem(String itemCode, Date dueDate, String homeLibrary, String title)
{
this.itemCode=itemCode;
this.dueDate=dueDate;
this.homeLibrary=homeLibrary;
this.title=title;
}
public void setDate(Date dueDate)
{
this.dueDate=dueDate;
}
public void setLibrary(String homeLibrary)
{
this.homeLibrary=homeLibrary;
}
public String getCode()
{
return itemCode;
}
public Date getDate()
{
return dueDate;
}
public String getLibrary()
{
return homeLibrary;
}
public String getTitle()
{
return title;
}
public String toString()
{
String libDetails = "Item code: " + itemCode +"\n" +
"Item title: " + title +"\n";
return libDetails;
}
}
But the LibraryItem class is not extended by my StudentBorrower class, so how can i access its constructor in order to create an Item? Obviously i cant do LibraryItem item = new LibraryItem(......) as it cannot be instantiated. I cant do StudentBorrower item = new StudentBorrower(...) as there is no extension between them. So is there any way the constructor can be accessed?
cheers

New Topic/Question
Reply




MultiQuote






|