Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; class Lab13 { public static void main(String[ ] args) { double side01 = 0.0; Scanner kBd = new Scanner(System.in); /* ******************************************************** * *

import java.util.Scanner;

class Lab13

{

public static void main(String[ ] args)

{

double side01 = 0.0;

Scanner kBd = new Scanner(System.in);

/* ********************************************************

*

* First create 2 "instances" of the object Squar

* and report on the initial contents (value) of those

* instances...

*

* ******************************************************** */

Squar square1 = new Squar( ); // create an instance of Squar

System.out.print("Enter side of the Square...");

side01 = kBd.nextDouble();

Squar square2 = new Squar(side01); // create another instance

System.out.println("The side of square1 is..." + square1.getSide( ));

System.out.println("The area of square1 is..." + square1.getArea( ));

System.out.println("The side of square2 is..." + square2.getSide( ));

System.out.println("The area of square2 is..." + square2.getArea( ));

/* ********************************************************

*

* Test your changes by entering the statements to retrieve

* and display the perimeters for squares 1 & 2

*

* ******************************************************** */

} // end of method main

} // end of class Lab13

public class Squar

{

private double side1 = 0.0; // contents 0 - 99.0

/* ********************************************************

*

* Constructors for Squar...

* A default constructor sets the side to 2.0 if the

* user does not initialize

*

* A one argument constructor for the users who enter

* a value for the side.

*

* ******************************************************** */

public Squar()

{

side1 = 2.0;

}

public Squar(double s)

{

side1 = s;

}

/* ********************************************************

*

* Accessor methods for Squar...

* getArea will return the value of the area of the

* square

*

* getSide will return the value of the side of the

* square

*

* getPerimeter will return the perimeter of the

* square. STUDENT MUST DEVELOP

*

* ******************************************************** */

public double getArea()

{

return side1 * side1;

}

public double getSide()

{

return side1;

}

Using the files you developed for Lab #13, create a Cube object and test its accessor and mutator methods (described below) with a client program.

Notes about processing:

Input - Using a menu system, provide the user with the following choices:

Processing - provide the requested response depending on the menu choice selected. When necessary, prompt for additional input (see below).

Output - if requested, provide the output requested. Should the user request the program stop (see below) terminate the menu and program.

For any test run you should create only a default cube or a cube with the side provided by the user.

A sample session might look like this: Cube Choices: 1. Create default cube 2. Create cube with side provided by user 3. Show volume of the cube 4. Show surface of cube 5. Show side 6. Change side 7. Quit Enter choice: 1 Cube created! Cube Choices: 1. Create default cube 2. Create cube with side provided by user 3. Show volume of the cube 4. Show surface of cube 5. Show side 6. Change side 7. Quit Enter choice: 3 Volume is 8 Cube Choices: 1. Create default cube 2. Create cube with side provided by user 3. Show volume of the cube 4. Show surface of cube 5. Show side 6. Change side 7. Quit Enter choice: 4 Surface is 12 Cube Choices: 1. Create default cube 2. Create cube with side provided by user 3. Show volume of the cube 4. Show surface of cube 5. Show side 6. Change side 7. Quit Enter choice: 5 Side is 2 Cube Choices: 1. Create default cube 2. Create cube with side provided by user 3. Show volume of the cube 4. Show surface of cube 5. Show side 6. Change side 7. Quit Enter choice: 4 Surface is 24 Cube Choices: 1. Create default cube 2. Create cube with side provided by user 3. Show volume of the cube 4. Show surface of cube 5. Show side 6. Change side 7. Quit Enter choice: 7 End of program

Notes about the Cube class:

Constructors - Create two (2) constructors. The first should be a "no argument" constructor that initializes the side(s) to a value of 2.0 (declared as a double). The second constructor will initialize the side of the cube to a value entered by the user.

Accessor Methods -

getSide - returns the value of the side of the cube

getVolume - returns the value of the volume of the cube (the volume is the side3).

getSurface - returns the surface of the cube (a cube has 6 sides, the surface will be the 6 * area of a side, or 6 * side2)

Output -

Display the values requested by the user via the menu. Let the sample program above guide you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago