I am working on a random circles program. Basically it is supposed to draw as many random circles as you tell it to, 1-20. I have it drawing circles but it only draws twenty no matter what I type in. Here is my code for the component:
You should write a class that represents a circle object and includes the following:
1. Private class variables that store the radius and centre coordinates of the object. 2. Constructors to create circle objects with nothing supplied, with just a radius value supplied and with a radius and centre coordinates supplied. 3. Public instance methods that allow the radius and centre coordinates to be set and retrieved (often known as set/get methods). 4. Public instance methods that return the circumference and area of the circle. 5. A public class method that tests if two circle objects overlap or not
Here is my code:
import java.lang.Math; public class Circle { private double xCentre, yCentre, Radius; // constructors public Circle() { xCentre = 0.0; yCentre = 0.0; Radius = 1.0;
[Code] ....
The second program just has to demonstrate each aspect addressed in the brief I pasted at the top.s of what else I can do.
This is as far as I got during the 3 hour lab session I had and both compiled fine but when running just displayed all the text eg. "Circumference of first circle is ", but didn't display any numeric values. I don't have the facilities to actually run the program unless I'm in the computer lab, I have a short opportunity to go in tomorrow but that will be the last so I'm doubtful that I'll get it fully working in time.
The problem is that when this code runs it doesn't display any numerical values, ie nothing is being passed between the two programs.
public class Circle extends GeometricObject implements Comparable<Circle> { private int radius; public Circle(int newRadius) { radius=newRadius;
[Code] ....
When I run the driver class it tells me that all tests have passed(as it should be) except for Test 0. I have tried to play around with the code, but I cant figure it out and it is driving me crazy because in my head my code makes sense.
I have created two classes. The FrameViewer is my driver class, and Circle is my constructor.
The first problem is, the program seems to be creating both circles, but it only displays displaying the last added circle (in this case, circle2).
The second problem is, I want to pass the color I wish to use to the constructor, but I'm having problems figuring out the proper method to do so. In the constructor, I have assigned Color.BLUE as a default. On circle two, I want to override this color choice and assign Color.Orange. I am not having any luck setting this to work either.
import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.Color; public class FrameViewer { public static void main(String[] args) { JFrame frame = new JFrame();
Write a program that draws 20 circles, with the radius and location of each circle determined at random...... Two circles overlap if the distance between their center points is less than the sum of their radii...
There may be many problems with the code in general but what I'm struggling with is the distance and the totalradius portion. Visually, its inaccurate.
import java.awt.*; import javax.swing.*; public class CircleTest extends JPanel { Circle []circles; Circle []circleCenter; Circle []all; private int distance, totalradius, dx, dy; private int radius,x,y;
The program is a Random String Generator; it takes user input (type of string, and length), and then generates a string with their requested method. Its extremly simplistic, but had some interesting coding challenges considering I only just did 'Hello World' a few days back xP I actually already have quite a few additions and modifications I want to make to it, but wanted to get a bit of feedback on it otherwise.
The Main Class, RandomStringGenerator.java:URL... InputHandler.java:URL.... RandomGenerator.java: URL....
Write I program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number.
public class NumberGuess { public static void main(String[] args) { // Create a Random object. final static Random rand = new Random(); // max number is the upward bound number final int MAXNUMBER = 10; /** * Method should return a random number within the upward bound MAX_NUMBER.
[code]....
I get compiler error message
NumberGuess.java:25: error: ';' expected int getRandomNumber (); ^ NumberGuess.java:63: error: reached end of file while parsing System.out.println("You got it right in " + numberOfGuesses + " guesses."); ^
I've run into some problems with my Quiz-game program. What I basicly want it to do is generate a random number that is tied to the other windows I have for the program (I want a new random question to be generated once I have guessed on the first one). I've read about a few different ways to approach this but everything I get is a pure number generator.
I imported
import java.util.Random;
into my program but I don't know where to go from there.
Instruction: You work for a telemarketing company and you are required to write a JAVA program that will generate a random phone number. (talk about a real-world application)
-The phone number should consist of 10 digits -The first 3 are the area code and should not begin with 0, 8 or 9 -The second 3 digits should not be greater than 742 and not less than 100. -The last 4 digits can be any digits -Print the number using the following format: "(xxx)-xxx-xxxx", this way it will look like a real phone number (use decimal formatting)
by this : Generating Random Numbers Using arithmetic operations
<Declaration of the array for storing random integers and other necessary variables and / or constants. >
private int numbers; private int max; private int[] integer; private Random generator; public integer ( int n, int m )
[code]....
I need to create a program that draws random numbers and stores them in an array. How many numbers to be drawn is dependent on the array length, which is a parameter in the class constructor. (The entire array to be filled!) The program shall, however, just save the figures are not drawn already. (Ie, the array must contain only one instance of each numeral.) All figures drawn should be in the range of 100 to 1000, both limits included. These limits are defined as named constants. When all the numbers are generated and stored in the array, the program should find the largest, smallest and average value of the numbers in the array. In addition, it should find the value closest gjennomnstittetsverdien.
I have been assigned to write a program that has a user input random numbers then the program is to sort them in different ways. I have the coding for the different sorts but, I have an error saying that I am missing a return statement in the "Bubble" method. I am trying to return "arr[i]" in the "for loop" which gives me this error, and when I try to take the "return arr[i]" outside of the "for()" loop the error reads the it cannot locate variable "i".
import java.awt.* ; import java.awt.event.*; import javax.swing.*; public class SwingSorts extends JFrame implements ActionListener { JRadioButton bubble; JRadioButton selection;
The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".
So far I have gotten the random number generation part working. I have up to here:
import java.util.Random; public class test4 { public static void main(String[] args) { Random random = new Random(); for(int i =0; i < 1; i++){ int num = random.nextInt(10) + 1; System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?"); } } }
Program is running fine. I can create usernames and everything but somehow I cannot quit or exit the program when I enter my sentinal value "QUIT". Here is my program question: Create an application that will create a username for a school computer system. Input a user’s first and last name. The username will be the first letter of the first name followed by the first 5 letters of his last name followed by a random 3 digit number. Continue to create and display usernames until a sentinel value is entered.
import java.text.*; import java.util.Random; import java.text.DecimalFormat; public class username
So im making this ghost game where i display an 8x8 filled with 0s and a randomly generator five 1s in there I can get it to display 0s and add 1s, however sometimes the 1s that are randomly generated sometimes go on the same spot making it look like there are only four 1s. How would i go about fixing that?
package Grade12; import java.util.Random; public class Ghost { public static void main(String[] args) { Random generator = new Random(); int gameboard [][] = new int [8][8]; int randomx, randomy, counter = 0, sum = 0; for(int row = 0; row < 8; row++){ for(int col = 0; col < 8; col++){ (gameboard[row][col]) = 0; }
Assume that vehicles are going through a two-way traffic intersection. There are three types of vehicles: car, motor bikes and trucks. Generate a series of 10 random integers, between 1 and 3,inclusive.The numbers represent the type of vehicle as stated below:
NumberVehicle Category 1Car 2Motor bikes 3Trucks
Write a program, using a for loop, to count how many vehicles going through the traffic intersection are cars, motor bikes and trucks. Then, the program should print out the numbers for each vehicle category. There is no user input for this program. How do i do it so they will add up the sum of each vehicle?
The answer should be something like
Number of cars = X Number of motor bikes = Y Number of Trucks = Z
I've been trying to get a card generator working, but hells bells nothing is easy in java (unless you already the correct answer) trying to figure out the correct way to apply a method you don't understand is like being asked for the German word for banana in Spanish class.
import java.util.Random; import java.util.Scanner; class jacktest { public static void main ( String[] args ) { Random r = new Random();
[code]....
my next step might be using object (hammer >=computer)=watch telly instead.
How do random text in an image ? Let me explain : I have ten identical pictures and want randomly appear different words in each image. This is possible to do?
while (gamesPlayed<gameQty) { userChoice = JOptionPane.showInputDialog("Rock, Paper, or Scissors?"); //Determine winner for each game if (compChoice.equalsIgnoreCase(userChoice));
[Code] ....
It seems to circle through the loop gameQty times, without comparing.
the program basically has a random number generating, and I want to ask the user to try to guess the number, and keep guessing until the number is right. In addition to this, I need to put in extra conditions for too high or too low by 10. So for example, if they user guesses a number and its off by more than 10, then it prints that they guessed too high, and if its below 10 they guessed too low.
import java.util.*; public class RandomNum { public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
[code].....
Modify the program to keep the user trying to guess the number till he/she gets it right, and stop once you guess the right number.Too high, high, too low, too low( If it's off by more than 10 = way too high, if its less than 10, way too low)
How would I get java to generate a random number from 0-2? all I've been able to find on random numbers is math.random which gives you from .0 to .10. you can multiply this by 10 to get 1-10 or by 100 to get 1-100 but how to make it so java will simply let me tell it the rand of numbers I want or get a random number in a range that is not a multiple of 10. and I can't seem to find anything about it anywhere.
I have been set this task, which is supposed to make me code using string arrays. The idea is to generate random sentences.This is what i have been able to do so far :
package usingarraysagain; public class sentences { public static void main (String[] args){ String[] NOUNS = { "lizards", "Nikola Tesla",
I have a class project working on that is supposed to ask the user for input and create a random set of #'s in 4 rows. However it compiles but doenst run At one point Eclipse was telling me Scanner not closed?
import java.util.Scanner; public class Matrixbuilder { // input a number that is used to build a matrix. ie = 4 rows and 4 colums //get the number //build the matrix of random integers //print the matrix
I'm trying to use a setter method to pick a random integer to be the MPG for a car. However, I'm having major issues in my driver when trying to use that random number in an instance. I'm not finished with the driver yet because I keep getting "cannot find symbol errors"
import java.util.Random; public class Car { private String make; private String model; private int year; private int mpg; private int odometer; Random generator = new Random();