metronome
02-23-2005, 10:13 AM
This is the super class vehicle
public class Vehicle
{
private String reg ;
private String type ;
private int maxLoad ;
public Vehicle(String registration)
{
reg = registration ;
}
public String getRegistration()
{
return reg;
}
public String getType()
{
return type;
}
public int getMaxLoad()
{
return maxLoad;
}
public void setType(String vehicleType)
{
if (vehicleType == "van") {maxLoad = 3500;}
if (vehicleType == "small van") {maxLoad = 500;}
if (vehicleType == "lorry") {setLoad(3000);}
type = vehicleType;
}
private void setLoad(int maximumLoad)
{
maxLoad = maximumLoad;
}
}
This is the lorry class that inherits from vehicle
public class Lorry extends Vehicle
{
private boolean artic ;
public Lorry(String registration, boolean articulated)
{
super(registration);
setType("lorry");
artic = articulated ;
}
public boolean getArticulated()
{
return artic;
}
}
I'm trying to get it to ask for a manual input when it detects the string "lorry" for vehicle type as lorries can have individual maximum capacities where as vans have known capacities. The problem is that I can get it to setup for the known types but since a lorry has a determined for individual loads, I need to know how to call a method and ask for an input
the method im looking at is the setLoad method which is called from the setType method. Currently it is happy to accpet 3000 as an input but i want it to ask for an input instead.
if i just have it as
if (vehicleType == "lorry") {setLoad();}
then it gives me the following error
setLoad(int) in Vehicle cannot be applied to ()
note: I don't even know if this is the right way of doing it, I thought that you'd have to call a method to ask for an input rather then being able to request in the if statement
anyway many thanks for anyone who is able to help out
public class Vehicle
{
private String reg ;
private String type ;
private int maxLoad ;
public Vehicle(String registration)
{
reg = registration ;
}
public String getRegistration()
{
return reg;
}
public String getType()
{
return type;
}
public int getMaxLoad()
{
return maxLoad;
}
public void setType(String vehicleType)
{
if (vehicleType == "van") {maxLoad = 3500;}
if (vehicleType == "small van") {maxLoad = 500;}
if (vehicleType == "lorry") {setLoad(3000);}
type = vehicleType;
}
private void setLoad(int maximumLoad)
{
maxLoad = maximumLoad;
}
}
This is the lorry class that inherits from vehicle
public class Lorry extends Vehicle
{
private boolean artic ;
public Lorry(String registration, boolean articulated)
{
super(registration);
setType("lorry");
artic = articulated ;
}
public boolean getArticulated()
{
return artic;
}
}
I'm trying to get it to ask for a manual input when it detects the string "lorry" for vehicle type as lorries can have individual maximum capacities where as vans have known capacities. The problem is that I can get it to setup for the known types but since a lorry has a determined for individual loads, I need to know how to call a method and ask for an input
the method im looking at is the setLoad method which is called from the setType method. Currently it is happy to accpet 3000 as an input but i want it to ask for an input instead.
if i just have it as
if (vehicleType == "lorry") {setLoad();}
then it gives me the following error
setLoad(int) in Vehicle cannot be applied to ()
note: I don't even know if this is the right way of doing it, I thought that you'd have to call a method to ask for an input rather then being able to request in the if statement
anyway many thanks for anyone who is able to help out
