Creating Instance Of Circle With A Diameter Of 50 And Green Colour
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;
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;
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;
package Threads; // THIS PROGRAM WILL HAVE TWO THREADS i.e. "main" AND ANOTHER THREAD (SYSTEM WILL NAME IT "Thread-0" //THE STORY IS THAT WE WILL START Thread-0 FROM main AND LET IT EXECUTE. //main WILL WAIT AND LET IT EXECUTE FOR 5 MINUTES. //IF IT FINISHES ITS EXECUTION BEFORE 5 MINUTES, WELL AND GOOD; //BUT IF IT DOESN'T, WE WILL INTERRUPT IT. //AFTER INTERRUPTION, WE WILL DECIDE TO WAIT INDEFINITELY.
public class SimpleThreadsCopy { public static void threadMessage(String s){ String sThreadName= Thread.currentThread().getName(); System.out.format("%s: %s%n", sThreadName, s);
[Code] ....
The statement against which I have written many *'s gives the following error.
No enclosing instance of type SimpleThreadsCopy is accessible. Must qualify the allocation with an enclosing instance of type SimpleThreadsCopy (e.g. x.new A() where x is an instance of SimpleThreadsCopy).
Now that a similar "error-free" code is given here, what's wrong with this piece of code and what should I do about it?
Trying to understand the error statement, I replaced the erroneous statement with
Java Code : Thread t= new Thread(new SimpleThreadsCopy().new MessageLoop()); mh_sh_highlight_all('java');
And the error got fixed. From that I understand that the inner class is just kinda a nonstatic member of the outer class and it will be accessed by the objects of the outer class only.
But then why doesn't the code in the tutorial give an error?
I have to create an application that deals with maps.
I first have to create the instance variables for the class.
So very simply if my hashmap is going to consist of football clubs and players. Football clubs being a string value for the key and players being a set of strings for the values. How would I go about creating the instance variable in a class for this?
I can't seem to find anything that specifically deals with instance variables and constructors for maps.
public String firstName() Returns the customer's first name public String lastName() Returns the customer's last name public double balance() Returns the customer's account balance
Finally I need to create a driver to test my class. And create several accounts and verify that the first name, last name, and balance methods work properly. This is my code below.. I don't know if I did it right.
public class BankAccount { String firstName, lastName; double balance; public BankAccount(String firstName, String lastName, double balance) {
I'm making a simple game where there's a 10x10 grid and you can move around a selection box and you can move around. I've been trying to make the green selection box to move around but it won't move! I only have right movement in the code but it won't work so far. Here are the classes that have to do greatly with each other.
I need to write up a code that will print the lyrics of the Green Bottles song. So it will ask the user to input a number and it will use that number to print the lyrics and then count down from that number. For example, user enters the number 5, the program will run and display:
"5 green bottles, hanging on the wall
5 green bottles hanging on the wall
and if one green bottles should fall
there will be 4 green bottles hanging on the wall
4 green bottles, hanging on the wall...." and so on.
So far I have managed to write a code that will display the number that is entered but I cant figure out how to subtract the number by 1 to continue it. My code so far:
import java.util.Scanner; public class SomeJavaCode { public static void main(String[] args) { System.out.println("How many bottles to start with?");
[Code] ....
How to code it so that it substracts the number and repeats the rhyme till 0.
I'm new to Java, & am using Eclipse Helios. How do I change the text colour within the Quotation marks "Try Again" to red, or any other colour, so when I run it, it will display the new colour.
Assume the tanker is a cylinder of length 19.35 feet and volume 1320 gallons. What is the diameter in feet of the tanker truck? To solve this problem, write a Java program to calculate the diameter. For full credit, your Java application must follow these specifications.
1. The program must interactively input the capacity of the tanker in gallons and its length in feet. This should be done in the main method of your Tester class.
2. The input data should then be used to construct a TankerTruck object. You will need to write the TankerTruck class.
3. A TankerTruck method should be used by main to calculate the resulting diameter of the truck in feet.
4. Your program should use the standard Java constant for the math constant PI.
5. The output should be displayed using fixed-point notation, rounding to one decimal place of precision
public class Test { public static void main(String[] args) { Car c = new Car(); c.setInf("toyota", "red"); System.out.println("name: "+ c.brand + " colour: " + c.colour);
[code]....
Why do I get the result brand null, colour null? I know what null means but what am I missing here?
public class Sphere { public double diameter; public double volume; public double area; public double fourThirds = 4/3; public Sphere(double someDiameter){ someDiameter = diameter;
[Code] ....
I am trying to get this code so that I only enter the diameter once in the sphere object1 = new Sphere(4); but I can't get it to work right. I can get the diameter to work with the calculate volume and area methods but that's it.
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; }
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);
//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
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); }
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;
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;
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;
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
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)