fortune2k
April 18th, 2008, 11:16 AM
hi, i am undertaking a project for my school and well i am not very knowledgable in the world of java andwell this is what i have to do :
Your task is to implement, in Java, an object-oriented system for Octagon Boat Hire.
Your system should contain, at minimum, a Boat, PedalBoat, RowingBoat, and BoatHireCompany class and exploit the key object-oriented concepts encapsulation, inheritance and polymorphism.
You should initially develop and test each class using an appropriate text-based driver (main) class, which does not need to have user interaction (choice or input via Scanner). In order to be able to fulfil the above scenario, the classes you develop should be able to:
Boat, PedalBoat, RowingBoat classes:
o construct a rowing boat
o construct a pedal boat
o mark a boat as hired, storing the customer name and time
o return a boat's details as a String, including customer name and time of hire if it currently hired out
o calculate the amount due on a hired boat, given the time it was brought back
o make a boat that has been brought back available for rehire
BoatHireCompany class:
o construct a company which holds a list of boats
o add a new boat to the list of boats owned by the company
o display the details of all boats owned by the company
o display the details of all pedal boats
o display the details of all rowing boats
o find an available pedal boat
o find an available rowing boat
o display the details of all the boats currently hired out, including the name of the customer who has hired each boat, and the time it was hired
o find a boat given its id number
this is what i have done so far :
BoatHireCompany Class:
package assignment;
import java.util.Scanner;
public class BoatHireCompany {
private RowingBoat [] theRowingBoats;
private PedalBoat [] thePedalBoats;
private int numRowingBoats;
private int numPedalBoats;
private int maxRowingBoats;
private int maxPedalBoats;
private String BoatHireCompanyName;
private RowingBoat [] notime;
public BoatHireCompany (String name, int num)
{
BoatHireCompanyName = name;
maxRowingBoats = num;
numRowingBoats = 0;
maxPedalBoats = num;
numPedalBoats = 0;
theRowingBoats = new RowingBoat[maxRowingBoats];
thePedalBoats = new PedalBoat [maxPedalBoats];
notime = new RowingBoat[maxRowingBoats];
}
public boolean addRowingBoat( RowingBoat newRowingBoat )
{
// add another Boat to the BoatHireCompany if the BoatHireCompany is not full
if ( numRowingBoats == maxRowingBoats )
{
// the BoatHireCompany is full Boat cannot be added
return false;
}
else
{
int stat;
stat=RowingBoat.status;
if(stat==0)
{
theRowingBoats[numRowingBoats] = newRowingBoat;
numRowingBoats++;
}
else
{
notime[numRowingBoats] = newRowingBoat;
}
return true;
}
}
public boolean addPedalBoat( PedalBoat newPedalBoat )
{
// add another Boat to the BoatHireCompany if the BoatHireCompany is not full
if ( numPedalBoats == maxPedalBoats )
{
// the BoatHireCompany is full Boat cannot be added
return false;
}
else
{
// add Boat to the BoatHireCompany
thePedalBoats[numPedalBoats] = newPedalBoat;
numPedalBoats++;
return true;
}
}
public void outputBoatHireCompanyDetails()
{
System.out.println("Company: " + BoatHireCompanyName );
System.out.println("");
//output each Boat in turn
System.out.println("The Rowing Boats:");
for( int i=0; i < numRowingBoats; ++i)
{
System.out.println(theRowingBoats[i].toString());
}
for( int i=0; i < numRowingBoats; ++i)
{
System.out.println(notime[i].toString());
}
System.out.println("\n");
System.out.println("The Pedal Boats:");
for( int i=0; i < numPedalBoats; ++i)
{
System.out.println(thePedalBoats[i].toString());
}
Scanner kybd = new Scanner(System.in);
System.out.println("MENU");
System.out.println("1. Hire a boat");
System.out.println("2. Return a boat");
System.out.println("Please enter your choice:");
int choice = kybd.nextInt();
switch (choice) {
case 1:
}
}
}
Boat Class
package assignment;
public class Boat {
public int ID;
public Boat (int a)
{
ID = a;
}
public String toString() {
String s = "ID:" + ID ;
return s;
}
}
Rowing Boat Class:
package assignment;
public class RowingBoat extends Boat
{
public String Name;
public static int status;
public String stat;
public RowingBoat(int a, String Name, int theStatus)
{
super(a);
this.Name=Name;
status=theStatus;
ID=a;
if(theStatus==0)
{
stat="Unavailable";
}
else
{
stat="Available";
}
}
public int getstat() {
return status;
}
public String toString() {
String s = "ID:" + ID + " Avaliablitiy: " + stat + " Name:" + Name ;
return s;
}
}
Testing Class
package assignment;
public class Test {
// Driver class to test the BoatHireCompany class
public static void main(String[] args) {
BoatHireCompany BoatHire = new BoatHireCompany("BoatHire",15);
BoatHire.addRowingBoat(new RowingBoat (1,"Tedship",1));
BoatHire.addRowingBoat(new RowingBoat (2,"Daveship",0));
BoatHire.outputBoatHireCompanyDetails();
}
}
Well my problem is that i cannont change the boats from availabe to unavaile and vise-versa..... soo for example you have a boat which is availble which a integer is set to 0 a person comes alone hires out a boat then i need to change the nterger to 1 to show that it is not available and then link that to the person which is hiring out the boat#
Thankyou
Your task is to implement, in Java, an object-oriented system for Octagon Boat Hire.
Your system should contain, at minimum, a Boat, PedalBoat, RowingBoat, and BoatHireCompany class and exploit the key object-oriented concepts encapsulation, inheritance and polymorphism.
You should initially develop and test each class using an appropriate text-based driver (main) class, which does not need to have user interaction (choice or input via Scanner). In order to be able to fulfil the above scenario, the classes you develop should be able to:
Boat, PedalBoat, RowingBoat classes:
o construct a rowing boat
o construct a pedal boat
o mark a boat as hired, storing the customer name and time
o return a boat's details as a String, including customer name and time of hire if it currently hired out
o calculate the amount due on a hired boat, given the time it was brought back
o make a boat that has been brought back available for rehire
BoatHireCompany class:
o construct a company which holds a list of boats
o add a new boat to the list of boats owned by the company
o display the details of all boats owned by the company
o display the details of all pedal boats
o display the details of all rowing boats
o find an available pedal boat
o find an available rowing boat
o display the details of all the boats currently hired out, including the name of the customer who has hired each boat, and the time it was hired
o find a boat given its id number
this is what i have done so far :
BoatHireCompany Class:
package assignment;
import java.util.Scanner;
public class BoatHireCompany {
private RowingBoat [] theRowingBoats;
private PedalBoat [] thePedalBoats;
private int numRowingBoats;
private int numPedalBoats;
private int maxRowingBoats;
private int maxPedalBoats;
private String BoatHireCompanyName;
private RowingBoat [] notime;
public BoatHireCompany (String name, int num)
{
BoatHireCompanyName = name;
maxRowingBoats = num;
numRowingBoats = 0;
maxPedalBoats = num;
numPedalBoats = 0;
theRowingBoats = new RowingBoat[maxRowingBoats];
thePedalBoats = new PedalBoat [maxPedalBoats];
notime = new RowingBoat[maxRowingBoats];
}
public boolean addRowingBoat( RowingBoat newRowingBoat )
{
// add another Boat to the BoatHireCompany if the BoatHireCompany is not full
if ( numRowingBoats == maxRowingBoats )
{
// the BoatHireCompany is full Boat cannot be added
return false;
}
else
{
int stat;
stat=RowingBoat.status;
if(stat==0)
{
theRowingBoats[numRowingBoats] = newRowingBoat;
numRowingBoats++;
}
else
{
notime[numRowingBoats] = newRowingBoat;
}
return true;
}
}
public boolean addPedalBoat( PedalBoat newPedalBoat )
{
// add another Boat to the BoatHireCompany if the BoatHireCompany is not full
if ( numPedalBoats == maxPedalBoats )
{
// the BoatHireCompany is full Boat cannot be added
return false;
}
else
{
// add Boat to the BoatHireCompany
thePedalBoats[numPedalBoats] = newPedalBoat;
numPedalBoats++;
return true;
}
}
public void outputBoatHireCompanyDetails()
{
System.out.println("Company: " + BoatHireCompanyName );
System.out.println("");
//output each Boat in turn
System.out.println("The Rowing Boats:");
for( int i=0; i < numRowingBoats; ++i)
{
System.out.println(theRowingBoats[i].toString());
}
for( int i=0; i < numRowingBoats; ++i)
{
System.out.println(notime[i].toString());
}
System.out.println("\n");
System.out.println("The Pedal Boats:");
for( int i=0; i < numPedalBoats; ++i)
{
System.out.println(thePedalBoats[i].toString());
}
Scanner kybd = new Scanner(System.in);
System.out.println("MENU");
System.out.println("1. Hire a boat");
System.out.println("2. Return a boat");
System.out.println("Please enter your choice:");
int choice = kybd.nextInt();
switch (choice) {
case 1:
}
}
}
Boat Class
package assignment;
public class Boat {
public int ID;
public Boat (int a)
{
ID = a;
}
public String toString() {
String s = "ID:" + ID ;
return s;
}
}
Rowing Boat Class:
package assignment;
public class RowingBoat extends Boat
{
public String Name;
public static int status;
public String stat;
public RowingBoat(int a, String Name, int theStatus)
{
super(a);
this.Name=Name;
status=theStatus;
ID=a;
if(theStatus==0)
{
stat="Unavailable";
}
else
{
stat="Available";
}
}
public int getstat() {
return status;
}
public String toString() {
String s = "ID:" + ID + " Avaliablitiy: " + stat + " Name:" + Name ;
return s;
}
}
Testing Class
package assignment;
public class Test {
// Driver class to test the BoatHireCompany class
public static void main(String[] args) {
BoatHireCompany BoatHire = new BoatHireCompany("BoatHire",15);
BoatHire.addRowingBoat(new RowingBoat (1,"Tedship",1));
BoatHire.addRowingBoat(new RowingBoat (2,"Daveship",0));
BoatHire.outputBoatHireCompanyDetails();
}
}
Well my problem is that i cannont change the boats from availabe to unavaile and vise-versa..... soo for example you have a boat which is availble which a integer is set to 0 a person comes alone hires out a boat then i need to change the nterger to 1 to show that it is not available and then link that to the person which is hiring out the boat#
Thankyou