i need a java program> help please i need a java program> help please Design a c
ID: 649038 • Letter: I
Question
i need a java program> help please
i need a java program> help please Design a class named Transportation with a data field indicating whether the mode of transportation is on land, air, or water using a String data type. Create a default constructor with null value and an overloaded constructor. Create accessor and mutator methods. Create a to String method to display mode of transportation. Design a class named Ship which inherits all the properties and behaviors of the Transportation class. The Ship class should have a String data field for ship?s name and an integer data field for the year the ship was built. Create a default constructor with null values and at least one overloaded constructor. Create accessor and mutator methods for each data field. Create an instance method to calculate the age of the ship using current year, 2015, as integer data type. Create a toString method to display mode of transportation, name of the ship, and year built. Design a class named CruiseShip which inherits all the properties and behaviors of the Ship class. This class should have a data field of integer for the number of passengers, integer for number of rooms, and double for price per passenger for five-day cruise. Create a default constructor with null values and at least one overloaded constructor. Create accessor and mutator methods for each data field. Create a method named halfFullIncome to calculate the amount of income if the ship were half full (number of passengers / two x price per passenger). Create a toString method to display mode of transportation, name of the ship, and year built, number of passengers, number of rooms, and price per passenger. Price and income should be formattedExplanation / Answer
class Transportation
{
String type;
Transportation()
{
}
Transportation(String t)
{
type=t;
}
void setype(String t)
{
type=t;
}
String gettype()
{
return type;
}
public String tostring()
{
return type;
}
}
class ship extends Transportation
{
String name;
int year;
int age;
ship()
{
}
ship(String n,int y)
{
name=n;
year=y;
}
void setname(String n)
{
name=n;
}
void setyear(int y)
{
year=y;}
int getyear()
{
return year;
}
String getname()
{
return name;
}
int calculate(int curyear)
{
age =curyear-year;
return year;
}
@Override
public String toString()
{
return "name of ship"+name+"year build"+year;
}
}
class crusieShip extends ship
{int nopas,noroom;
double price,income;
crusieShip()
{
}
crusieShip(int n,int y)
{
nopas=n;
noroom=y;
price=0.0;
}
void setpass(int n)
{
nopas=n;
}
void setnoroom(int y)
{
noroom=y;}
void setprice(double p)
{
price=p;
}
double getprice()
{
return price;
}
int getpass()
{
return nopas;
}
double halffullIncome()
{
income=nopas/2*price;
return income;
}
@Override
public String toString()
{
return " name of ship "+ name+ " year build "+ year+"no person "+nopas+"price "+price+" income "+income;
}
}
class calcu
{
public static void main(String args[])
{
crusieShip csh= new crusieShip();
double inco=csh.halffullIncome();
System.out.println(csh);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.