Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Mixed Fraction JAVA

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Mixed Fraction JAVA

    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);
        }
     
    }
    Last edited by Json; January 19th, 2010 at 09:34 AM. Reason: Please use code tags.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Mixed Fraction JAVA

    Rather than spamming the same terrible post across many forums on the web, why don't you write a nice neat post and try again, and actually ask us a question

Tags for this Thread