Question

In: Computer Science

Follow the UML diagram and directions on the attached file to create a RectangularPrism class and...

Follow the UML diagram and directions on the attached file to create a RectangularPrism class and a RectangularPrismDemo class.

---------------------------------------------------------------------------------------------------------------------------------------

RectangularPrism

           - length: double

      - width: double

      - height: double

+ RectangularPrism()

+ RectangularPrism(l:double,w:double, h:double)

+ setLength(l:double):void

+ setWidth(w:double):void

+ setHeight(h:double):void

+getLength():double

+getWidth():double

+getHeight():double

+getVolume():double

+getSurfaceArea():double

+toString():String

---------------------------------------------------------------------------------------------------------------------

  1. Create a RectangularPrism class in its own file based on the UML
  2. Create a separate RectangularPrismDemo Class file to demonstrate your class by doing the following:
    1. Create two prisms, one with each constructor
    2. Test each of your set and get methods
    3. Print out the information for both of your Prisms, using printf()

Solutions

Expert Solution

thanks for the question, here are the two classes - RectangularPRism.java and RectangularPRismDemo.java with screenshot fo the output

======================================================================================

public class RectangularPrism {

    private double length;
    private double width;
    private double height;

    public RectangularPrism() {
        this.length = 0;
        this.width = 0;
        this.height = 0;
    }

    public RectangularPrism(double length, double width, double height) {
        this.length = length;
        this.width = width;
        this.height = height;
    }

    public void setLength(double length) {
        this.length = length;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public double getHeight() {
        return height;
    }

    public double getVolume() {
        return getHeight() * getLength() * getWidth();
    }

    public double getSurfaceArea() {

        return 2 * (getWidth() * getLength() + getWidth() * getHeight() + getLength() * getHeight());
    }

    @Override
    public String toString() {
        return "Length: " + getLength() + ", Width: " + getWidth() + ", Height: " + getHeight() +
                ", Volume: " + getVolume() + ", Surface Area: " + getSurfaceArea();
    }
}

===============================================================================================

public class RectangularPrismDemo {

    public static void main(String[] args) {

        RectangularPrism prismOne = new RectangularPrism();
        RectangularPrism prismTwo = new RectangularPrism(6,4,10);
        prismOne.setLength(10);
        prismOne.setHeight(12);
        prismOne.setWidth(8);

        System.out.printf("Prism Two Height: "+prismTwo.getHeight());
        System.out.printf("\nPrism Two Length: "+prismTwo.getLength());
        System.out.printf("\nPrism Two Width: "+prismTwo.getWidth());

        System.out.printf("\nPrism One: "+prismOne);
        System.out.printf("\nPrism Two: "+prismTwo);
    }
}

===============================================================================================


Related Solutions

create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called  Dog that contains instance data that represent the dog's name and age.   define the Dog constructor to accept and initialize instance data.   create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age).   Include a toString...
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called Dog that contains instance data that represent the dog's name and age. define the Dog constructor to accept and initialize instance data. create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age). Include a...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart or another diagramming tool. If you can’t find a diagramming tool, you can hand draw the diagram but make sure it is legible. Points to remember: • Include all classes on your diagram. There are nine of them. • Include all the properties and methods on your diagram. • Include the access modifiers on the diagram. + for public, - for private, ~ for...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student...
HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student class. - id : Integer - units : Integer - name : String + Student ( ) : + Student (id : Int, name : String, units : Int) : + ~Student( ) : + setID(id : Integer) : void + setName(name: String) : void + setUnits(units : Integer ) : void + displayRecord() : void 2.)   Include 3 files: -   Source.cpp -   Student.h...
Draw a UML diagram that describes a class that will be used to describe a product...
Draw a UML diagram that describes a class that will be used to describe a product for sale on Glamazon.com. The product has a name, a description, a price, ratings by many customers (1 to 5 stars), and a group of customer comments. New products have no ratings or comments by customers, but do have a name, description and price. The price can be changed and more customer ratings and comments can be added. A global average rating of all...
Complete the following class UML design class diagram by filling in all the sections based on...
Complete the following class UML design class diagram by filling in all the sections based on the information given below.         The class name is Boat, and it is a concrete entity class. All three attributes are private strings with initial null values. The attribute boat identifier has the property of “key.” The other attributes are the manufacturer of the boat and the model of the boat. Provide at least two methods for this class. Class Name: Attribute Names: Method...
What would the pseudocode look like for this UML class diagram? Class - oranges: String -...
What would the pseudocode look like for this UML class diagram? Class - oranges: String - bananas: String - grapes: String - apples: String + Class(String bananas, String grapes, String apples) + oranges( ): void + isValidGrapes( ): boolean + isValidApples( ): boolean + getOranges( ): String + getBananas( ): String + setBananas(String bananas): void + getGrapes( ): String + setGrapes(String grapes): void + getApples( ): String + setApples(String apples): void
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you need to define: 1a.) +setName(value:String):void 1b.) +setGPA(value:double):void 1c.) +setID(value: String):void 1d.) +getName(): String 1e.) +getLastName():String 2.) Working with constructors 2a.) +Student() : This is the default constuctor. For the Strings properties, initialize them to null. The order is String ID, String name, String lastName, and double GPA. 2b.) +Student(value:String) - This constructor receives just the ID. 2c.) +Student(value:String, var: String) - This constructor receives...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT