1)
/// Pizza.java ///
public class Pizza
{
public String description;
public double price;
public Pizza() {}
public Pizza(String desc,double pri)
{
this.description=desc;
this.price=pri;
}
public String toString()
{
return this. description+" Price:
$"+this.price;
}
}
/// DeliveryPizza.java ///
public class DeliveryPizza extends Pizza
{
public double fee;
public String address;
public DeliveryPizza(String desc,double pri,String
add)
{
super(desc, pri);
this.address=add;
if(super.price>15.0)
{
this.fee=3.0;
}
else
{
this.fee=5.0;
}
}
public String printDetails()
{
return
super.toString()+"\n\tDeliver to: "+this.address+". Fee is:
"+this.fee;
}
}
/// DemoPizzas.java ///
public class DemoPizzas
{
public static void main(String[] args)
{
Pizza pizza=new Pizza("susage and
onion pizza",14.99);
System.out.println(pizza.toString());
Pizza pizza1=new Pizza("green
pepper pizza",12.99);
System.out.println(pizza1.toString());
DeliveryPizza deliveryPizza=new
DeliveryPizza("cheese pizza",11.99,"22 Acron");
System.out.println(deliveryPizza.printDetails());
DeliveryPizza deliveryPizza1=new
DeliveryPizza("pepproni,susage and pineapple pizza",19.5,"47
Oak");
System.out.println(deliveryPizza1.printDetails());
}
}
Code Screenshots:-
Pizza.java
DeliveryPizza.java
DemoPizzas.java
Output:-
2)
/// Rock.java ///
public class Rock
{
int noOfsamples;
String typeOfrock;
double weightOfrock;
public Rock(int noOfsamples,double weightOfrock)
{
this.noOfsamples=noOfsamples;
this.typeOfrock="Unclassified";
this.weightOfrock=weightOfrock;
}
public void setnoOfsamples(int noOfsamples)
{
this.noOfsamples =
noOfsamples;
}
public int getnoOfsamples()
{
return this.noOfsamples;
}
public void setweightOfrock(double weightOfrock)
{
this.weightOfrock =
weightOfrock;
}
public double getweightOfrock()
{
return this.weightOfrock;
}
public String toString()
{
return "Samples # "+noOfsamples+"
weight "+weightOfrock+"\nDescription: "+typeOfrock+"\n";
}
}
/// MetamorphicRock.java ///
public class MetamorphicRock extends Rock
{
MetamorphicRock(int noOfsamples,double
weightOfrock)
{
super(noOfsamples,
weightOfrock);
}
public void settypeOfrock(String typeOfrock)
{
super.typeOfrock =
typeOfrock;
}
public String gettypeOfrock()
{
return super.typeOfrock;
}
}
///SedimentaryRock.java ///
public class SedimentaryRock extends Rock
{
public SedimentaryRock(int noOfsamples,double
weightOfrock)
{
super(noOfsamples,
weightOfrock);
}
public void settypeOfrock(String typeOfrock)
{
super.typeOfrock =
typeOfrock;
}
public String gettypeOfrock()
{
return super.typeOfrock;
}
}
/// IgneousRock.java ///
public class IgneousRock extends Rock
{
public IgneousRock(int noOfsamples,double
weightOfrock)
{
super(noOfsamples,
weightOfrock);
}
public void settypeOfrock(String typeOfrock)
{
super.typeOfrock = typeOfrock;
}
public String gettypeOfrock()
{
return super.typeOfrock;
}
}
/// DemoRocks.java ///
public class DemoRocks
{
public static void main(String[] args)
{
IgneousRock obj1=new
IgneousRock(123,4.5);
obj1.settypeOfrock("Igneous rocks are crystalline solids \nwhich
form directly from the cooling of magma");
System.out.println(obj1.toString());
SedimentaryRock obj2= new SedimentaryRock(234,14.9);
obj2.settypeOfrock("Sedimentary rocks are called
secondary,\nbecause they are often the result of the accumulation
\nof small pieces broken off of pre-existing rocks");
System.out.println(obj2.toString());
MetamorphicRock obj3=new
MetamorphicRock(345,7.0);
obj3.settypeOfrock("Any rock can become a metamorphic rock \nif the
rock is moved into an environment in which the \nminerals which
make up the rock become unstable and \nout of equilibrium with the
new environmental condition");
System.out.println(obj3.toString());
}
}
Output:-
Please UPVOTE thank you...!!!
1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and...
(To be written in Java code) Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display()...
Create a class named Book that contains data fields for the title and number of pages. Include get and set methods for these fields. Next, create a subclass named Textbook, which contains an additional field that holds a grade level for the Textbook and additional methods to get and set the grade level field. Write an application that demonstrates using objects of each class. Save the files as Book.java, Textbook.java, and DemoBook.java.
Create a class named BankAccount with data fields for a count number and a balance. Include a constructor that takes arguments for each field. The constructor sets the balance to 0 if it is below the required $200.00 minimum for an account. Include a method that displays the account details, including an explanation if the balance was reduced to 0. Write the class TestAccount in which you instantiate two BankAccount objects, prompt a user for values of the account number...
a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...
Create a class named Horse that contains data fields for the name, color, and birth year. Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field that holds the number of races in which the horse has competed and additional methods to get and set the new field. Write an application that demonstrates using objects of each class. Save the files as Horse.java, RaceHorse.java, and DemoHorses.java. Program 1 Submission Template Fields:...
Create a data class named Automobile that implements the Comparable interface. Give the class data fields for make, model, year, and price. Then add a constructor, all getters, a toString method that shows all attribute values, and implement Comparable by using the year as the criterion for comparing instances. Write a program named TestAutos that creates an ArrayList of five or six Automobiles. Use a for loop to display the elements in the ArrayList. Sort the Arraylist of autos by...
Create a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number of lines in the poem (of type int) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a...
Create a Mattress class should have fields for size (king, queen, twin), manufacturer, and price, and a constructor should set default values for each. Write set methods only for size and manufacturer. The set method for size adds $200 for king or $100 for queen. Add a toString() method that returns the data from all of the fields. A child class named AdjustableMattress extends Mattress and adds a field for adjustment type (air or mechanical), with air being the default....
Graded Exercise Create a class named Student. A Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the type int, assessedPrice of the type double. A constructor for this class should have three arguments for initializing these fields. Add accessors and mutators for all fields except a mutator for yearBuilt, and the method toString. Create a class StreetHouse which extends House and has additional fields: streetNumber of the type int, homeowner of the type String, and two neighbors: leftNeighbor and rightNeighbor, both...