# Simple Calculator Code in Java - need help please!

Page 1 of 1

## 2 Replies - 2701 Views - Last Post: 26 October 2009 - 03:14 PM

### #1 sweetD

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 18-October 09

# Simple Calculator Code in Java - need help please!

Posted 18 October 2009 - 09:53 AM

Hello - I'm new to Java and hoping someone can help me with the code I have started. I need to create a simple calculator in Java. Below is what I have so far; it is not working currently and I'm not sure why. I also needed to add the parseInt function somewhere in the code but I'm not sure where. Thanks!

import java.util.Scanner;
public class CalcDemo {

public static void main(String[] args) {
}

private int valueA;
private int valueB;
private String operator;
private char operatorA;

public int getvalueA() {
return valueA;
}

public int getvalueB() {
return valueB;
}

{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter problem.");

{

valueA = keyboard.nextInt();
valueB = keyboard.nextInt();
operator = keyboard.next();
operator1 = operator.charAt(0);

int add = valueA + valueB;
int minus = valueA - valueB;
int multiply = valueA * valueB;
int divide = valueA / valueB;
String clearScreen = null;

switch (operatorA) {
case '+':
break;

case '-':
System.out.println(minus);
break;

case '*':
System.out.println(multiply);
break;

case '/':
System.out.println(divide);

case 'C':
System.out.println(clearScreen);
break;

default:
System.out.println("unknown operator '" + operator + "'. Please try again.");
break;
}

}
}
}

Is This A Good Question/Topic? 0

## Replies To: Simple Calculator Code in Java - need help please!

### #2 athlon32

• D.I.C Regular

Reputation: 117
• Posts: 363
• Joined: 20-August 08

## Re: Simple Calculator Code in Java - need help please!

Posted 18 October 2009 - 10:25 AM

There 'is' a Java forum

### #3 rdutchman

• New D.I.C Head

Reputation: 0
• Posts: 2
• Joined: 26-October 09

## Re: Simple Calculator Code in Java - need help please!

Posted 26 October 2009 - 03:14 PM

sweetD, on 18 Oct, 2009 - 08:53 AM, said:

Hello - I'm new to Java and hoping someone can help me with the code I have started. I need to create a simple calculator in Java. Below is what I have so far; it is not working currently and I'm not sure why. I also needed to add the parseInt function somewhere in the code but I'm not sure where. Thanks!

import java.util.Scanner;
public class CalcDemo {

public static void main(String[] args) {
}

private int valueA;
private int valueB;
private String operator;
private char operatorA;

public int getvalueA() {
return valueA;
}

public int getvalueB() {
return valueB;
}

{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter problem.");

{

valueA = keyboard.nextInt();
valueB = keyboard.nextInt();
operator = keyboard.next();
operator1 = operator.charAt(0);

int add = valueA + valueB;
int minus = valueA - valueB;
int multiply = valueA * valueB;
int divide = valueA / valueB;
String clearScreen = null;

switch (operatorA) {
case '+':
break;

case '-':
System.out.println(minus);
break;

case '*':
System.out.println(multiply);
break;

case '/':
System.out.println(divide);

case 'C':
System.out.println(clearScreen);
break;

default:
System.out.println("unknown operator '" + operator + "'. Please try again.");
break;
}

}
}
}

try the Tutorial: A Basic Calculator
http://sumtotalz.com...icCalc_Tut.html