Calculating Area And Circumference Of A Circle
Apr 21, 2014
Here is the code that I wrote out:
//program that calculates the circumference and area of a circle
import java.util.Scanner;
public class circle{
public static void main(String[] args){
Scanner input= new Scanner( System.in);
double r; //declares radius
[Code] .....
And here is what is displayed in the command prompt when I compile my code:
circle.java:17: error: cannot find symbol
r.input.nextdouble();//entered the radius
symbol: method nextdouble()
location: variable input of type Scanner
1 error
What am I doing wrong?
View Replies
ADVERTISEMENT
Mar 5, 2014
I am doing an assignment that is asking for the user to put in the radius of a circle and the program figures out the area, diameter and circumference. It is using 2 different java programs to accomplish this. One with the info on how to get area, diameter and circumference and one is the demo that runs the program. I keep getting errors on my demo.
// Circle Class
public class Circle {
private double rad;
private double Pie;
private double area;
private double diameter;
[Code] .....
View Replies
View Related
Jul 15, 2014
Here is the program I wrote for calculating the circumference of a circle.
//circumference.java
//program that calculates the area and circumference of a circle
import java.util.Scanner; //program uses class scanner
public class circumference{
//main method begins execution of Java application
public static void main(String args[]){
[Code] .....
Even though my code compiles and runs without any errors, the program doesn't calculate the circumference.
View Replies
View Related
Oct 24, 2014
I have to print points on a circle in increments of -0.1, but when I use a number larger than 1.3, the list stops at 0.1 larger than negRadius, and I don't know why. (Assume the center is (0,0))
public class PointsOnACircleV1
{
public static void main(String[] args)
{
double radius = 1;
[code]...
View Replies
View Related
Mar 11, 2015
I'm starting with my version of very basic program: calculating area of circle. And of course it doesn't get well. My question: what is wrong in this code?
public class circleAre{
double radious;
void putData(double radi){
radi = radious;
[Code] .....
View Replies
View Related
Sep 23, 2014
I am able to draw this image using filloaval() but afterwards when i am calculating some area i have to shade that in the figure in some different color
R is fixed to 100 and d lies between 0 to R
View Replies
View Related
Mar 3, 2015
package areatest;
import javax.swing.JOptionPane;
public class AreaTest {
public static double areaTriangle (double length, double width){ //How to calculate the area of a triangle
return .5f * length * width;
[Code] .....
When I try to get the area of a rectangle it gives me 9 no matter what input I give it. When I try to get the area of a triangle it gives me .5 no matter what input I give it. Same with the circle but it always gives me 12.56370...
View Replies
View Related
Sep 9, 2014
I am supposed to be doing a class assignment that calculates the area of a triangle and outputs with JOptionPane. I was able to fix some errors, but it's uncovering more errors.Here is my code:
import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
public class Area {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle
StringTokenizer st;
[code]....
View Replies
View Related
Mar 22, 2015
I've been given a school assignment that reads, "Rewrite the main class Geometry so it takes in the dimensions for the triangle and ellipse as user inputs and create a Triangle and an Ellipse class. Use the appropriate variable types, constants, variable names and computational formulas.
Triangle class will have a computePerimeter and a computeArea methods Ellipse class will have a computeArea method Create Report class
• Create a method createReport that takes the values returned from Triangle and Ellipse and combines them in the following message and displays it. Format the values so that they have 2 decimals.
“The triangle has a perimeter of [perimeter] with an area of [area] while the ellipse has an area of [area]”
• Create a method switchReport that takes the original string from createReport and changes the message to display using the available methods in the String class
“The ellipse has an area of [area] while the triangle has an area of [area] with a perimeter of [perimeter]”"
I've run into a problem when creating the createReport method. Everytime i run it i get incorrect values for the perimeter and area (namely i get zero every time).
my code is as follows:
public class Triangle
{
public double base;
public double height;
public double hypotenuse;
private double tArea;
private double perimeter;
public Triangle()
{
base = 0;
height = 0;
hypotenuse = 0;
[code]....
For the triangle class and
public class Report {
Triangle tri2 = new Triangle();
Ellipse eli2 = new Ellipse();
public Report() {
}
public void createReport() {
System.out.println("The triangle has a perimeter of "+tri2.computePerimeter() +" with an area of " +tri2.computeTArea() +" while the ellipse has an area of " +eli2.computeEArea() );
}
for the report class.the Geometry class allows you to input values and if i skip the report and simply print the perimeter and area they are correct. However with the report class it simply gives me zeros.
View Replies
View Related
Mar 19, 2014
I was suppose to create a simple Java program for calculating the area of a rectangle (height * width). Then check the user’s input, and make sure that they enter in a positive integer, and letting them try again if they enter in a negative number. (I'm not sure how to get them to try again.
I am suppose to use an "if" statements and indeterminate loops to achieve the solution. The program will have the following requirements:
1. Ask the user to enter in both a height and width (as an integer)
2. If the user enters in a negative number, display an error
3. If the user enters in a negative number, give them another chance to enter in the correct value
4. Calculate the area and display to the screen once two positive integers have been entered.
import java.util.Scanner;
public class RectangleAreaCalc
{
public static void main(String[] args)
{
int length;
int width;
int area;
[Code] ....
View Replies
View Related
Feb 8, 2015
i'm trying to do a nested circle dynamically. i don't know whats wrong with my program ...
private Ellipse2D.Float doubleElip(int x1, int y1, int x2, int y2){
int x = Math.min(x1, x2);
int y = Math.min(y1, y2);
int width = Math.abs(x1 - x2);
int height = Math.abs(y1 - y2);
for( int i=0; i < 1; i++){
Ellipse2D.Float elip = new Ellipse2D.Float(x , y,
width/i, height/i);
}
return elip;
}
View Replies
View Related
Jan 11, 2015
So I have this randomly generated set of tiles that is wrapped in a circle and I'm not really sure how to scroll it around the circle. Basically it's a side-view planet that is in 2D and needs to be wrapped and moving at a controllable rate to give the illusion of planet rotation. What to do to the x and y to make it scroll around. I want every tile except the water tiles to move from left to right and then wrap around the circle. Here's what a planet looks like: [URL] ....
Java Code:
for (int x = 0; x < planet1.length; x++)
{
for (int y = 0; y < planet1[0].length; y++)
{
if (planet1[x][y] == 1 || planet1[x][y] == 2)
{
g.drawImage(water, x * 32, y * 32);
[Code] ....
View Replies
View Related
Mar 5, 2015
i want to draw a circle inside a circle in java. so far i'm using this piece of code
private Ellipse2D.Float drawEllipse(int x1, int y1, int x2, int y2) {
int x = Math.min(x1, x2);
int y = Math.min(y1, y2);
int width = Math.abs(x1 - x2);
int height = Math.abs(y1 - y2);
return new Ellipse2D.Float(x, y, width, height);
}
View Replies
View Related
Jan 27, 2015
The method public static int steps(int posts, int stride) calculates how many strides can be taken to get back to posts. Let's say if the method is (12, 4), it takes only three steps. Now let's say the method has parameters (12,5), so it should be (5, 10, 3, 8, 1, 6, 11, 4, 9, 2, 7, 12). My method works for such examplse as (12, 4) or (12,3) or (6,2)... but how can I figure out (12,5)?
Java Code:
public static int steps(int posts, int stride) {
int countSteps = 0;
int result = 0;
do {
result += stride;
[Code] ....
View Replies
View Related
Aug 12, 2014
i want to make a circle with java coding.... i tried but i am grtting some error...
View Replies
View Related
Apr 9, 2014
I am try to move circle.Below is my code...
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.JPanel;
[Code] .....
And I have error
run:
Exception in thread "main" java.lang.NullPointerException
at swingdesing.Game.buffer(Game.java:32)
at swingdesing.Game.moveBall(Game.java:27)
at swingdesing.Game.main(Game.java:51)
BUILD SUCCESSFUL (total time: 9 seconds)
how to overcome this?
View Replies
View Related
Mar 19, 2014
Prompt: Write a class encapsulating the concept of a circle, assuming a circle has the following attributes: a Point representing the center of the circle, and the radius of the circle, and integer.
Include a constructor, the accessors and mutators, and methods toString and equals.
Also include methods returning the perimeter ( 2 x 𝜋 x 𝑟 ) and area ( 𝜋 x 𝑟^2) of the circle.
Write a client (application) class to test all the methods in your class. I started out trying to thing how to do this and I mapped out a certain idea but do not know how to incorporate the point represent the center of the circle. I am not sure how to proceed further..
import java.awt.*;
public class Circle {
public static void main(String[] args) {
final double PI = 3.14;
int x,y, radius = 4;
double area;
double perimeter;
[Code] ...
View Replies
View Related
Jan 6, 2015
I have two classes LightController & Circle. I need to use the LightController class to do the following:
Creates an instance of Circle with a diameter of 50 and a colour of OUColour.GREEN and assigns this new circle to the instance variable light.
Sets the xPos of light to 122.
Sets the yPos of light to 162.
I am struggling to write the correct line of code to set the colour to green and set diameter to 50.
Code for the two classes below.
001
import ou.*;
002
import java.util.*;
003
/**
004
* Class LightController
005
* This class uses the Circle class, and the Shapes window
[Code] ......
View Replies
View Related
Jul 9, 2014
What's that diameter? Create a new method for the circle class called diameter. Add this method to the circle class described on page 15-1. It should return a double that is the diameter of the circle. No parameters are passed to this method.
In a tester class, test the performance of your new diameter method as follows:
(Your project should have two classes, Tester and Circle.)
here is what i have so far:
public class Circle
{
public Circle (double r)
{
radius = r;
}
public double area()
{
double a = Math.PI * radius * radius;
[Code] ....
View Replies
View Related
Mar 12, 2015
I want to draw a line inside a circle, i what to have a horizontal line. Here is what i have done so far.
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
[Code] ....
View Replies
View Related
Sep 19, 2014
So Ive got to make a turtle on an image draw a semicircle that starts at the top of a circle and goes down and to the left, changing colors halfway through. I've got everything down, I can draw the turtles and make them do straight lines. My problem is more math related. I need to use the equation of a circle, give it points, and figure out how to write that code in java.
We use the equation for a circle: (x - a)^2 + (y - b)^2 = r^2
amanda.setName("amanda");
amanda.setShellColor(Color.BLUE);
amanda.setBodyColor(Color.RED);
amanda.setPenColor(Color.YELLOW);
amanda.setPenWidth(3);
amanda.forward();
amanda.turn(-90);
amanda.setPenColor(Color.BLUE);
amanda.forward(???);
the question marks are where I need to draw a line on an arc, like in the picture.
View Replies
View Related
Apr 28, 2015
So in trying to create a circle class, and use the dimensions of that circle (radius, area, etc.) to prove it will equal pie and print (3.141592653589793). This is my code so far it and am getting an error in the last two classes. I know it has to do with Circle(Radius); in the 2nd class but whenever i call upon it, it is assigned to itself. And in the last class im not too sure how to put the B= new b(1,1).
[public class Circle {
private double radius;
public Circle() {
radius = 0;
}
public Circle(double radius) {
this.radius = radius;
[Code] .....
View Replies
View Related
Sep 15, 2014
I am getting an error with my code. How to fix it.
import java.util.Scanner;
import java.util.*;
/*
* FileName: Circle.java
*/
public class Circle {
private double PI = 3.14159;
private double radius;
public Circle()
{
radius = 0.0;
[Code] ....
This is the error i am receiving:
Circle.java:78: error: method getRadius in class Circle cannot be applied to given types;
System.out.println("A circle with a radius of " + circle.getRadius() + " will have an area of " + circle.getArea() + " , a diameter of " + circle.getDiameter() + " and a circumference of " + circle.getCircumference());
^
required: double
found: no arguments
reason: actual and formal argument lists differ in length
1 error
View Replies
View Related
Feb 19, 2014
This code is shown to eliminate "smearing":
public void paintComponent (Graphics g) {
g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(), this.getHeight());
g.setColor(Color.green);
g.fillOval(x, y, 40, 40);
}
I had done all the previous code (in my own style) and found that the background rectangle was either being redrawn on its own, or there was something else removing the old circles from the screen. I then typed in the code from the previous page exactly as it was, to see if I had some change in syntax that would cause this, and it did the same thing.
Here's my code:
import javax.swing.*;
import java.awt.*;
public class SimpleAnimation {
int x, y;
private static final int HEIGHT = 600;
private static final int WIDTH = 600;
[Code] .....
Is this because I'm using JRE7? I can't find any documentation that indicates the repaint() method has changed since Java 5.
View Replies
View Related
Sep 7, 2014
I'm new to programming and I have an assignment due in java class. Here is the error code:
TestCircle.java:10: error: method setradius in class Circle cannot be applied to given types;
circle1 = inputCircle.setradius();
^
required: double
found: no arguments
reason: actual and formal argument lists differ in length
And here is my code:
import java.util.Scanner;
public class TestCircle
{
public static void main(String[] args)
{
double circle1;
double circle2;
double circle3;
Circle inputCircle = new Circle();
[Code] ......
View Replies
View Related
Jan 6, 2015
I have two classes LightController & Circle. I need to use the LightController class to do the following:
Creates an instance of Circle with a diameter of 50 and a colour of OUColour.GREEN and assigns this new circle to the instance variable light.
Sets the xPos of light to 122.
Sets the yPos of light to 162.
I am struggling to write the correct line of code to set the colour to green and set diameter to 50.
Code for the two classes below.
import ou.*;
import java.util.*;
/**
* Class LightController
* This class uses the Circle class, and the Shapes window to simulate a disco light, that grows and shrinks and changes colour.
*/
public class LightController
{
/* instance variables */
private Circle light; // simulates a circular disco light in the Shapes window
private Random randomNumberGenerator;
[Code] ....
View Replies
View Related