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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need Help with this Java Calculator

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 added = '\0';
    char type = '\0';
    int years = 0;
    boolean clear = false;
    boolean done = false;
    menu(princ, interest, added, type);
    while(!clear)
    {
    //checking for valid inputs
    if((added != 'a' || added != 's' || added != 'q') && (type != 's' || type != 'c'))
    {
    System.out.println("There was an error in your input, please try again.");
    menu(princ, interest, added, type);
    }
    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(header);
    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)");
    		  added=input.next();
    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
    		  added=input.next();
                            ^
    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.


    PLEASE HELP ME. Thank you
    Last edited by jo112205; December 13th, 2011 at 05:28 AM.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need Help with this Java Calculator

    BigDecimal is a class in java.math package and you can not access it directly so you need to import it as,
    import java.math.BigDecimal;

Similar Threads

  1. Implementing order of operations for a Java calculator.
    By mjpam in forum Java Theory & Questions
    Replies: 2
    Last Post: May 15th, 2011, 06:11 PM
  2. Java certificate of deposit calculator project
    By jimbo357 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 17th, 2011, 02:18 AM
  3. Java Calculator Square Root Function
    By laser1992 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 3rd, 2011, 09:34 AM
  4. Java Calculator
    By helloworld922 in forum Algorithms & Recursion
    Replies: 7
    Last Post: January 10th, 2011, 06:01 AM
  5. Calculator
    By javapenguin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2010, 09:00 AM