PDA

View Full Version : simple java calculator Help!

babypandabacon
02-18-2012, 02:11 AM
im just:o learning java and im trying to program a multipurpose calculator but i keep running into brick walls. Heres the coding:

import java.util.Scanner;

public class dinoremix2{

public static void main (String[] args){
boolean play = false;
String playAgain;
do{

String math;
System.out.println(" Hello! Just type what you want to do! add , multiply , subtract , divide , or quadratic (please dont use caps) ");
String math = scan.nextString;

do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 + num2;

if (math = subtract);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 - num2;

if (math = divide);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 / num2;

if (math = multiply);{
do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
int num1 = dinoremix.nextInt();
System.out.println(" Thanks! Please Enter The Second Number: ");
int num2 = dinoremix.nextInt();
int answer = num1 * num2;

do{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);
double a = scan.nextDouble();
double b = scan.nextDouble();
double c = scan.nextDouble();
double disc = (b*b)-(4*a*c);
boolean isImag = false;
if (disc == 0){
double fac = (b * -1) / (2 * a);
System.out.println("heres the root" + fac);
}
if(disc > 0) {
isImag = false;

}
if (disc < 0){
isImag = true;
disc = disc * -1;
}
double fac1 = ((b * -1) + Math.sqrt(disc))/(2*a);
double fac2 = ((b * -1) - Math.sqrt(disc))/(2*a);
if (isImag){
System.out.println(fac1 + "i");
System.out.println(fac2 + "i");
}else{
System.out.println(fac1 + "i");
System.out.println(fac2 + "i"); }

System.out.println("Try again? ");
playAgain = in.nextLine();
if(playAgain.equals("yes")){
play = true;
}
if(playAgain.equals("no")){
play = false;
}
}
}
im missing a set of closing brackets somewhere but i cant find where :(

xelawho
02-18-2012, 02:49 AM
another brick wall: posting in the wrong branch.

this is javascript. you're looking for java

Old Pedant
02-18-2012, 06:03 AM
You are missing *MANY* closing braces.

Why in the world are you using do, at all?

You also have a fatal error in your if usage:

That semicolon there means the condition after the if is NOW COMPLETE.

The code after the semicolon will thus be executed no matter if the if condition is true or false.

KEEP IT SIMPLE!

{
Scanner in = new Scanner(System.in);
Scanner scan = new Scanner(System.in);