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;
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;
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;
I'm having an issue with figuring out how to structure and call a method using a string prompt. My prof has given us specific methods to create, and the one I'm having issues with is blic static double getOperand(String prompt). What I have currently is this:
public static double getOperand(String operand1, String operand2){ Scanner input = new Scanner(System.in); System.out.println("What is the first operand?"); operand1 = input.toString();
System.out.println("What is the second operand?"); operand2 = input.toString(); return operand1, operand2; }
which is obviously not working. When I asked my prof he sent me this, "The String paramater in the getOperand() method is intended to have the prompt value that is passed to it. Within the method, the prompt is then displayed, what the prompt is asking for is input, and then returned to the method call.For example, if the method is public double getOperand(String prompt) within the method you would display the prompt, as in System. out. println(prompt), use the Scanner class to create an object, perhaps called input, and then use the input object to get the value asked for by the prompt. Once you have that value, which in this example would be a double, then return the value to the method that called it.
The call could be something like this: double value = getOperand("What is the first operand?");". But that only works a little. Clearly I'm missing something and no matter what I google, or how many times I read the chapter, I am just not getting this. Everything else up to this point has been easy. and I can create regular methods just fine, the menu method works, but I can't figure out this string method and all the rest build off this method.
I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is strong return a, if it is notstrong return b. How would you write that in a Code?
I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.
mlong should return an int depending on the X.moth. at the moment my code looks like this:
// File1: public class date { public int day; public int month; public int year; }
// File 2: public class monthlength { public int mlong(date X) { int t; t = X.month; if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12) { return 31; } if(t == 4 || t == 6 || t == 9 || t == 11) {return 30;} } }
How do i take input values for TwoDPoint (which are objects) and return it back in numerical values also print them.
When i create an object in main method and pass values to my function of return type TwoDPoint,it gives error:- found int,int need TwoDPoiint,TwoDPoint.
// Here is what i tried to do:
Created class TwoDPoint that contains two fields x, y which are of type int. Defined another class TestTwoDPoint, where a main method is defined.In the main method created two TwoDPoint objects.
Then I modified the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).
Then I added another function to TestTwoDPoint. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoint's and whose y value is the sum of the y values of the input TwoDPoint's.
class TwoDPoint { int x = 2; int y = 4; } class TestTwoDPoint { public static void main(String args[]) { TwoDPoint obj1 = new TwoDPoint(); System.out.println(obj1.x); System.out.println(obj1.y);
Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.
Hints:
- The distance between two points can be calculated by taking the square root of
( x2 - x1 )2 + ( y2 - y1 )2
- Use Math class methods to compute the distance.
- Your output should appear as follows:
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter
Or Enter X1: 1
Enter Y1: 1
Enter X2: 4
Enter Y2: 5
Distance is 5.000000
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
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
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.
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();
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
Alright, I don't understand how to link my compress method to my return statement method "getPText". Also in my compression I only want it to compress for 3 or more consecutive letters.
I need to write a method that will consume string representation of Object type and will return one object of this type. How to set return type for the method in this case?
Here is exmaple :
public <?> identifyType(String typeString){ if (typesString.matches("String")){ return new String(""); }else if (typeString.matches("Integer")){ return new Integer(0); } //....etc..}
The two last methods stumped me. The return type to each is "DateTime", according to JUnit complaints.I know that I can use the "this" keyword to reference to the object. But how do I get these two methods to return the correct result?
I've a question on rounding doubles on 0.05 As far as i know there is no class method that is able to do this. To achieve this rounding i have the following code:
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
I'm trying to calculate a certain value, but it is returning 0 and I'm not sure why. This is a measurement to define the angle from the equator and the center of the sun
For my project, I am trying to return the method average so the program can calculate the average after grades are enter. I'm not sure what I am doing wrong and how I should improve it. My code is below. This is my error message: "Project.java:71: error: '.class' expected".
import java.util.Scanner; public class Project { public static void main(String[] args)
Im having trouble with my method return. I am new to using methods and cant seem to grasp the idea on the return part. I have to write a method that tells if a number is prime or not. This is what I have so far and it wont compile because it is saying "missing return statement } "..
import javax.swing.JOptionPane; public class IsPrimeMethod { public static void main(String []args) { String primeNum; int number; int i = 2;
I've just been having a go at an exercise where I have to create and use a class called Point, with two fields of type double. I have to create some methods for it, one of which is a distanceTo(Point) method, that calculates the distance to another point. I've tried to keep the distanceTo(Point) method short so have created some other methods to use within the method. My question is about the getDistance() method that I've made. As you can see below, I've given it two parameters, which are references to values within two Point objects (this.x and otherPoint.x).
public class School { public final int MIN_GRADE = 0; public final int MAX_GRADE = 100; private int [] grades; public School( int students ) { grades = new int[students];
[Code] ....
The output is :
The numbers in the array are: 1 2 3 4 6 7 8 9 10 13 14 15 The highest grade is: 11
For some reason it is not giving me the highest number in my array. Did I write the method wrong ? Is my array even passing through HighestGrade ?
I am getting these errors with this code, I can not figure why this error is occuring.
what is the issue with this code?
Java Code: package ABC; import java.util.ArrayList; import java.util.Scanner; public class GetInputFromUser { private ArrayList<String> name = new ArrayList<String>();