Results 1 to 3 of 3

Thread: Mixed Fraction

  1. #1
    x3iancute is offline Member
    Join Date
    Jan 2010
    Posts
    2
    Rep Power
    0

    Default 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. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    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. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

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

Similar Threads

  1. Mixed Fraction JAVA
    By x3iancute in forum JCreator
    Replies: 0
    Last Post: 01-19-2010, 02:39 PM
  2. swing mixed with awt graphics
    By weddy69 in forum AWT / Swing
    Replies: 2
    Last Post: 08-31-2009, 08:01 AM
  3. Need help on Fraction
    By mitch25 in forum New To Java
    Replies: 2
    Last Post: 07-24-2009, 09:46 PM
  4. Mixed language project?
    By toadaly in forum NetBeans
    Replies: 5
    Last Post: 03-11-2009, 06:29 AM
  5. Big Fraction 1.00
    By JavaBean in forum Java Software
    Replies: 1
    Last Post: 03-26-2008, 04:24 AM

Posting Permissions

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