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;

[Code] ....

View Replies


ADVERTISEMENT

Method Should Return A Double That Is Diameter Of Circle

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

Asking User To Put In Radius Of A Circle To Calculate Area / Diameter And Circumference

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

LightController And Circle Class - Creating A Constructor

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

Error - Creating Instance Of Inner Class

Mar 22, 2014

Java Code:

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?

View Replies View Related

Creating Instance Variables And Constructors For Map Class

Mar 27, 2014

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.

View Replies View Related

Creating Instance Methods And Driver Class

May 5, 2014

Okay, so I have to create a class with instance data and instance methods.

First, BankAccount class. It should contain the following information, stored in instance variables:

First name: The customer's first name.
Last name: The customer's last name
Balance: The amount of money the customer has in the account.

It should have the following methods:

BankAccount(String firstName, String lastName,
double openingBalance)

This constructor creates a new BankAccount

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) {

[Code] .....

View Replies View Related

Creating Instance Of A Class That Implements Runnable

Jul 31, 2014

I'm reading about threads In Head First Java and the way an Instance of a class that Implements Runnable Is created confuses me a little.

public class MyRunnable implements Runnable ......
Runnable ThreadJob = new MyRunnable();

I thought I had to use this syntax :

MyRunnable ThreadJob =new MyRunnable();

View Replies View Related

How To Make Green Selection Box To Move Around

Feb 16, 2014

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.

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferStrategy;
import java.util.Random;
 
public class Game extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
 
[Code] ....

I also tried an approach where you click with the move and it snaps to a tile grid but that didn't work either.

View Replies View Related

Green Bottles Activity - Printing Lyrics Of Song

Feb 23, 2014

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.

View Replies View Related

How To Rotate Object And Give Colour Inside

Mar 13, 2014

package id.ac.ub.ptiik.computergraphics;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.*;
public class CG04_3DTransformation extends CGApplication {
protected boolean wireframe = true;

[Code] .....

View Replies View Related

Changing Text Colour Within Quotation Marks?

May 7, 2013

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.

println("Try Again!!");

View Replies View Related

Java Program To Calculate Diameter?

May 6, 2014

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

View Replies View Related

Converting Parent Instance To Child Instance?

Mar 7, 2014

I've Parent and child(extends Parent) class To initialize the constructors, I'm injecting from google.juice#injector. Let me show the code,

Parent.class

public class Parent{
private Animal animal;
@inject
Parent(Animal animal){
this.animal = animal;

[code].....

When I do this, ClassCastException is happening. Why is it so? Is there any way to convert instance of parent to child instance.

View Replies View Related

Why To Get Result Brand Null / Colour Null

Feb 28, 2015

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?

View Replies View Related

How To Enter In Diameter In Main Class For Sphere Class

Apr 1, 2015

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.

View Replies View Related

How To Do Nested Circle Dynamically

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

2D Circle Texture Rotation?

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

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 View Related

Swing/AWT/SWT :: How To Do A Nested Circle Dynamically

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

Calculating Points On A Circle Using Radius

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

Counting Number Of Steps Throughout The Circle

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

Program To Calculate Area Of Circle

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

Make A Circle With Java Coding

Aug 12, 2014

i want to make a circle with java coding.... i tried but i am grtting some error...

View Replies View Related

Shade Portion Of Circle Based On Area Given?

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

Moving Circle - Null Pointer Exception

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







Copyrights 2005-15 www.BigResource.com, All rights reserved