What's new

Java Need help with something for school

Z

Zuke

Curb Appeal.
Messages
3,324
Reaction score
507
question 3 is write a program that will calculate the the area of a square and a circle displayed to two decimal places (so use the double variable) how do i go about doing this ? I missed the week we were doing it in school so I'm clueless. Any help GREATLY appreciated
 
X

Xeren

♦♦♦ God Complex ♦♦♦
Messages
5,671
Reaction score
2,119
question 3 is write a program that will calculate the the area of a square and a circle displayed to two decimal places (so use the double variable) how do i go about doing this ? I missed the week we were doing it in school so I'm clueless. Any help GREATLY appreciated
Area of a Square: sqrt(lengthOfSide)
Area of a Circle: pi*sqrt(radius)
 
X

XKLUTCHIN OUTX

Enthusiast
Messages
523
Reaction score
74
Ok so the only reason I'm just giving it to you is because I'm just learning to write in java, but I ended up with this

Code:
import java.util.*;
import java.text.*;
public class XKLUTCHIN_OUTX {
 
	public static void main(String[] args) {
		double circleAnswer, squareAnswer, sideLength, radius;
		DecimalFormat df = new DecimalFormat("###,##0.00");
		Scanner Input = new Scanner(System.in);
		System.out.println("Enter side length: ");
		sideLength = Input.nextDouble();
		squareAnswer = sideLength * sideLength;
		System.out.println("Your area for the square is "+df.format(squareAnswer));
	   
	   
		System.out.println("Enter radius: ");
		radius = Input.nextDouble();
		circleAnswer = (3.14) * (radius * radius);
		System.out.println("Your area for the circle is "+df.format(circleAnswer));
	}
 
}
 
Z

Zuke

Curb Appeal.
Messages
3,324
Reaction score
507
Ok so the only reason I'm just giving it to you is because I'm just learning to write in java, but I ended up with this

Code:
import java.util.*;
import java.text.*;
public class XKLUTCHIN_OUTX {
 
	public static void main(String[] args) {
		double circleAnswer, squareAnswer, sideLength, radius;
		DecimalFormat df = new DecimalFormat("###,##0.00");
		Scanner Input = new Scanner(System.in);
		System.out.println("Enter side length: ");
		sideLength = Input.nextDouble();
		squareAnswer = sideLength * sideLength;
		System.out.println("Your area for the square is "+df.format(squareAnswer));
	 
	 
		System.out.println("Enter radius: ");
		radius = Input.nextDouble();
		circleAnswer = (3.14) * (radius * radius);
		System.out.println("Your area for the circle is "+df.format(circleAnswer));
	}
 
}
Area of a Square: sqrt(lengthOfSide)
Area of a Circle: pi*sqrt(radius)
Thanks guys !
 
L

LawlessBaron

A myth
Retired
Messages
5,558
Reaction score
1,774
question 3 is write a program that will calculate the the area of a square and a circle displayed to two decimal places (so use the double variable) how do i go about doing this ? I missed the week we were doing it in school so I'm clueless. Any help GREATLY appreciated
I might have deleted my old source code but i may have it around for a assessment that was similar to this
 
Z

Zuke

Curb Appeal.
Messages
3,324
Reaction score
507
I might have deleted my old source code but i may have it around for a assessment that was similar to this
I finished it all up yesterday, it wasn't actually about the code but your comments flow cart and notes.
 
L

LawlessBaron

A myth
Retired
Messages
5,558
Reaction score
1,774
ah i see
 
U

uid0

Programming Guru
Messages
436
Reaction score
74
Ok so the only reason I'm just giving it to you is because I'm just learning to write in java, but I ended up with this

Code:
import java.util.*;
import java.text.*;
public class XKLUTCHIN_OUTX {
 
	public static void main(String[] args) {
		double circleAnswer, squareAnswer, sideLength, radius;
		DecimalFormat df = new DecimalFormat("###,##0.00");
		Scanner Input = new Scanner(System.in);
		System.out.println("Enter side length: ");
		sideLength = Input.nextDouble();
		squareAnswer = sideLength * sideLength;
		System.out.println("Your area for the square is "+df.format(squareAnswer));
	 
	 
		System.out.println("Enter radius: ");
		radius = Input.nextDouble();
		circleAnswer = (3.14) * (radius * radius);
		System.out.println("Your area for the circle is "+df.format(circleAnswer));
	}
 
}
I wouldn't just hand it to him I'd lead him to the idea of it because you giving it to him is supporting his ignorance in the area.
 
Z

Zuke

Curb Appeal.
Messages
3,324
Reaction score
507
I wouldn't just hand it to him I'd lead him to the idea of it because you giving it to him is supporting his ignorance in the area.
i didn't need the code, Just the metod of how to do it !
 
Top Bottom