a java program to ask user input of two fraction numbers andoperators (+, - , *
ID: 3619207 • Letter: A
Question
a java program to ask user input of two fraction numbers andoperators (+, - , * , / ) , that uses loop to run program untilluser wants to continue it again by answering 1 for yes and 2 forno. ( make sure output results is a reduced fraction number)Explanation / Answer
x.P5lor="red">please rate - thanks reducing negative fractions was getting a little "hairy" and I didn't know how complete you wanted that--I do have improper fractions changing to mixed numbers, so get back to me if there is anything you want change import java.util.*; public class fractions { public static void main(String[] args) {Scanner in=new Scanner(System.in); int num1,num2,den1,den2,more,num3=0,den3=0,factor,n=0; boolean goodop; String operation; char op=' '; do {System.out.println("For the first fraction:"); System.out.print("Enter the numerator:"); num1=in.nextInt(); System.out.print("Enter the denominator:"); den1=in.nextInt(); System.out.println("For the second fraction:"); System.out.print("Enter the numerator:"); num2=in.nextInt(); System.out.print("Enter the denominator:"); den2=in.nextInt(); in.nextLine(); //clear buffer of enter goodop=false; while(!goodop) {System.out.println("Enter the operation to perform"); System.out.println("+ addition"); System.out.println("- addition"); System.out.println("* addition"); System.out.println("/ addition"); operation=in.nextLine(); op=operation.charAt(0); switch(op) {case '+':num3=num1*den2+num2*den1; den3=den1*den2; goodop=true; break; case '-':num3=num1*den2-num2*den1; den3=den1*den2; goodop=true; break; case '*':num3=num1*num2; den3=den1*den2; goodop=true; break; case '/':num3=num1*den2; den3=den1*num2; goodop=true; break; default: System.out.println("Invalid Entry"); } } factor=reduce(num3,den3); num3/=factor; den3/=factor; if(num3Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.