html - Java program for calculating fractions -


The purpose of the program is to obtain two parts of a user, to obtain an operator from the user, and then to obtain For the second part, two more user input programs should check that 0- 99 different numbers have been used in both fractions and it has zero zero separator. The program also has to ensure that the user uses a valid operator (-, +, *, /).

Now the only problem facing me is that none of my variables are being started and I do not know how the output looks like this:

  1 1 3 --- --- --- --- 8 8 8/8   

Even the code I have, any help would be greatly appreciated because Java I have little knowledge to use:

  import java.util.Scanner; Public class fracture calculator {public static wide main (string [] AGR) {scanner in = new scanner (system.); Int N1; Int N2; Int d1; Int D2; Int n; Int d; Four o; Int m1, m2; Integer tempN1, tempN2; Int LCM, X; System.out.println ("Enter a fraction for part 1:"); N1 = in.nextInt (); System.out.println ("Enter a lower for part 1:"); D1 = in.nextInt (); If (D1> 0) {System.out.println (); } else {System.out.println ("Invalid Flight"); System.exit (0); } System.out.println ("Enter an operator:"); O = in.next () ToCharArray () [0]; System.out.println ("Enter a fraction for part 2:"); N2 = in.nextInt (); System.out.println ("Enter a Bottom for Part 2:"); D2 = in.nextInt (); If (D2> 0) {System.out.println (); } Else {System.out.println ("Invalid Flight"); System.exit (0); } Switch (O) {case '*': n = n1 * n2; D = D1 * D2; break; Case '/': n = n1 * d2; D = N2 * D1; break; Cases '+': int max = n1 & gt; D1? N1: D1; Int min = n1 & lt; D1? n1: d1; For (int i = 1; i & lt; = min; i ++) x = max * i; If (x% min == 0) LCM = X; TempN1 = n1 * m1; TempN2 = n2 * m2; M1 = LCM / d1; M2 = LCM / d2; N = tempN1 + tempN2; D = LCM; break; Case '-': n = tempN1 - tempN2; D = LCM; break; Default: System.out.println ("Invalid operator:" + o); break; Perhaps you want to enter OOP (object oriented programming):    

  Q x = new Q (1, 4); QY = new Q (1, 8); Q Z = X. Plus (y); System.out.println ("% s +% s =% s% n", x, y, z); (1/4) + (1/8) = (3/8) Public square Q {Final integer fraction; In the last interval; Public quote (integer number, interval intent) {int g = gcd (fraction, divisor); This.numerator = numerator / g; This.denominator = tampering / g; } @ Override public string toasting () {return string.format ("(% d /% d)", fraction, divisor); } Public Q Plus (Q rhs) {New Q (partial * rhs.denominator + rhs.numerator * denominator, pseudo * rhs.denominator); }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -