Question
1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and onion) and price. include a constructor fhay requires arguments for borh fields ans a method to diplay the data. Create a subclass names DelicedPizza that inherits from Pizza bit adds a delivery fee and a delicery address. The description, price, and delicery address are required as arguments to the constructor. The delivery fee is $3 if the pizza ordered cost more that $15; otherwise it is $5. Write an application that instantiates at least two objects of each type, and display the calues. Save the files as Pizza.java, DeliveryPizza.java and DemoPizzas.java.

2. Create a class named Rock that acts as a superclass for rock samples collected and catalogued by a natural history musuem. The Rock class contains fields for a bumber of samples, a description of the type of rock, and the weight. The Rock constructor sets the deacription value to Unclassified. Include get methods for each field. Create three child classes named IgneousRock, Sedimentary Rock, and MetamorphicRock. The constructors for these classes require parameters for the sample number and weight. Search the Internet for a brief desceiption of each rock thoe and assign it to the description field. Create an application that instantiates an object of each tyoe and demonstrate that the methods work appropriatelt. Save the files as Rock.java, IgnsousRock.jave, SedumentaryRock.java, MetamorphicRock.java, and DemoRocks.java.
CIST 2371 Lab 9 DROP BOX ASSIGNMENT- Inheritance Instructions: 1. Create a class named Pizza with data fields for description
eetech.blackboard.com/bbcswebdav/pid-1979565-dt-content-rid-28068933_1/courses/CIST2371_202016_CR_60555/ 2. Create a class na
ahoocheetech.blackboard.com/bbcswebdav/pid-1979565-dt-content-rid-28068933_1/courses/CIST2371_202016_CR_60555/ 2/2 Sample out
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

public class Pizza Ç{ public String description; public double price; public Pizza () {} public Pizza (String desc, double pr

DeliveryPizza.java

{ { 1 public class DeliveryPizza extends Pizza 2 9 { public double fee; public String address; public DeliveryPizza (String d

DemoPizzas.java

public class Demo Pizzas 2 { public static void main(String[] args) { 8 9 10 11 12 13 14 Pizza pizza=new Pizza (susage and o

Output:-

C. C:\Windows\SYSTEM32\cmd.exe susage and onion pizza Price: $14.99 green pepper pizza Price: $12.99 cheese pizza Price: $11.

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:-

6:8. C:\Windows\SYSTEM32\cmd.exe Samples # 123 weight 4.5 Description: Igneous rocks are crystalline solids which form direct

Please UPVOTE thank you...!!!

Add a comment
Know the answer?
Add Answer to:
1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (To be written in Java code) Create a class named CollegeCourse that includes the following data...

    (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....

    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...

    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,...

    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....

    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...

    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...

    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...

    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...

    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...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT