Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Plain Text by ros ( 12 years ago )
package first;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Vehicle
{
static String name;
static int wils = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public Vehicle() throws IOException
{
}
void disp()
{
System.out.println("Vehicle is: " + name);
System.out.println("Number of wheels: " + wils);
}
public static void main (String [] args) throws IOException
{
while(true)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Choices: ");
System.out.println("------ ");
System.out.println("Van ");
System.out.println("Porsche ");
System.out.println("Audi Lans ");
System.out.println("Ferrari ");
System.out.println("Elf ");
System.out.println("Fortuner ");
System.out.println("Bajaj ");
System.out.println("Mio");
System.out.println("Rusi ");
System.out.println("Raider ");
System.out.println("Trailer ");
System.out.println("-------- ");
System.out.println("Enter vehicle: ");
name = reader.readLine();
System.out.println("Enter wheels: ");
wils = Integer.parseInt(reader.readLine());
if(name.equalsIgnoreCase("Van") || name.equalsIgnoreCase("Fortuner"))
{
if(wils == 4)
{
SUV suv = new SUV();
suv.disp();
}
else
{
System.out.println("Wheels entered is not enough or over the possible number of wheels in an SUV vehicle.");
}
}
else if(name.equalsIgnoreCase("Porsche") || name.equalsIgnoreCase("Audi Lans") || name.equalsIgnoreCase("Ferrari"))
{
if(wils == 4)
{
Cars car = new Cars();
car.disp();
}
else
{
System.out.println("Wheels entered is not enough or over the possible number of wheels in a car vehicle.");
}
}
else if(name.equalsIgnoreCase("Bajaj") || name.equalsIgnoreCase("Mio") || name.equalsIgnoreCase("Rusi") || name.equalsIgnoreCase("Raider"))
{
if(wils == 2)
{
Motorcycle motor = new Motorcycle();
motor.disp();
}
else
{
System.out.println("Wheels entered is not enough or over the possible number of wheels in a motorcycle vehicle.");
}
}
else if(name.equalsIgnoreCase("Elf") || name.equalsIgnoreCase("Trailer"))
{
if(wils >=6 && wils <= 18)
{
Truck trak = new Truck();
trak.disp();
}
else
{
System.out.println("Wheels entered is not enough or over the possible number of wheels in a truck vehicle.");
}
}
else
{
System.out.println("");
}
}
}
}
class Truck extends Vehicle
{
public Truck() throws IOException
{
}
void disp()
{
System.out.println("This is a truck!");
super.disp();
}
}
class Cars extends Vehicle
{
public Cars() throws IOException
{
}
void disp()
{
System.out.println("This is a car!");
super.disp();
}
}
class SUV extends Vehicle
{
public SUV() throws IOException
{
}
void disp()
{
System.out.println("This is an SUV!");
super.disp();
}
}
class Motorcycle extends Vehicle
{
public Motorcycle() throws IOException
{
}
void disp()
{
System.out.println("This is a motorcycle!");
super.disp();
}
}
Revise this Paste