473,395 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Beginner -- Applet problems

I am a beginner programmer just starting to learn Java. Can someone tell me
what is wrong with this applet?
The output is:
Circumference is 47.1225
Area is 176.70938
Volume is 1767.0938

I don't think that is the correct value of the volume because it is exactly
10 times the area.

What went wrong and also, is there an easier way to square or cube a number?

Thanks,
Josh

//Calculates circumference, area of circle and volume of sphere based on a
radius

import java.awt.*;
import java.applet.Applet;

public class Calculations extends Applet {
public void paint(Graphics g) {
float pi = 3.1415f;
float radius = 7.5f;
float circumference = 2.0f * pi * radius;
float area = pi * (radius * radius);
float volume = 4.0f * pi * (radius * radius * radius) / 3;
g.drawString("Circumference is: " + circumference, 50, 50);
g.drawString("Area is: " + area, 50, 75);
g.drawString("Volume is: " + volume, 50, 100);
}
}

Jul 17 '05 #1
4 3650

"jcnews" <jc****@earthlink.net> wrote in message
news:FE*******************@newsread1.news.pas.eart hlink.net...
I am a beginner programmer just starting to learn Java. Can someone tell
me
what is wrong with this applet?
The output is:
Circumference is 47.1225
Area is 176.70938
Volume is 1767.0938

I don't think that is the correct value of the volume because it is
exactly
10 times the area.

What went wrong and also, is there an easier way to square or cube a
number?

Thanks,
Josh

//Calculates circumference, area of circle and volume of sphere based on a
radius

import java.awt.*;
import java.applet.Applet;

public class Calculations extends Applet {
public void paint(Graphics g) {
float pi = 3.1415f;
float radius = 7.5f;
float circumference = 2.0f * pi * radius;
float area = pi * (radius * radius);
float volume = 4.0f * pi * (radius * radius * radius) / 3;
g.drawString("Circumference is: " + circumference, 50, 50);
g.drawString("Area is: " + area, 50, 75);
g.drawString("Volume is: " + volume, 50, 100);
}
}


If you bothered to check yourself, you'd have found the area and volume
values are correct. 4/3 * 7.5 = 10

java.util.Math.pow(radius, 3);
Jul 17 '05 #2

"Murray" <pa***@SMAFFoffSPAMMER.optusnet.SPAMMAGE.com.au> wrote in message
news:v9******************@news-server.bigpond.net.au...

"jcnews" <jc****@earthlink.net> wrote in message
news:FE*******************@newsread1.news.pas.eart hlink.net...
I am a beginner programmer just starting to learn Java. Can someone tell
me
what is wrong with this applet?
The output is:
Circumference is 47.1225
Area is 176.70938
Volume is 1767.0938

I don't think that is the correct value of the volume because it is
exactly
10 times the area.

What went wrong and also, is there an easier way to square or cube a
number?

Thanks,
Josh


If you bothered to check yourself, you'd have found the area and volume
values are correct. 4/3 * 7.5 = 10

java.util.Math.pow(radius, 3);

Thanks for your help. The last time I was in a math class was 14 years ago
and I have not used any math since. I ran it through on a calculator and
had came up with a different number so I figured there was something wrong.
I guess it was right.

Thanks again.


Jul 17 '05 #3
"jcnews" <jc****@earthlink.net> wrote in
news:FE*******************@newsread1.news.pas.eart hlink.net:
I am a beginner programmer just starting to learn Java. Can someone
tell me what is wrong with this applet? <snip>
import java.awt.*;
import java.applet.Applet;

public class Calculations extends Applet {
public void paint(Graphics g) {
float pi = 3.1415f;

<snip>

In the future, you may want to consider using java.lang.math.PI

--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Jul 17 '05 #4
"Ian Shef" <in*****@avoiding.spam> wrote in message
news:Xn****************************@138.126.254.21 0...
"jcnews" <jc****@earthlink.net> wrote in
news:FE*******************@newsread1.news.pas.eart hlink.net:
I am a beginner programmer just starting to learn Java. Can someone
tell me what is wrong with this applet?

<snip>

import java.awt.*;
import java.applet.Applet;

public class Calculations extends Applet {
public void paint(Graphics g) {
float pi = 3.1415f;

<snip>

In the future, you may want to consider using java.lang.math.PI


Ok... I have no idea what java.lang.math.PI is yet or how to use it because
I am just a couple of days into Java, but I will look into it. Thanks.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Paul | last post by:
Hello, I've been reading up on security in Java Applets and whilst I understand the concept, I can't successfully get my applet to read a file on my local machine. I discovered from...
1
by: Tormod Omholt-Jensen | last post by:
Ï need to dynamically insert an applet into a document. In IE 6.0 my code works fine, but there seems to be problems in Opera 7. The page looks like there is allocated space for an applet. ...
2
by: Roberto Gallo | last post by:
Hi; I have two problems regarding Scripts and Applets. I need to construct a page that has some instances of the same Applet. These instances are responsible to get informations from the user...
1
by: Don | last post by:
Hi, I try to get a simple applet working, the class-file does load, but the image doesn't appear;( An error doesn't appear. The view is and stays 'grey' What I want: Automatic refresh of a...
2
by: Dag Sunde | last post by:
I have the following code fragment in one of my pages: if (typeof document.getElementById('myApplet').getTableAsSDV != 'undefined') { rowBuffer =...
8
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some...
5
by: Jacky Luk | last post by:
import java.awt.Graphics; public class printtest extends java.applet.Applet { public void init() { } public void paint (Graphics g) {
3
by: Jimbo | last post by:
I have a website & applet produced under Windows-XP. It works fine. I took it to a machine running Windows 98 & an earlier version of Java to test what happens when I open the web page using IE6 &...
2
by: Andrew Neiderer | last post by:
This is simple HTML, Java but I am really confused. I include the code since it is so small - ---------------------------------------------------------------------------- -- test.html -- ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.