Question

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. Include a get and set method for this field, adding $400 for air and $500 for mechanical. Implement a constructor that accepts all fields and calls the Mattress constructor. A toString() method should call the parent class toString() and add to it the adjustment type.

An application named MattressDemo should thoroughly demonstrate the functionality of both classes.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note : Plz check the following code and let me know if u need any changes...

______________________

// Mattress.java

public class Mattress {
   private String size;
   private String manufacturer;
   private double price;

   public Mattress() {
       this.size = "";
       this.manufacturer = "";
       this.price = 0.0;
   }
  
   public Mattress(String size, String manufacturer) {
       this.size = size;
       this.manufacturer = manufacturer;
   }

   public void setSize(String size)
   {
       if(size.equalsIgnoreCase("king"))
       {
           price=200;
       }
       else if(size.equalsIgnoreCase("queen"))
       {
           price=300;
       }
   }
  
   public void setPrice(double price) {
       this.price = price;
   }
   public void setManufacturer(String manufacturer)
   {
       this.manufacturer=manufacturer;
   }
   @Override
   public String toString() {
       return "Size=" + size + ", manufacturer=" + manufacturer
               + ", price=" + price ;
   }
  
}

_______________________

// AdjustableMattress.java

public class AdjustableMattress extends Mattress {
   private String adjustmentType;

   public AdjustableMattress() {
       this.adjustmentType = "air";
   }

   public AdjustableMattress(String size, String manufacturer,
           String adjustmentType) {
       super(size, manufacturer);
       if (adjustmentType.equalsIgnoreCase("air"))
           setPrice(400);
       else if (adjustmentType.equalsIgnoreCase("mechanical"))
           setPrice(500);
   }

   public String getAdjustmentType() {
       return adjustmentType;
   }

   public void setAdjustmentType(String adjustmentType) {
       this.adjustmentType = adjustmentType;
   }

   @Override
   public String toString() {
       return super.toString() + " AdjustmentType=" + adjustmentType;
   }

}
_________________________

Add a comment
Know the answer?
Add Answer to:
Create a Mattress class should have fields for size (king, queen, twin), manufacturer, and price, 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
  • 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...

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

  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • Design a class called Building. The class should keep the following information in the fields: String...

    Design a class called Building. The class should keep the following information in the fields: String address double property_value create several constructors including copy constructor , create accessor and mutator methods        Part 2 (50 points) Define interface Taxable which has one method getPropertyTax() Design a class called Private_Property that extends Building and implements Taxable It should have the following field : double value_of_improvements Create a constructor for this class to include newly added fields. The tax for the private property...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Create the header file named “Complex.h” that contains the following class: The class Complex represents a...

    Create the header file named “Complex.h” that contains the following class: The class Complex represents a complex number which is a number of the form a + bi where a and b are real numbers and i2 = −1. The class should contain: Private double field named real. Private double field named imaginary. Public default constructor that assigns 1 to real and 0 to imaginary. Public overloaded constructor that takes a double as a parameter named real. It assigns real...

  • Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain...

    Exercise #3: Create a class to represent a dog. Name the class “Dog”. It will contain three (3) class attributes, its bark, size, and cuteness. The bark will be the sound of the dog’s bark, as in “woof!”. Its size will be how tall the dog is from the ground, and that number should always be between 6 and 44 inches. The cuteness is a string describing how cute the dog is, based on this scale: “ugliest dog ever!” “pretty...

  • Write a class named Month. The class should have an int field named monthNumber that holds...

    Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • 1. Create a class named Pizza with data fields dor desceiption ( such as sasuage and...

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

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