Question: Write a Java Program. Pictures/Written format would be preferred. Use the appropriate class name for the class that you define. For example, a class that
Write a Java Program. Pictures/Written format would be preferred.
Use the appropriate class name for the class that you define. For example, a class that defines a House should be named House.java. For the written questions, provide your answers in the standard heading of your code at the top of the code file. For Question 1, you may draw the UML diagram using any tool (Word, Excel, Paint, etc.), or take a picture of your diagram and upload the file. For this exercise, you may want to SKIP the standard documentation listing the input and output variable names.
1. Draw a UML diagram for: A class named Q1 that contains 3 private int attributes and one public String attribute. The class includes SETTER and GETTER methods to set values of the private attributes and return the value for the private attributes. The class has a no-arg constructor to initialize values of the attributes.
2. Assuming you have access to a class named Q2 with a constructor that accepts to String parameters, show how you would create an object named objQ2 to construct an object using this constructor.
3. Assuming you have access to a class named Q3 with a constructor that does not accepts any parameters, show how you would create an object named objQ3 to construct an object using this constructor.
4. Write the definition of a class named Rectangle that contains: Two double attributes (data fields) named wid and len that specify the width and the length of a rectangle. A constructor to create a default rectangle (no-arg constructor) with values of 10 for width and length. A constructor to create a rectangle with specified values (through the parameters) for width and length. A method named setWidth to set the width of a rectangle. A method named setLength to set the length of a rectangle. A method named getArea to return the area of a rectangle (length * width) A method named getPerimeter to return the perimeter of a rectangle (2*length+2*width)
5. Write a test (driver) program to: Define an object using the no-arg constructor Define an object using the parametrized constructor to set the values of width and length to 5 and 15, respectively Display the width, length, area and perimeter of both objects. Make the output descriptive.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
