Results 1 to 3 of 3
Thread: Mixed Fraction
- 01-19-2010, 02:40 PM #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);
}
}
- 01-19-2010, 02:58 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
-
Similar Threads
-
Mixed Fraction JAVA
By x3iancute in forum JCreatorReplies: 0Last Post: 01-19-2010, 02:39 PM -
swing mixed with awt graphics
By weddy69 in forum AWT / SwingReplies: 2Last Post: 08-31-2009, 08:01 AM -
Need help on Fraction
By mitch25 in forum New To JavaReplies: 2Last Post: 07-24-2009, 09:46 PM -
Mixed language project?
By toadaly in forum NetBeansReplies: 5Last Post: 03-11-2009, 06:29 AM -
Big Fraction 1.00
By JavaBean in forum Java SoftwareReplies: 1Last Post: 03-26-2008, 04:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks