Question: . Material -name : String -weight: double + Material () + Material (n: String, w : double) + setName(n : String): void + setWeight(w :
.
| Material |
| -name : String -weight: double |
| + Material () + Material (n: String, w : double) + setName(n : String): void + setWeight(w : double): void + getName(): String + getWeight(): double |
Write a class declaration for Material class and add the two variables to the class declaration
- name: is a String variable that holds the name of the material.
- weight: is a double variable that holds the weight of the material.
2- The class should have the following constructors:
- A constructor that accepts the following value as argument and assigns it to the appropriate fields: material name and weight.
- A no-arg constructor that assigns empty strings ("") to the name, and 0.0 to the weight field.
3- Write mutator methods that store values in these fields and accessor methods that return the values in these fields as in above UML diagram.
4- Once you have written the class, write a separate program that creates two Material objects to hold the following data:
| name | weight |
| Steel | 45.8 |
| Wood |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
