I've been looking at the calculating PI using Monte Carlos method. All of the codes request an input from the user to be able to determine PI. However, I want the program to print out only 10, 100, 1000, 10000, 100,000 and 1,000,000,000 for PI.
I am trying to calculate a fine in a PoliceOfficer object with method calls to a ParkedCar and ParkingMeter object. The word problem is:
The fine is $25 for the first hour or part of it and $20 for every additional hour of part of it.
My code is:
public class PoliceOfficer public static final int PARKING_FINE1 = 25; public static final int PARKING_FINE2 = 20; public static final int NUMBER_OF_MINUTES_OVER_PARKED = 60; public double calculateFine(){ double calculateFine = 0;
[Code] ....
obviously the fine is not calculated correctly but I'm not sure how to proceed from here...
import java.awt.*; import java.applet.*; import java.awt.event.*; public class Assignment extends Applet implements ActionListener { TextArea textInput = new TextArea(); // user input Button analyzebutton = new Button("Analyze"); Button resetbutton = new Button("Reset"); Label lbloutput = new Label ("Please enter text into the textbox!");
Write method distance, which calculates the distance between two points (x1, y1) and (x2, y2). All numbers and returned values should be of type double. Incorporate this method into an program that enable the user to enter the coordinates of the points, then calculate and display the distance by calling the method –distance.
I've tried numerous times to make it work and I'm on the right path, however I'm missing some things in the code to make my results look like this later on, which I've attached onto this post.
I have to write a program to calculate my weight on different planets and to do that, I have to read in the surface gravity of all the planets from a file using a separate method from main
public static double[] readGravity() throws IOException { double[] surfaceGravity = new double[8]; Scanner readFile = new Scanner("gravity1.txt"); int i = 0; while (readFile.hasNext()) { surfaceGravity[i] = readFile.nextDouble(); i++; } return surfaceGravity; }
I get this message in the while loop when I try to run the program:
java.util.InputMismatchException; null (in java.util.Scanner)
I have understood my programming class up to this point and now I have been given a lab that I can't figure out for the life of me. Here what I have to do: Write a program that will call a method (called f) to calculate the following function" f(x)=(x^2)-16...this is what the output should be:
I need to modify the drawShape method to calculate the distance from the starting point (the diameter) of any shape regardless of how many sides I give it, but I have absolutely no clue where to begin with this. The ultimate goal of the program is to calculate the value of pi using the shape that is drawn.
Java Code:
public class PiTurtle extends Turtle { private double mySize; private int mySides; private double diameter = 0;
I am trying to write a loop that calculates the distance traveled (distance = speed * time). It should use the loop to calc how far the vehicle traveled for each hour of time. My program asks for hours and then mph but its not calculating time * speed. Here is my code.
public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter Hours Traveled "); int hoursTraveled = input.nextInt(); System.out.println("Enter MPH "); int mph = input.nextInt();
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).
I made a MVC calculator. I was wondering if you could take a look at my design and if I was on track. I am still working on getting it to actually calculate something. All the buttons respond and print text on the JTextField but it is not calculating.
package calculator.MVC; import javax.swing.JButton; import javax.swing.JTextField; public class CalculatorModel { private int sum; private int number; private char opt;
public class NewClass4 { public static void main(String[] args) { int a = 1; int b = 2; int c = 3; a += 5; b *= 4; c += a * b; c %= 6; System.out.println("a = " + a); System.out.println("b = " + b); System.out.println("c = " + c);
public class PondRadius { public static void main (string[] args) { //Calculate the radius of a pond //which can hold 20 fish averaging 10 inches long int fishCount = 20;//number of fish in pond int fishLength = 10;// Average fish length int inchesPerFoot = 12;//number of inches in one foot
[Code] ....
And here is the error or exceptions i received
C:javaLesson1>javac PondRadius.java PondRadius.java:23: error: ')' expected System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch es long you need a pond with an area of " +
So I have this code to calculate the lowest value of an array:
public class Exercise1 { public static void main(String[] args) { int[] theArray = {1/*/,2,3,4,5,6,7,8,9,10/*/}; int result = Exercise1.min(theArray); System.out.println("The minimum value is: " +result);
[code].....
and I need to write an exception class that should be thrown if the array does not hold any elements.
I have been tasked with creating an invoice (school assignment). Part of the calculations is creating an interest depending on the amount of days between the current date entered, and invoice date entered (The program prompts the user to enter both the current and invoice dates by asking for the day, month and year).
We are also supposed to set the contructor to a default date of 1/1/1900.. but I don't know how or where to code that.
How to calculate the difference between the CurrentDate and Invoice. I have displayed the dates to the user as follows.
how does the program know to calculate for only one year?
public class Interest2 { public static void main(String[] args) { double principal; // The value of the investment. double rate; // The annual interest rate. double interest; // The interest earned during the year.
i need to calculate the minimum and the maximum, actually it seems to be easy but, the minimum should be the smallest number but 0..this is my code
Java Code:
Scanner s = new Scanner (System.in); int max = 0 ; int min = 0 ; System.out.println(" Please enter 3-5 numbers"); int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); int d = s.nextInt(); int e = s.nextInt();
there are the normal parking rates with two condition using two difference code and two difference calculator method. the fees for the two code also different.i need to display the code, enter time. enter out, and parking charge. i have a problem with the processor method.
So I wrote a method that simply calculates the sum of all integers between 1 and a given integer n. The method works fine however, as n gets big the solution will have time and space problems. Some I'm just curious if there is a better method than my iterative one that would produce a better Big O value.
public static int sum(int n) { int total = 0; for (int i = 1; i <=n; i++) total += i; return total; }
Write a program called ComputePi to compute the value of pi using the following series expansion. you have to decide on the termination criterion used in the computation(such as number of terms used or the magnitude of an additional term). Is this series suitable for compute pi?
I have for example a letter code "EECC"...Now i want to have a good loop that checkes if the code typed in by the player matches or not? For example if player types CECE it should say it matches because C occurs 2 times and E occurs 2 times. This function must return than 4.If player types CEEE, it must return 3, because the code has 2 C en 2 E, player input is 1 C and 3 E, the last E is wrong.I've tried some loops with breaks but they all fail..
for example:
String test = "EFCC"; String test3 = "ECEC"; for(int i = 0; i < test.length(); i++){ matchFound = false;
The first is MyArray Class (You can either use an array or an arrayList)Create a class called LastNameFirstNameMyArray according to the UML diagram. This class will allow a user to enter 5 integer values into an array(or object of ArrayList<Integer>). It contains methods to find min and max values and calculate the mean for the data set.
LastNameFirstNameMyArray - data[ ] : int (or data : ArrayList<Integer> ) - min : int - max: int - mean : double + LastNameFirstNameMyArray() + findMin() : void + findMax() : void + calculateMean(): void + toString() : String
Attributes: data[]the array which will contain the values or data<Integer>the arraylist which will contain the values minthe minimum value among the values in the arraylist maxthe maximum value among the values in the arraylist mean the arithmetic average of the values
Methods: You need to implement the constructor LastNameFirstNameMyArray(), which populates 5 values. In addition, the constructor should call findMin() and findMax(), and also calculateMean().
Methods: LastNameFirstNameMyArray()the constructor. It will allocate memory for the array (or arraylist) of size 5. Use a for loop to repeatedly display a prompt for the user which should indicate that user should enter value 1, value 2, etc. Note: The computer starts counting with 0, but people start counting with 1, and your prompt should account for this. For example, when the user enters value 1, it will be stored in indexed variable 0. The constructor should populate 5 integer values, call findMin() and findMax(), and also calculateMean().
findMin()this is a method that uses a for loop to access each data value in the array (or arraylist) and finds the minimum value. The minimum value is stored into min.
findMax()this is a method that uses a for loop to access each data value in the array (or arraylist) and finds the maximum value. The maximum value is stored into max.
calculateMean()this is a method that uses a for loop to access each data value in array (or arraylist) and add it to a running total. The total divided by the number of values (use the length of the array), and the result is stored into mean. toString()returns a String containing data, min, max, and the mean.
Task #2 TestMyArray
1. Create a LastNameFirstNameTestMyArray class. This class only contains the main method. The main method should declare and instantiate a LastNameFirstNameMyArray object. 2. Compile, debug, and run the program. Then, it should print out the contents, the min, max, and mean of the data.
and the second is A theater seating chart is implemented as two-dimensional array of ticket prices, like this:
Write a program that prompts the users to pick either a seat or price. Mark sold seats by changing the price the 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price.
Note: Assume that if the user enters 1 for the row and 1 for the seat, the yellow marked sit will be sold.
i finished up a project here and seem to be running into some issues. I figured its my notation, when i ask a user to enter a number, if its below 10, it should *only* print "No Coupon." but what appears to happen is that the program prints "No Coupon" Plus the "discount coupon and % of purchase."
import java.util.Scanner; public class assign1c { /* Start of Class 1c */ static double cost; static double coupon = 0; static String x = "No coupon"; public static void main(String[] args) { // TODO Auto-generated method stub