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...
draw a uml diagram for a class
draw a uml diagram for a class
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...
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
A UML class diagram can be used to model UML by considering each graphical component of...
A UML class diagram can be used to model UML by considering each graphical component of the notation to be a class. For example, a class diagram contains a collection of classes. Your problem is to construct and draw one class diagram with the below UML elements. That is, there will be a class for each of the elements listed. You must also provide ALL of the relationships between each of these classes. The elements to model in the class...
Create a Java class named ReadWriteCSV that reads the attached cis425_io.txt file that you will save...
Create a Java class named ReadWriteCSV that reads the attached cis425_io.txt file that you will save in your workspace as src/cis425_io.txt and displays the following table: -------------------------- | No | Month Name | Days | -------------------------- | 1 | January | 31 | | 2 | February | 28 | | 3 | March | 31 | | 4 | April | 30 | | 5 | May | 31 | | 6 | June | 30 |. | 7...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT