# Thread: Mixed Fraction

1. Member
Join Date
Jan 2010
Posts
2
Rep Power
0

## Mixed Fraction

Not working

help me please :(

import java.util.Scanner;

public class FractionTester {

public static void main(String[] args) {
MixedFraction operand1, operand2;

operand1 = enterFractionValue("fraction 1: ");
operand2 = enterFractionValue("fraction 2: ");

// place code below

}

private static MixedFraction enterFractionValue(String operand) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Form of " + operand);
System.out.println(" (a) Fraction: whole value");
System.out.println(" (b) Fraction: with numerator and denominator");
System.out.println(" (c) Mixed Fraction");
char choice;
do {
System.out.println("Enter choice: ");
choice = Character.toLowerCase(keyboard.nextLine().charAt(0 ));
} while (choice != 'a' && choice != 'b' && choice != 'c');
System.out.println();

MixedFraction f;
switch(choice){
case 'a':
System.out.print("Enter the whole value: ");
int whole = keyboard.nextInt();
f = new MixedFraction(whole,0,1);
break;
case 'b':
f = new MixedFraction(0,inputRegularFraction(keyboard));
break;
default:
int w;
do {
System.out.print("Enter whole part: ");
w = Integer.parseInt(keyboard.nextLine());
} while (w == 0);
f = inputRegularFraction(keyboard);
return new MixedFraction(w,f);
}
return f;
}

private static Fraction inputRegularFraction(Scanner kb){
System.out.print("Enter numerator: ");
int n = Integer.parseInt(kb.nextLine());
int d;
do {
System.out.println("Enter denominator: ");
d = Integer.parseInt(kb.nextLine());
} while (d == 0);
return new Fraction(n,d);
}

}

2. Senior Member
Join Date
Aug 2009
Posts
2,388
Rep Power
7
Don't double post, use code tags to post code and explain your problem fully. "Not working" is just being too lazy for someone looking for free help.

3. Agree, "not working" tells us zilch about what is not working here.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•