Arithmetic Expression With Quadratic Formula
Oct 3, 2014
I have just started to learn programming in the book I am teaching myself from it said how would you write the following arithmetic expression with it being the quadratic formula but only the plus part of it in the plus or minus..
package javalearning;
import java.util.Scanner;
public class QuadraticFormula {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter value for B: ");
double B = input.nextDouble();
System.out.print("Enter value for A: ");
double A = input.nextDouble();
System.out.print("Enter value for C: ");
double C = input.nextDouble();
double negativeOfB = -B;
[code]....
View Replies
ADVERTISEMENT
Mar 4, 2015
Write a program named QuadraticTable.java that takes three double arguments and two int arguments (in that order) from the command line. The three doubles will represent a, b, and c from the quadratic formula.
If the discriminant is non-negative, find and print the solutions to the quadratic equation. (The plus/minus sign in the quadratic formula indicates that you would separately perform both operations). Otherwise print "no real solutions".
Then using the last two int arguments as x_min and x_max, print a table of x and ax
2 + bx + c
values using the a, b, and c read in as command line arguments.
Sample output: (command line arguments were 1 0 2 -3 3)
1x^2 + 0x + 2 has no real solutions.
X 1x^2 + 0x + 2
-3 11
-2 6
-1 2
0 2
1 3
2 6
3 11
View Replies
View Related
Oct 26, 2014
I have a given arithmetic expression, which form is (A+B) or (A-B), were A and B are either numbers from 0-9, or another ARITHMETIC Expression.
The first thing that comes to my mind is a recursive function, but how to start...
View Replies
View Related
Sep 29, 2014
I am looking to find a way to display the number of decimal places without using any type of formatting string.
Only to make it xxx.x instead of xxx.xxxxxx.
View Replies
View Related
Nov 18, 2014
This was the way I was supposed to write it (every thing separated). Any way, I was wondering why when ever I try to run I only get NaN for roots, and my discriminant is off
/**
* Find roots of quadratic equations
*/
import java.util.Scanner;
public class QuadraticProject {
public static void main(String[] args) {
[Code] ....
View Replies
View Related
Feb 14, 2014
I am suppose to write a method for solving a quadratic equation using the following header:
public static int solveQuadratic(double[] eqn, double[] roots)
I have entered 1, -3 and -4. The answer I get is "The solution is:0.0" .
import java.util.Scanner;
public class QuadratilEq {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
double[] eqn = new double[3];
double[] roots = new double[4];
[Code] .....
View Replies
View Related
Mar 30, 2014
What is accurate formula area and perimeter for pyramid and hexagon? I got stuck of my assignment.
View Replies
View Related
Mar 17, 2015
I am working on this new project where we are using the great distance formula but every time I run my ending result is NaN. I was researching, and people say its because you divide by 0. I think I have my formula correct.
Java Code:
public class testingFormula {
public static void main(String[] args) {
double lat = 34.01858902;
double lon = -118.2817688;
double lat2 =33.94530869;
double lon2 = -118.3994904;
[Code] ....
View Replies
View Related
Jan 28, 2014
It's suppose to generate a table with the month, and the new amount of the CD. Right now, the program generates a continuous table for months, but it doesn't update the value of the CD.
import java.util.*;
public class Excercise04_31 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
[Code] ....
View Replies
View Related
Jan 20, 2015
I'm trying to convert a Formula to run in a java program.
This is the formula:
(you can ignore the modifier part)
This is my attempt. However it prints out 0.0
import java.util.Scanner;
public class DamageCalc{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
[Code].....
View Replies
View Related
Sep 1, 2014
i am trying to calculate the number of months it takes to pay off a set amount of credit card debt given the following information: principle amount, annual interest rate, and monthly payment. How to import the formula necessary to system.out.print the answer (number of months it takes to pay off debt) ???
View Replies
View Related
Feb 10, 2014
Still trying to get a handle on arrays! So, I declare an array to be a 46x1 and I am trying to populate it with a Log formula that I am using but I keep getting an ArrayIndexOutofBoundsException.
Code :
private double[][] LNValues = new double[46][1];
//Calculating y=LN(E-k) and Initializing the Array
for(int x=0; x<LNValues.length; x++)
{
double i = Math.log(eValues[x][1] - kValue);
if(i > 0)
[Code] ....
View Replies
View Related
Sep 6, 2014
I'm supposed to take an input from the user and calculate the value of pi using this formula: 1/1 - 1/3 + 1/5 - 1/7 etc... so on alternating between minus and plus and denominator increasing by 2 every time. If the user inputs the number 3, then it should print (1/1 - 1/3 + 1/5 - 1/7 + 1/9) *4. The idea here is that the higher the input of the user is, the higher the equation will be close to pi.
This is what i have so far :
import java.util.Scanner;
public class Pi
{
public static void main(String[] args) {
double first = 1/1;
double second = 1/3;
Scanner input = new Scanner(System.in);
System.out.println("Enter a Number to calculate how far you want the formula to perform: ");
double count = input.nextDouble();
}
}
This is literally all i have, i know i need a while loop and an if loop.
View Replies
View Related
Jun 19, 2014
I have this formula for creating quarter wave antennas, however for some reason I can not get the right answer for it. double parM takes the users information which is a frequency in Megahertz and changes to feet so we can construct our antenna. However, in the program it gives me 1.9 instead 7.7 which it is suppose to be.
double parM = Double.parseDouble(userInput.getText());
double getSize = (234 / parM) * 12; // 12 is in inches
View Replies
View Related
Sep 19, 2014
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
amanda.setName("amanda");
amanda.setShellColor(Color.BLUE);
amanda.setBodyColor(Color.RED);
amanda.setPenColor(Color.YELLOW);
amanda.setPenWidth(3);
amanda.forward();
amanda.turn(-90);
amanda.setPenColor(Color.BLUE);
amanda.forward(???);
the question marks are where I need to draw a line on an arc, like in the picture.
View Replies
View Related
Feb 24, 2014
Basically its a program where a user is prompted to enter the length of all three sides of a triangle and the program calculates the area by herons formula and can tell if the triangle is equilateral or Pythagorean. I am having trouble entering a formula to where all three enter sides cant possibly be a triangle. Here is my Program. Where the '?' is stated.
import java.util.Scanner;
public class Triangle {
public static void main(String[] args){
double a;
double b;
double c;
double s;
double x;
double area;
[Code] ....
View Replies
View Related
Aug 6, 2014
How do i go about developing a simple arithmetic tester program which can be used to support young children improve their arithmetic skill. The program should accepts string data for the player's name and the number of questions they want to try, which will be entered by the user. The program should take in the following inputs from the user:
The name of the player, so that the game can refer to them by name in messages. The name must be between 2 and 20 characters inclusive.
The number of sums that the user wants to attempt. This number must be a whole number, and be between 2 and 50 inclusive.
The program must check that the values entered fall within the valid ranges. The program must also check that no empty strings are entered for names.
Once the player has entered their name and the number of questions they want to attempt, the game begins. The program must generate sums for the player.
The program should generate one question at a time and display the question for the user. The questions must involve two numbers and be either a multiplication, division, subtraction, or addition. For example, the following are all valid questions:
3 * 4 = ?
8 / 2 = ?
7 + 1 = ?
9 - 8 = ?
The first number, second number, and arithmetic operator (multiply, divide, add, subtract) should all be chosen randomly, the program should Generate a new random number for each of the three parts of each sum. this requires you to choose one of the four symbols based on which random number is returned.
A few checks must be carried out before a generated question is displayed to the user. If the question is an addition question, no checks are required. If the question is a multiplication question, no checks are required. However, checks are required for subtraction and division sums.
If the question is a subtraction question, the program must check that the second number is equal to or smaller than the first number. Whilst the second number is larger than the first number, new numbers should be generated.
View Replies
View Related
Nov 21, 2014
import java.util.*;
public class TestArithmetic {
public static void main(String [] args) {
Scanner console = new Scanner (System.in);
System.out.println("Enter First Number");
int x1 = console.nextInt();
System.out.println("Enter Second Number");
[code]...
View Replies
View Related
Nov 25, 2014
I'm new to Java and I want to write a program that compute all the possible arithmetic operations of 4 integers.
For example, if the user enter 1, 2, 3, and 4 respectively, then I want the computer to print out the following results:
1 + 2 + 3 + 4
1 + 2 + 3 - 4
1 + 2 + 3 * 4
1 + 2 + 3 / 4
..
1 / 2 / 3 / 4
(parenthesis can be ignored for this program)
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.
View Replies
View Related
Apr 1, 2014
So I have one set of If Else If statements. My program calculates just the first comboBox. It is retrieving all the values from the other comboBoxes but I do not understand where to place the other If statement structure so I can calculate the other values I have set for the other objects. I would not like to use a different class for each and I know I have my calculations done right below my current if statement. Could it be left there and where shall I place the other if statements so they get read by my arithmetic sequence?
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource() ;
int deckSiz = (int) Decks.getSelectedIndex() ;
int wheelSiz = (int)Wheels.getSelectedIndex();
[code]....
View Replies
View Related
Jan 29, 2015
I want to catch the exception in my program is the below way:
class Temp
{
public static void main(String s[])
{
try
{
int x=10/s.length;
System.out.println(x);
[Code] ....
I am expecting my program should give output as "java.lang.ArithmeticException: / by zero" but is giving
Temp.java:11: error: ')' expected
catch (ArithmeticException e | ArrayIndexOutOfBoundsException e)
^
Temp.java:11: error: ';' expected
catch (ArithmeticException e | ArrayIndexOutOfBoundsException e)
^
Temp.java:16: error: 'catch' without 'try'
catch (Exception e)
^
Temp.java:22: error: reached end of file while parsing
}
^
4 error
View Replies
View Related
Feb 23, 2014
The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.
Here is what I have so far:
double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 };
ArrayList<Double> d = new ArrayList<Double>();
ArrayList<Double> e = new ArrayList<Double>();
for ( double x : q ) {
d.add( x );
e.add ( new Double ( x ) );
[Code] .....
Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.
View Replies
View Related
Nov 6, 2014
My goals:
1) Have some source file be read in
2) Specify what arithmetic operators to swap (+, -, /, *)
2) If an arithmetic operator is read (like a + sign etc) then we swap it with its opposite (- for example)
3) Once the swap is complete, the rest of the file stays the same even if more operators are in the file...it is then output to a file (I am going with 1mutation.java)
4) This is where it gets tricky....it then picks up where it left off to finish reading the + operators (or whatever was specified) and repeats steps 2-3 (but the operator that is already swapped gets left as it was / skipped) and the output is saved as 2mutation.java.
The most I have been able to manage is having it changed 1 operator or all of them at once. I deleted a lot of my work to start fresh / master one operator for the time being. Here is what I have:
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
public class OperatorSub {
[Code] ....
This is the data file I am using. (see attached) The file should be .java or .cpp but I stuck with .txt for now. How to tackle this? Am I on the right track?
View Replies
View Related
Oct 13, 2014
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");
[Code] .....
View Replies
View Related
Sep 19, 2014
I am new Java Programming and I am struggling to pass my Java class. How to perform Java but I am trying. For this particular assignment I supposed to:
* Change all variables' data types to double.
* Change the two prompts to request double values
* Change change the two calls to the nextInt() method to nextDouble().
This is the original assignment:
import java.util.Scanner;
public class ArithmeticDemo
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
int firstNumber;
int secondNumber;
int sum;
int difference;
int average;
[code]....
View Replies
View Related
Nov 17, 2014
I am trying to write a program which asks the user to enter two numbers and then do the arithmetic operation based on user's input . No compiling errors but when I run the program I keep getting "StringIndexOutOfBounds" error .
class arithmetic {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int ent1 = 0;
[Code]....
View Replies
View Related