English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i need a program written using java where you are given the radius of a sphere (double) as input and outputs the spheres diameter, circumference, surface area and volume

2007-12-20 06:24:50 · 4 answers · asked by Norman2073 1 in Computers & Internet Programming & Design

4 answers

This is rather simple. You'll have to do a lot of the actual programming yourself but I'll give you the basics. The equations that you will need to remember are:
Diameter = 2*Radius
Circumference = 4*Pi*r^2
Volume = 4/3*Pi*r^3
Java has Pi written in its collection (Math.PI I believe you can check the API to make sure).

You can then write the solution out to the console or where ever you need to.

2007-12-20 07:17:25 · answer #1 · answered by Anonymous · 0 0

Seems pretty straight forward to me. The only thing complicated about it is the MultiSphere class, which is really simple once you understand it. I really don't want to write it for you, because that defeats it's purpose, and therefore mine as well. I recommend you start with the first requirement, and so on. You need a Sphere class. public class Sphere { public Sphere() {} } done. You need it to have a diameter variable that has getter / setter public class Sphere { private int diameter; // constructor public Sphere(int initial_diameter) {this.diameter=initial_dimater;} public void diameter(int newValue) { this.diameter=newValue; } public int diameter() {return this.diameter} } done. Now you need two methods that perform simple math. You can construct these easily based on the information I have provided above. Create two public function named Volume and Surface, and return a value using "this.diameter". The toString method is something that ALL classes have, it is inherited by Object (all classes are objects). I won't go into detail, because you should have learned this the very first day in class. :P But if you make a toString function in your Sphere class that returns a String, as it should, then you have overridden the default that ALL classes inherit. Here is the prototype: public String ToString(); As for the MultiSphere, you need to first understand how to use the above class you have made... Sphere my_first_sphere = new Sphere(20); // diameter of 20 That makes an Instance of your Sphere class/object. So just make another class called MultiSphere, and in the constructor put that code in it. class MultiSphere { public MultiSphere() { // ... put code here ... } }

2016-05-25 04:49:13 · answer #2 · answered by ? 3 · 0 0

So what part do you need help with exactly? I doubt you'll find anyone here willing to do the whole project for you but many will answer specific questions if you run into a problem.

2007-12-20 06:28:18 · answer #3 · answered by Jim Maryland 7 · 0 0

He's right. That sound like work and no one will want to do it for free. There are some freelance programmers that work cheap. Post what you need on the website below and see what bids you get.

http://www.scriptlance.com/

2007-12-20 07:07:02 · answer #4 · answered by mawduce65 6 · 0 0

fedest.com, questions and answers