Hello guys,
Sorry for the title, it should be Renting bicycle program XD Can't edit XD
I've got a task from my school. I've to create a new computer system for Oslo City bikes. The Oslo City Cycle bike racks at various locations around Oslo where people with valid bike card can rent a bike at a time for up to 3 hours. This system consists of several modules and my task is to program the module that registers the position and the submission of a bike. To do this, I need to create a several classes.
I've mostly done with this program, but it won't work as I want it to so it must be something with my code. Some logical errors I guess. I won't paste the whole code here since it's alot but I will try to explain it and I can send PMs if needed.
There are six classes in this program, Bicycle, Person, BikeRack, PersonRegister, RentLocation and BicycleCity.
The class Bicycle is representanting a bicycle in this program. Each bicycle has an unique ID.
The class Person is representanting cyclists in this program. Each with an unique ID.
The class PersonRegister is a register with all the cyclists stored.
The class BikeRack is where the bicycles are placed when not rented out.
The class RentLocation contains the display (JFrame, buttons etc).
The class BicycleCity is just a simple on which contains the main method and creates various places for the bicycle racks.
The display contains a JLabel for Person ID, then JTextField where I enter the person ID and a button for rent.
Next line: JLabel for Bicycle ID, JTextField for enter the Bicycle ID and a button for delivering the bicycle.
Next line: JTextArea which gives you all information (like which cycle to take, if the rack is full or not etc).
My problem:
I can borrow a bike, but when I'm trying to deliver it I always get a message which says "Unknown bicycle ID". Here is the method from RentLocation:
private BikeRack rack = new bikeRack(amount); //amout is declared in parameter in the constructor. private access as computer field or what its called..
private PersonRegister person; //in constructor person = p;
public void deliver()
{
int bikeID = Integer.parseInt(bikeIdField.getText()); //bikeIdField is where I enter the bike ID when I want to deliver.
if(person.findBikeUser(bikeID) != null)
{
display.setText(rack.deliver(person.findBikeUser(bikeID)));
}
else
display.setText("Unknown bikeId");
}
I don't know if it's this method or not, but when I run my program, it always jumps to the else setting.. Giving me "Uknown BikeID". I don't know why.. I can show the method for findBikeUser and rack.deliver from two different classes (findBikeUser from PersonRegister and rack.deliver from BikeRack:
public Person findBikeUser(int bikeId)
{
for(int i = 0; i < person.length; i++) //created an array
{
if(person[i].getBike() != null && person[i].getBike().getId() == bikeId) //getBike() is a simple get-method from class Person. getBike().getId() just returns the ID number for the bike from class Bicycle
return person[i];
}
return null;
}
public String deliver(Person s)
{
String output = "";
for(int i = 0; i < rack.length; i++) //created an array for the rack earlier
{
if(rack[i] == null) //if rack is empty or almost full
{
s.deliver(); //this method is from class Person which creates an end date for deliver time. if you've delivered to late, you will get an comment which tells the user that you've delivered the bike to late (can only borrow bike for 3 hours max). else I set Private Bicycle bike = null; and private date startTime = null; not like private but bike = null; and startTime = null; (declared earlier)
output += "Put the bicycle on place " + (i+1);
return output;
}
}
output += "Full here, but your bicycle somewhere else!";
return output;
}
And just to repeat my probem: I can't deliver the bikes. It always jumps to the else setting in deliver method in class RentLocation.
I know it's a lot more, but I think it will be easier to PM all files if needed. Maybe it's some logical errors, I don't know. Do you see something?