I am learning Java and I am working in Java class Cycles, which mimics the London Boris bicycles. To create a interface that counts the number of time a bycicle station is used. The output I want is something like this;
- Please enter docking No. for Cycle 1 - 0
- Please enter docking No. for Cycle 2 - 1
- Please enter docking No. for Cycle 3 - 2
- Cycle with ID: 101 is in use
- Cycle with ID: 102 is at docking station 1
- Cycle with ID: 103 is at docking station 2
Number of cycles currently in the systems Cycle@355da254
What I want to achieve instead is
- Please enter docking No. for Cycle 1 0
- Please enter docking No. for Cycle 2 1
- Please enter docking No. for Cycle 3 2
- Cycle with ID: 101 is in use
- Cycle with ID: 102 is at docking station 1
- Cycle with ID: 103 is at docking station 2
Number of cycles currently in the systems 3
Here is the source code Cycle Class;
/**
* Created by devops05 on 28/02/16.
*/
public class Cycle {
private int ID;
private int dockingStationID;
private static int lastAssignedNumber = 100;
//private int count;
public Cycle()
{
lastAssignedNumber ++;
ID = lastAssignedNumber;
dockingStationID = 0;
}
public int getID()
{
return ID;
}
public boolean pickup()
{
if (dockingStationID == 0)
{
return false;
}
else
{
return true;
}
}
public boolean park(int dockSID)
{
if (dockingStationID == 0)
{
dockingStationID = dockSID;
return true;
}
else
{
return false;
}
}
public String getDockingStationNo()
{
if(dockingStationID == 0)
{
return " is in use ";
}
else
{
return " is at docking station "+ dockingStationID;
}
}
public int getNumberOfCycles()
{
int cycle1 = 1;
int cycle2 = 1;
int cycle3 = 1;
int cycleTotal = cycle1 + cycle2 + cycle3;
//for(int count = 0; count<3; count++)
return cycleTotal;
}
}
The second Java surce Class CycleTest;
/**
* Created by devops05 on 28/02/16.
*/
import java.util.Scanner;
public class CycleTest {
public static void main(String[] args)
{
Cycle cycle1 = new Cycle();
//int limit = 3;
//int count = 0;
Scanner in = new Scanner(System.in);
System.out.println("Please enter docking No. for Cycle 1");
int dockSID = in.nextInt();
cycle1.park(dockSID);
//for(int i=0; i < dockSID; i++)
{
//count++;
if (cycle1.park(dockSID))
{
System.out.println("Cycle with ID: " + cycle1.getID() + " is in use");
}
else
{
System.out.println("Cycle with ID: " + cycle1.getID() + cycle1.getDockingStationNo());
}
Cycle cycle2 = new Cycle();
System.out.println("Please enter docking No. for Cycle 2");
dockSID = in.nextInt();
cycle2.park(dockSID);
if (cycle2.park(dockSID))
{
System.out.println("Cycle with ID: " + cycle2.getID() + " is in use");
}
else
{
System.out.println("Cycle with ID: " + cycle2.getID() + cycle2.getDockingStationNo());
}
Cycle cycle3 = new Cycle();
System.out.println("Please enter docking No. for Cycle 3");
dockSID = in.nextInt();
cycle3.park(dockSID);
if (cycle3.park(dockSID))
{
System.out.println("Cycle with ID: " + cycle3.getID() + " is in use");
}
else
{
System.out.println("Cycle with ID: " + cycle3.getID() + cycle3.getDockingStationNo());
}
//Cycle cycleTotal = new Cycle();
//System.out.print("Number of cycles currently in the systems " + cycleTotal);
Cycle numberOfCycles = new Cycle();
System.out.print("Number of cycles currently in the systems " + numberOfCycles);
}
System.out.println();
//System.out.println("Number of cycles currently in the system is " + cycle.getNumberOfCycles());
//System.out.println("Number of cycles currently in the system is " + count);
}
}