Fraction Calculator app

public class Calculator 
{
    public static void main(String[] args)
    {
        String choice = "";
        String userFract = "0";
        String userFract2 = "0";
        Scanner scan = new Scanner(System.in);
        String fract = "0";
        int clearCounter = 0;

        String add = "a"; String multiply = "m";
        String subtract = "s"; String divide = "d";
        String reciprocal = "r"; String clear = "c";
        String reverse = "n"; String proper = "p";
        String improper = "i"; String quit = "q";



        while(!choice.equals("q"))
        {
            if(clearCounter == 0)
            {
                System.out.print("Enter a fraction: ");
                userFract = scan.nextLine();

               clearCounter++;
            }

            NewFraction currentFract = NewFraction.parseNewFraction(userFract);
            fract = currentFract.toString();
            System.out.println(fract);

            System.out.println("add:         a,  clear:            c");
            System.out.println("subtract:    s,  reverse sign:     n");
            System.out.println("multiply:    m,  proper display:   p");
            System.out.println("divide:      d,  improper display: i");
            System.out.println("reciprocal:  r,  quit:             q");
            System.out.print("-->");
            choice = scan.nextLine();
            System.out.println("");

            if(choice.equals(add))
            {
                System.out.print("Enter another fraction: ");
                userFract2 = scan.nextLine();
                NewFraction newFract = NewFraction.parseNewFraction(userFract2);

               NewFraction Fract = currentFract.Add(newFract);
               System.out.println(Fract.Proper());
            }

            if(choice.equals(clear))
            {
                clearCounter--;
            }

          }


    }
}

I am working on a program for a fraction calculator, and like my NewFraction file works properly but I am having trouble wit the calculator file.so my file compiles and executes but the output is weird. It displaces the right answer and on the next line, it also displays the original fraction? Idk what to do.. HELP!

Answers


You need to replace this line

System.out.println(Fract.Proper());

with

currentFract = Fract;

The fraction Fract will be printed out at the start of the next iteration of the loop.


Need Your Help

Eclipse no intellisense for Android Development for Layouts

android eclipse

I am getting started with Android Development and having trouble to get the suggestion box/intellisense to work in XML layouts.

WebRTC between two endpoints in the same browser page?

websocket webrtc

Is it technically possible to create a WebRTC connection for transferring JSON between two WebRTC endpoints spawned in the same script on the same page in the same browser?