Page 1 of 1

I really need this code. Create an object-oriented program to output the area of a sphere. The user should be asked to e

Posted: Sun May 15, 2022 2:09 pm
by answerhappygod
I really need this code.
Create an object-oriented program to output the area of a
sphere. The user should be asked to enter the radius of the sphere.
The formula for calculating the area of the sphere is area=
4πr2 . The program should set the value for the radius.
The program should calculate the area of the sphere. The program
should allow the area of the sphere to be accessed. The program
should display the area of the sphere to the
screen.
Note: this assignment requires user input. The scanner class
will be required to complete the assignment. The value of pi can be
set to 3.14159 for this assignment. Java has a built-in version pi
if you would like to look it up and use it. Finally, R squared is r
* r.
I am using NotePad++ and Putty.
This the UML I also need with the code. Fix the errors and fill
in the actions the user is doing. The member data and
method have to be in that type of way when creating the code.
Modified UML: 2.0
Use Case Diagram
AreaOfASphereDriver.java
Driver
Insert Money
User
Make Selection
Get Soda
Class Diagram:
AreaOfACircle
Member Data:
- double area;
- double radius;
Methods:
+ setRadius(double
currRadius)
- calcArea();
+ double
getArea();
Class Modeling
Problem Statement:
Create an object-oriented program to
calculate the area of a circle. The area of a circle is determined
by squaring the radius of a circle and multiplying it times
π. The program should have the ability to set the
radius of the circle. The program should then calculate the area of
the circle. The program should finally allow the area of the circle
to be accessed. The program should display the results to the
screen.
Noun/Verb Extraction:
Nouns:
Verbs:
Normal Scenario:
Abnormal Scenario:
Below is the format the code is suppose to be in which is an
example.
*Example Format*
GallonToLiters.java
/*
________________________________________________________________

Class: GallonsToLiters
Author: User
Date: 1/30/2022
Purpose: Convert gallons to liters
----------------------------------------------------------------

Member Data:
- double liters;
- double gallons;
---------------------------------------------------------------

Methods:
+ setGallons(double currGallons)
- calcLiters();
+ double getLiters();
_______________________________________________________________

*/
public class GallonsToLiters
{
private double liters;
private double gallons;
/*
______________________________________________________
Method: setGallons(double currGallons)
Author: User
Date: 1/30/2022
Params: double currGallons
Returns: none
Purpose: set the number of gallons
______________________________________________________
*/
public void setGallons(double currGallons)
{
gallons = currGallons;
calcLiters();
}
/*
______________________________________________________
Method: calcLiters()
Author: User
Date: 1/30/2022
Params: none
Returns: none
Purpose: calc liters given gallons
______________________________________________________
*/
private void calcLiters()
{
liters = gallons * 4 * 0.946;
}
/*
______________________________________________________
Method: getLiters()
Author: User
Date: 1/30/2022
Params: none
Returns: double
Purpose: return the number of liters
______________________________________________________
*/
public double getLiters()
{
return liters;
}
}
GallonToLitersDriver.java
/*
******************************************************************

Program Name:
Author: User
Date: 1/30/2022
Assignment: Gallon to Liters demo
Purpose: Convert gallons to liters
Input: none
Output: gallons to liters
Related files: GallonsToLiters.java
Classes: GallonsToLiters
History: none
******************************************************************

*/
public class GallonsToLitersDriver
{
public static void main(String[] args)
{
double barrel55 = 30.0;
double litersInBarrel= 0.0;

GallonsToLiters barrelConversion = new GallonsToLiters();
barrelConversion.setGallons(barrel55);
litersInBarrel = barrelConversion.getLiters();
System.out.println("The number of liters in a 30 gallon barrel is
"
+ litersInBarrel);
}
}