Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » I need help making a calculator in java(I am a beginner in java programming and i currently am making a calculator in java. i use eclipse.)
icon5.gif  I need help making a calculator in java [message #1070438] Thu, 18 July 2013 01:00 Go to next message
Xavier Lacasse is currently offline Xavier LacasseFriend
Messages: 1
Registered: July 2013
Junior Member
hi, i am trying to use the Scanner tool to scan these symbols : *, /, -, +

my code:

this is the part that is used for integers:

import java.util.Scanner;
class CalculatorInt {
public static void main(String args[]) {
int FirstNumber;
double Sign;
int SecondNumber;
Scanner myScanner = new Scanner(System.in);
FirstNumber = myScanner.nextInt();
Sign = myScanner.next {
if (Sign = *) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = /) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = -) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = +) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}
}
}
}
}
}
}
}
}
}



this is the part used for numbers with decimals:

import java.util.Scanner;
class CalculatorInt {
public static void main(String args[]) {
double FirstNumber;
double Sign;
double SecondNumber;
Scanner myScanner = new Scanner(System.in);
FirstNumber = myScanner.nextInt();
Sign = myScanner.next {
if (Sign = *) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = /) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = -) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}else{
Sign = myScanner.next {
if (Sign = +) {
SecondNumber = myScanner.nextInt();
System.out.println("calculating");
System.out.println("calculating");
}
}
}
}
}
}
}
}
}
}
the 2 file attachments are the java code in java. the CalculatorInt.class is for the integers and the CalculatorDouble.class is for the numbers with decimals. Please tell me how to fix my code to make the scan work.
Re: I need help making a calculator in java [message #1070656 is a reply to message #1070438] Thu, 18 July 2013 12:05 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1035
Registered: July 2009
Senior Member
Two comments: don't post compiled class files and expect people to run them on their machines.

Second: use the compiler's error messages to detect the errors in your program and fix them before wondering why the code doesn't work.
Previous Topic:Exported tableLayout only shows header - works fine in Emulator
Next Topic:QuickDiff - using specific SVN revision as a reference source
Goto Forum:
  


Current Time: Wed Nov 26 00:51:33 GMT 2014

Powered by FUDForum. Page generated in 0.13208 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software