Java Program To Test Circle Dimensions To Prove Pie
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;
I'm working on a homework assignment and I keep getting a compiler message this is the message
GradesAverage.java:44: error: variable totalgrade might not have been initialized System.out.println("Over all you have " + totalgrade); ^ 1 error
The homework is this Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test stores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table:
Test Score Average Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F
This is my code
import javax.swing.JOptionPane; // Needed for JOptionPane class import java.util.Scanner; // Needed for the scanner class public class GradesAverage { public static void main (String[] args)
Four experiments are performed, each consisting of six tests. The number of test results for each experiment is entered by the user. Write a Java program using a nested loop to compute and display the average of the test results for each experiment.
You can run the program by entering the following test results:
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 working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.
Anyway, i am working on simply making the spiral, which should look like the one below.
n = 3
7 8 9 6 1 2 5 4 3
where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.
import java.io.*; public class Spiral { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the number of elements : "); int n=Integer.parseInt(br.readLine());
I started with Eclipse and wrote the basic "Hello World" app and added a few other lines of a=5, b=9, println (a*b) etc. and ran the program in the screen.
Then I thought that perhaps I could move it onto my nexus 7 and see what it looks like there. [I have a lot to learn I suppose].
The first issue is that I can't connect my Nexus 7 tablet to me macbook pro without using "android file transfer" and then the computer does not show the device in the finder because it is running through the file transfer program.
I have done some research and changed the settings in the nexus to connect as a camera rather than storage but that doesn't work either.
So my main issue now is being able to get the program onto the device - can it simply be copied and pasted into one of the files on the device using the file transfer screen?
User-defined classes. The concept of getters and setters goes right over my head. Right now we're to write a program to test the Person class below. We have to create 2 instances of the class to test each constructor, and test each method.
class Person { // Data Members private String name; // The name of this person private int age; // The age of this person private char gender; // The gender of this person // Default constructor public Person() { this("Not Given", 0, 'U');
[code]....
then my output will print out the name. But the assignment doesn't tell us to modify the Person class at all, just to create a tester one.
i have to use a if loop. I just started using methods and loops..You have been hired as a software developer for Canada’s customs - Toronto Pearson International Airport. Your job is to develop part of the Canada Passport System. The Database Administrator has forwarded to you the database for all the Canadians. For simplicity, assume you only have five records (i.e., only five people on file). These fixed records are the following:
First name, Last name, SIN, Last Date of Entry to Canada, Number of Entries Mike beee 4567 12-12-1999 7 Jessie weree 4444 07-07-2007 1 Liza veee 2121 05-05-2013 2 Zico qeeee 2444 Never left the country 0
the two dimensional array stores all the values. In addition, all these values should be of type String.The Canadian officer can always see the following four choices:
1) Show custom’s database, 2)Update custom’s database, 3) A summary of a passenger’s record, and 4) Exit.
Choice 1 : always allows the officer to see all the database records (i.e., the five records). Each of these records consists of the following: First Name, Last Name, SIN, Last Date of Entry to Canada, and the Number of Entries (i.e., see the above stored values).
Choice 2 : allows the officer to update the database whenever one of the five Canadian passengers arrives. Once the officer chooses this option, the system will ask him/her for the SIN of the passenger. Then the system will ask for today’s date (i.e., the recent entry date). The system will then reflect those changes on the console screen and the number of entries will be increased by one.
Choice 3: summarizes the record for one passenger where his/her first and last names and last date of entry to Canada will be shown. The last date of entry should only have the last four digits (i.e., only the year). To extract those digits, you should use the String’s method(s). However,before a record is summarized, the records of all Canadians should be shown on the screen in order to allow the officer to choose among those records. Choice 4 allows the officer to exit from the system completely; otherwise the list of choices should be always shown on his/her monitor.This is the code i have so far.
import java.util.Scanner; public class QuestionFive{ public static void main(String[] args) {
double passportInput; Scanner sc = new Scanner(System.in); // public static int generalList() // to show the list of choices and return the chosen option // // public static void updateRecords(int recordSize, String[][] passportDataBase) //to update the records //
I'm making a program for school that reads a text file with answers to a personality test and prints the temperament to an output file. Problem is, it sets the temperament for the first person to INFJ and then prints INFJ for the rest of the people too. My code is below, and the input file 'personality.txt' goes like this:
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program:
calculateAverage This method should accept five test scores as arguments and return the average of the scores. determineGrade This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale
Score Letter Grade 90-100 A 80-89 B 70-79 C 60-69 D Below 60 F
System.out.println("Enter the first score"); test1 = keyboard.nextDouble(); System.out.println("Enter the second score"); test2 = keyboard.nextDouble();
I did a problem from my book which is "Write a method that displays an n-by-n matrix. Each element is 0 or 1, which is generate randomly. Write a test program that prompts the user to enter n and displays the n-by-b matrix".
So if a user would enter 3, and output could be 0 1 1 0 1 0 1 0 1
So here's my question... I was able to get the program to work in the way my book describes (by just writing the code in the class with the main), but for practice, I want to learn how to do this OOP-style...
I'm not sure how to do this, though, since the method is a void method, so I can't seem to call it within a toString method.
import java.util.Scanner; public class MatrixTest { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter an int"); int number = input.nextInt(); MatrixClass mc = new MatrixClass(number);
I have read the API and looked at examples but its not answering my question. Which layout would treat a panel as its own entity. Meaning if I made a method that made a matrix of buttons using GridLayout and returned that panel. Then called the method onto a frame and the buttons would not spread out all over the frame. They would simply stop at the dimensions of the panel. Am I looking for something that is not possible?
How do you test a default constructor in one class and then test it in a different class? This is the code for the Person class which has the default constructor. I'm not sure in the PersonTester class how to access this default constructor and how to test it - what I have so far for the second class is also below.
class Person { // Data Members private String name; // The name of this person private int age; // The age of this person private char gender; // The gender of this person
I have written this program but I am seeing error when I compile this program ( javac TestArithmetic.java).
1)TestArithmetic.java:26 cannot find symbol
2)symbol: class Arithmetic
3)location: class TestArithmetic
4) Arithmetic ar = new Arithmetic(x1,x2,x3);
1)TestArithmetic.java:26 cannot find symbol
2)symbol: class Arithmetic
3)location: class TestArithmetic
4) Arithmetic ar = new Arithmetic(x1,x2,x3);
2 errors.
Code :
import java.util.*; class TestArithmetic { public static void main (String[] args){ float number; Scanner console= new Scanner (System.in); System.out.println("Enter first number");
I have style sheet file (e.g. myStyle.xslt). I am trying to decide where to put this file in my web application so that both src and test can access it. All my source in packages inside /src folder and test code in packages inside /test folder.
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;