Allow the user to specify the number of terms (5 terms are shown) to use in the computation. Each time around the loop only one extra term should be added to the estimate for PI.
Alter your solution from part one so that the user is allowed to specify the precision required between 1 and 8 digits (i.e. the number of digits which are correct; e.g. to 5 digits PI is 3.14159), rather than the number of terms. The condition on the loop should be altered so that it continues until the required precision is obtained. Note that you need only submit this second version of the program (assuming you have it working).
My output for part 1 is :
Enter number of wanted terms for value of PI
100
PI = 3.1666666666666665 Number of Term = 2
PI = 3.1333333333333333 Number of Term = 3
PI = 3.145238095238095 Number of Term = 4
PI = 3.1396825396825396 Number of Term = 5
PI = 3.1427128427128426 Number of Term = 6
PI = 3.1408813408813407 Number of Term = 7
PI = 3.142071817071817 Number of Term = 8
PI = 3.1412548236077646 Number of Term = 9
PI = 3.141839618929402 Number of Term = 10 ................ and so on
I know you have to compare value of current Pi to the previous one but I'm stuck.
The question states: Design a class named LinearEquation
for a 2 x 2 system of linear equations:
ax + by = e
cx + dy = f
Where
x =
ed − bf/ad − bc
y =
af − ec/ad − bc
The class contains:
- Private data fields a, b, c, d, e, and f. - A constructor with the arguments for a, b, c, d, e, and f. - Six get methods for a, b, c, d, e, and f. - A method named isSolvable() that returns true if ad−bc is not 0. - Methods getX() and getY() that return the solution for the equation.
Write a test program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad − bc is 0, report that "The equation has no solution."
I believe that my program is correct because I am able to compile it and get no errors, however I have no clue how to display the information for x and y or display this equation has no solution if ad-bc=0.
Java Code:
import java.util.Scanner; public class Exer911 { public static void main(String[] args){ // Create a scanner system to hold the numbers for each variable Scanner input = new Scanner(System.in); // Prompt the user to enter a number for each of the variables
I develop a finite element code at java. I am looking for efficiency solver and fast for large, sparse , symmetric and positive define matrices .
i used in jblas but i encounter in problem when the matrix has high condition number(ill condition number) and i get error for singular matrix while in mathematica i succeed to solve that system without problems...
Any good solver and fast solver package in java can i use for solving that system?
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:
Here is my full program, you can find these lines of code on lines 64 and 70.
Java Code:
import java.util.Scanner; public class StockTransaction { public static void main(String[] args) { // TODO Auto-generated method stub //Variable Declaration Section
So Ive got to make a turtle on an image draw a semicircle that starts at the top of a circle and goes down and to the left, changing colors halfway through. I've got everything down, I can draw the turtles and make them do straight lines. My problem is more math related. I need to use the equation of a circle, give it points, and figure out how to write that code in java.
We use the equation for a circle: (x - a)^2 + (y - b)^2 = r^2
I want make a math equation game. usually math game use equation for the question and we answer that equation. ex : what is the result of 2*5 / 2+2/ 2^2 etc. and we answering that. but i want to make it different so i want to make the equation answer as the question and the equation as the answer of the game. Ex : the question is 54 so we can answer it with 9*6 or 24+30. and this is my java code
package coba; import java.util.Scanner; public class Coba {
public static void main(String[] args) { double angka = Math.random()*70;
[Code] ....
but when i run it the error code show like this : Quote
I just created a program to calculate the roots for a 2. degree equation, When I first created my program, I defined the r1 and r2 as double, but got an error saying they needed to be defined as String, why is that?When should I be using string? I am new to java and I have mostly only used int, double and Boolean so far.
import java.util.Scanner; import java.text.DecimalFormat; public class c3e1 { public static void main(String[]args){
1) I'm trying to use a logarithm to determine the length of a user input number. I keep getting an error stating <> indetifier expected. I'm assuming this means that the program is not recognizing the function of a logarithm. I know that normally you can include that information in the method, but my teacher has stated specifically that each of these methods be called something else, as shown in the code.
2) I'm not quite sure I understand how to assign the numbers I obtain from the modular equation to a certain position in the array. As I'm asking the user to input any number these values can change so therefore I can't simply state that first number = this place.Here is my code:
import javax.swing.*; import javax.*; public class getSize { public static void main( String[] args )
I am running into some trouble with Line-Plane intersection, my method works, provided I am perpendicular to the plane I want to intersect. This is caused be the plane equation (with my given x, y, and z coordinates, the equation is -Z - 1 = 0). So the equation is only relying on the Z value of anything inputted. Is there another way to calculate the equation of a plane that would rely on all axis? Here is my current code:
Java Code:
Vector3f A = new Vector3f(0, 0, -1); Vector3f B = new Vector3f(0, 1, -1); Vector3f C = new Vector3f(1, 1, -1);
This is what I have so far, but I don't know how to continue:
import java.util.Scanner; public class ArithmeticComputation{ public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int num1 = stdin.nextInt();
[Code] ....
I'm looking for a method that allows me to assign char into actual operators, so that I can loop through all the computation.
This is what I need to do: Write a method called scientific that accepts two real numbers as parameters for a base and an exponent and computes the base times 10 to the exponent, as seen in scientific notation. For example, the call of scientific(6.23, 5.0) would return 623000.0 and the call of scientific(1.9, -2.0) would return 0.019.
This is the method I have written:
public double scientific(double num1, double num2); { double base = num1; double exp = num2; double scientific = base * Math.pow(10, exp); System.out.println(scientific); return scientific; }
These are the following error messages I received when trying to compile the code:
Line 4 missing method body, or declare abstract missing method body, or declare abstract public double scientific(double num1, double num2);
My verify method also always returns false. So I'm given three classes to begin with. Calculator, Expression, and InfixExpression and they are listed below.
The goal is to create a class called PostfixExpression that extends Expression and can read and calculate postfix expressions.
My evaluate() method works for most calculations but when it needs to return a negative value it just returns the positive equivalent.
Also, my verify method always returns false and I can't pinpoint why.
Here's my current code. Some things are commented out for debugging purposes.
import java.util.Scanner; /** * Simple calculator that reads infix expressions and evaluates them. */ public class Calculator { public static void main(String[] args) { Scanner input = new Scanner(System.in);
<import javax.swing.JOptionPane; public class TempCalc {
public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = (JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)");
[Code] ....
So I've been trying to come up with a Farenheit to Celsius converter and back. However, whenever I run the program in JCreator it never recognizes the string "Farenheit". Even if I put that exact thing (I copy/pasted from the if (FarOrCel == "Farenheit")) it keeps asking me for a Celsius value.
[quote name='INNOCENTREAPER##!' date='28 September 2014 - 07:40 PM' timestamp='1411958437' post='2057072']
<import javax.swing.JOptionPane; public class TempCalc { public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)";
Basically I'm trying to compute the standard deviation for a set of numbers and I'm using previously know data to compute this. The data I'm working with is here (note all of this is fake as its for an assignment):
Next this is the code that I know is producing the error:
/** * Pass in original data from files, and pass in computed grades as arraylist. this returns all of the standard deviations to be printed */ public static ArrayList calcStandDev(String data1[], ArrayList<Double> grades, ArrayList<Integer> averages) { double standDev = 0; int j = 0; //gets rid of first element in string array, makes processing MUCH easier String[] data = Arrays.copyOfRange(data1, 1, data1.length);
[Code] ....
Look for the line with all the ***'s, it is producing the "java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer".
The reason I dont undersand why its producing this error is because temp.get(i) should be a integer - averages.get(i) (is type double), I do believe automatic up casting is present here making them both a double then I multiply it by itself producing a double? I dont understand where the casing is occurring. And just incase you want the formula I'm using for standard deviation here it is:
Write a program that computes the cost of painting and installing carpet in a room. Assume that the room has one door, two windows, and one bookshelf. Your program must do the following:a. Prompts the user to enter, in feet, the length, width, and height of a room.
A. Read the dimensions of the room.
b. Prompts the user to enter the width and heights, in feet, of the door, each window, and the bookshelf. Read these quantities.
c. Prompts the user to enter the cost, per square foot, of painting the walls. Read these quantities.
d. Prompts the user to enter of cost, per square foot, of installing carpet. Read these quantities.
e. Output the cost of painting the walls and installing the carpet.
My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.
When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.
//stephanie import java.util.Scanner; public class gradeAverage { public static void main(String[] args)
We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.
1)A factorial of a number X is equal to X*(X-1)*(X-2)*...*1.For example,3! is equal 3*2*1=6.Create a class called Factorial Algorithm which will compute and print the factorial of an integer number on the screen
2)Write a Java program to accept eight integers and a search element from the user and display whether the element is found or not.(Hint:use bubble sorting and binary search)
I have tried running the java application without adding the site to site list in java security tab. But I get a sand box message as APPLICATION BLOCKED BY SECURITY SETTINGS. How to run the java application without adding the site to site list in java security tab.
I want to develop a Java program that uses OpenScript APIs to test my applications. The OpenScript framework automatically creates the Java Code so I was thinking of either using this code or create my own using the APIs.
I tried both options using NetBeans but I'm getting errors everywhere starting with the library import. I'm pretty new to Java so I'm sure I'm missing a lot of things here. I pasted the code below from the OpenScript framework that want to use in a stand-alone file for your reference.,
I've written a java application with several classes all in the same .java file. It works just fine. Now, I've broken it up so that each class has its own .java file. Still works fine. My next step is to put those classes into a package, but I'm not about to get the program to run.The .java source files are all in /home/user/src
I've set the CLASSPATH to /home/user/src..All of the source files have "package com.myfirm.program" on the first line.I compiled the application with:
the compiler created the directory: /home/user/src/com/myfirm/program and put all of the .class files in there.So how do I get the program to run? if I run from /home/usr/src
java File1
I get: Exception in thread "main" java.lang.NoClassDefFoundError: File1 (wrong name: com/myfirm/program/Program)
In Main.java, How can i call method in CircleCalculationMethod.java ?
Should I put everything in same folder ??Should i do something like "import CircleCalculationMethod.java"Should i do something like create a package ...