Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Need Help with this Java Calculator

1. ## Need Help with this Java Calculator

Hello, I'm a beginner at this. This is my assignment and I need to program a calculator. Here is what i have so far:

```import java.util.Scanner;
public class IntCalc {
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
BigDecimal princ = 0;
double interest = 0;
char type = '\0';
int years = 0;
boolean clear = false;
boolean done = false;
while(!clear)
{
//checking for valid inputs
if((added != 'a' || added != 's' || added != 'q') && (type != 's' || type != 'c'))
{
}
else clear = true;
}
String header = "Period     Beginning Amount     Interest Earned     Ending Amount   ";
String out = "";
if(type == 's') out = calcSimple(princ, interest, added, years);
else out = calcComp(princ, interest, added, years);
System.out.println(out);
}

public String calcSimple(BigDecimal princ, double interest, char added, int years)
{
String o;
BigDecimal amnt = princ;
BigDecimal intEarned = princ*interest;
int num = 0;
if(added == 's') num = years*2;
else if(added == 'q') num = years*4;
for(int x = 0; x < num; x++)
{
o += IntegertoString(x+1) + "    " + IntegertoString(amnt) + "    " + intEarned + "    " + amnt+intEarned + "\n";
amnt += intEarned;
}
return o;
}
public String calcComp(BigDecimal princ, double interest, char added, int years)
{
String o;
Decimal amnt = princ;
BigDecimal intEarned = princ*interest;
int num = 0;
if(added == 's') num = years*2;
else if(added == 'q') num = years*4;
for(int x = 0; x < num; x++)
{
o += IntegertoString(x+1) + "    " + IntegertoString(amnt) + "    " + princ*interest + "    " + amnt+intEarned + "\n";
amnt += intEarned;
intEarned = princ*interest;
}
return o;
}
public void menu(BigDecimal princ, double interest, char added, char type, int years)
{
System.out.println ("This program will calculate simple and compound interest.");
System.out.println (" ");
System.out.println ("What is the principle amount?");
princ=input.next();
System.out.println ("What is the interest rate?");
interest=input.next();
System.out.println ("Will the interst be added anualy, semi-anualy or quartely? (a, s, q)");
System.out.println("Is the interst simple or compound? (s, c)");
type=input.next();
System.out.println("How many years would you like to calculate the interest for?");
years=input.next();
}
}```

This is the Error Message I'm getting when I try to compile:

``` ----jGRASP exec: javac -g IntCalc.java
IntCalc.java:32: cannot find symbol
symbol  : class BigDecimal
location: class IntCalc
public String calcSimple(BigDecimal princ, double interest, char added, int years)
^
IntCalc.java:47: cannot find symbol
symbol  : class BigDecimal
location: class IntCalc
public String calcComp(BigDecimal princ, double interest, char added, int years)
^
IntCalc.java:63: cannot find symbol
symbol  : class BigDecimal
location: class IntCalc
public void menu(BigDecimal princ, double interest, char added, char type, int years)
^
IntCalc.java:6: cannot find symbol
symbol  : class BigDecimal
location: class IntCalc
BigDecimal princ = 0;
^
IntCalc.java:35: cannot find symbol
symbol  : class BigDecimal
location: class IntCalc
BigDecimal amnt = princ;
^
IntCalc.java:36: cannot find symbol
symbol  : class BigDecimal
location: class IntCalc
BigDecimal intEarned = princ*interest;
^
IntCalc.java:42: cannot find symbol
symbol  : method IntegertoString(int)
location: class IntCalc
o += IntegertoString(x+1) + "    " + IntegertoString(amnt) + "    " + intEarned + "    " + amnt+intEarned + "\n";
^
IntCalc.java:50: cannot find symbol
symbol  : class Decimal
location: class IntCalc
Decimal amnt = princ;
^
IntCalc.java:51: cannot find symbol
symbol  : class BigDecimal
location: class IntCalc
BigDecimal intEarned = princ*interest;
^
IntCalc.java:57: cannot find symbol
symbol  : method IntegertoString(int)
location: class IntCalc
o += IntegertoString(x+1) + "    " + IntegertoString(amnt) + "    " + princ*interest + "    " + amnt+intEarned + "\n";
^
IntCalc.java:68: cannot find symbol
symbol  : variable input
location: class IntCalc
princ=input.next();
^
IntCalc.java:70: cannot find symbol
symbol  : variable input
location: class IntCalc
interest=input.next();
^
IntCalc.java:72: cannot find symbol
symbol  : variable input
location: class IntCalc
^
IntCalc.java:74: cannot find symbol
symbol  : variable input
location: class IntCalc
type=input.next();
^
IntCalc.java:76: cannot find symbol
symbol  : variable input
location: class IntCalc
years=input.next();
^
15 errors

----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.```

`import java.math.BigDecimal;`