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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Whenever I input fractions I just get back my own error message, (the error message I send as System.err.println("There was an error in your input, try again."); ) or nothing at all. I think it might be a problem with my output code but I'm not sure. I'm not having a program crash error message or system error message. The error message I'm talking about is the one I have set up in case someone does something stupid like 2/3 ++ 1/3.
    import java.util.*;
    public class Fractioncalculator {
    	public static void main(String[] args){
    		boolean quit = false;							//boolean for recognition of quit command
    		boolean error = false;
    		String inputstr = null;
    		Scanner sc = new Scanner(System.in);
     
    		//Loop for input of problem and output of solution
     
    	while(quit==false){
    		int iterator = 31;						//iterator for reduction of end result
    		int first_whole_int = 0;				//first whole integer
    		int firstnum = 0;						//first numerator
    		int firstdenom = 0;						//first denominator
    		int second_whole_int = 0;				//second whole integer
    		int secondnum = 0;						//second numerator
    		int seconddenom = 0;					//second denominator
    		char operator;							//operator storage
    		int cmndenom = 0;						//common denominator
    		int finalint = 0;						//final integer
    		int finalnum = 0;						//final numerator
    		int finaldenom = 0;						//final denominator
    		//Request for input
     
    		System.out.println("Please enter your fractions: ");
    		inputstr = sc.nextLine();
    		if(inputstr.equals("quit")){											//check if quit received
    			quit = true;
    		}
    		StringTokenizer errorst = new StringTokenizer(inputstr, " ");
    		if(errorst.countTokens()!=3){
    			error = true;
    		}
    		else {
    			StringTokenizer st1 = new StringTokenizer(inputstr, " ");			//Tokenize by spaces (First Section, Operator, Second Section)
    			//
    			//Section One
    			//
    			String first = st1.nextToken();
    			boolean indwhole = first.contains("/");								//boolean for checking if section one contains a fraction
    			if(indwhole==false){												//parses first whole number if above is false
    				first_whole_int = Integer.parseInt(first);
    			}
    			boolean indmixed = first.contains("_");								//boolean for checking is section one is a mixed number
    			if(indmixed==true){													//if above is true, execute parsing of first whole integer, 
    				StringTokenizer st1_sub1 = new StringTokenizer(first, "_");		//first numerator and first denominator.
    				String first_whole = st1_sub1.nextToken();
    				first_whole_int = Integer.parseInt(first_whole);
     
    				String firstfractionstr = st1_sub1.nextToken();
    				StringTokenizer st1_sub2 = new StringTokenizer(firstfractionstr, "/");
    				firstnum = Integer.parseInt(st1_sub2.nextToken());
    				firstdenom = Integer.parseInt(st1_sub2.nextToken());	
    			}
     
    			if(indwhole==true&&indmixed==false){								//if section one is just a fraction, parse numerator and denominator
     
    				StringTokenizer st1_sub2 = new StringTokenizer(first, "/ ");
    				firstnum = Integer.parseInt(st1_sub2.nextToken());
    				firstdenom = Integer.parseInt(st1_sub2.nextToken());
     
     
    			}
    			//
    			//operator
    			//
    			String op = st1.nextToken();
    			operator = op.charAt(0);
    			//
    			//Second section
    			//
    			String second = st1.nextToken();
    			boolean indwhole2 = second.contains("/");							//boolean for checking if section two contains a fraction
    			if(indwhole2==false){												//parses first whole number if above is false
    				second_whole_int = Integer.parseInt(second);
    			}
     
    			boolean indmixed2 = second.contains("_");							//boolean for checking is section two is a mixed number
    			if(indmixed2==true){												//if above is true, execute parsing of second whole integer,
    				StringTokenizer st2_sub1 = new StringTokenizer(second, "_");	//second numerator and second denominator.
    				String second_whole = st2_sub1.nextToken();
    				second_whole_int = Integer.parseInt(second_whole);
     
    				String secondfractionstr = st2_sub1.nextToken();
    				StringTokenizer st2_sub2 = new StringTokenizer(secondfractionstr, "/");
    				secondnum = Integer.parseInt(st2_sub2.nextToken());
    				seconddenom = Integer.parseInt(st2_sub2.nextToken());	
    			}
    			if(indwhole2==true&&indmixed2==false){								//if section one is just a fraction, parse numerator and denominator
     
    				StringTokenizer st2_sub2 = new StringTokenizer(second, "/ ");
    				secondnum = Integer.parseInt(st2_sub2.nextToken());
    				seconddenom = Integer.parseInt(st2_sub2.nextToken());
     
     
    			}
     
     
    			if(operator == '+'){												//function execution for if operator is addition
     
    				if(firstdenom!=0 && seconddenom!=0){
    					cmndenom = firstdenom * seconddenom;
    				}
    				if(firstdenom!=0 && seconddenom==0){
    					cmndenom = firstdenom;
    				}
    				if(firstdenom==0 && seconddenom!=0){
    					cmndenom=seconddenom;
    				}
     
    				finalint = first_whole_int + second_whole_int;
     
    				if(firstnum!=0 && secondnum!=0){
    					finalnum = firstnum*seconddenom + secondnum*firstdenom;
    				}
    				if(firstnum==0 && secondnum!=0){
    					finalnum=secondnum;
    				}
    				if(firstnum!=0 && secondnum==0){
    					finalnum=firstnum;
    				}
    			}
    			if(operator == '-'){
    			finalint = first_whole_int - second_whole_int;
    				if(firstdenom!=0 && seconddenom!=0){
    					cmndenom = firstdenom * seconddenom;
    				}
    				if(firstdenom!=0 && seconddenom==0){
    					cmndenom = firstdenom;
    				}
    				if(firstdenom==0 && seconddenom!=0){
    					cmndenom=seconddenom;
    				}
    				if(firstnum!=0 && secondnum!=0){
    					finalnum = firstnum*seconddenom - secondnum*firstdenom;
    				}
    				if(firstnum==0 && secondnum!=0){
    					finalnum=secondnum;
    				}
    				if(firstnum!=0 && secondnum==0){
    					finalnum=firstnum;
    				}
    			}
    			if(operator == '/'){
    				if(first_whole_int!=0 && firstdenom!=0){
    					firstnum=first_whole_int*firstdenom + firstnum;
    				}
    				if(first_whole_int!=0 && firstdenom==0){
    					firstnum=first_whole_int;
    					firstdenom=1;
    				}
    				if(second_whole_int!=0 && seconddenom!=0){
    					secondnum=second_whole_int*seconddenom + secondnum;
    				}
    				if(second_whole_int!=0 && seconddenom==0){
    					secondnum=second_whole_int;
    					seconddenom=1;
    				}
    				finalnum=firstnum*seconddenom;
    				cmndenom=firstdenom*secondnum;
     
    			}
    			if(operator=='*'){												//function execution for if operator is multiplication
    				if(firstdenom==0){
    					firstnum=first_whole_int;
    					firstdenom=1;
    				}
    				if(firstdenom!=0 && first_whole_int!=0){
    					firstnum=first_whole_int*firstdenom + firstnum;
    				}
    				if(seconddenom==0){
    					secondnum=second_whole_int;
    					seconddenom=1;
    				}
    				if(seconddenom!=0 && second_whole_int!=0){
    					secondnum=second_whole_int*seconddenom + secondnum;
    				}
    				finalnum=firstnum*secondnum;
    				cmndenom=firstdenom*seconddenom;
    			}
    		finaldenom = cmndenom;		//nuance of code, ignore
    			while(iterator>1){												//reduction of fraction through common dividend
    					if(finalnum%iterator==0 && finaldenom%iterator==0){
    						finalnum = finalnum / iterator;
    						finaldenom = finaldenom / iterator;
    						iterator--;	
    					}
    				else{
    					iterator--;
    				}
    			}
    		while(finalnum>finaldenom){											//reduction of fraction to mixed number
    			finalnum = finalnum - finaldenom;
    			finalint++;
    			}
     
     
    		//Output
    		//Prints are self-explanatory through blue text, and are only executed if they are possible
    		//Outputs do not print if an error has occurred
    		if(error=false){
    			if(finalint!=0 && finaldenom!=1 && finaldenom!=0 && finalint>0){
    				System.out.println("Mixed number form: " + finalint + "_" + finalnum + "/" + finaldenom);
    			}
    			if(finaldenom==0 && finalnum==0 && finalint!=0){
    				System.out.println("Final Number: " + finalint);
    			}
    				finalnum = finalnum + (finalint*finaldenom);
    				if(finaldenom!=1 && finaldenom!=0){
    				System.out.println("Fraction form: " + finalnum + "/" + finaldenom);
    				}
    				if(finaldenom==1){
    					System.out.println("Final Number: " + finalnum);
    				}
    			}
    			else {
    				System.err.println("There was an error in your input, try again.");
    			}
    		System.out.println();
    			}
    			if(quit==true){
    				System.out.println("Program has exited.");
    			}
    		}
    	}
    }
    Last edited by DUE IN 4 HOURS; November 3rd, 2011 at 06:13 AM. Reason: To clarify what the error is in response to posts.


  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: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    DUE IN 4 HOURS,

    As i am guessing from your name your assignment is due in soon. Now, i'm also going to assume you have probably cross-posted this on many forums in the hope of getting a response. Also, I am going to assume that you have skipped reading the forum rules,

    Announcements - What's Wrong With My Code?

    Perhaps if you give those a read, and then take the time to provide error messages, an indication of where the code is crashing etc etc we will be able to provide help.

    Regards,
    Chris

  3. The Following User Says Thank You to Freaky Chris For This Useful Post:

    KevinWorkman (November 3rd, 2011)

  4. #3
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    REMOVED DUE TO INCORRECT AND STUPID ADVICE BY ME LOL
    Last edited by macko; November 3rd, 2011 at 07:28 AM. Reason: Wrong Advice

  5. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    if(finalint!=0 && finaldenom!=1 && finaldenom!=0 && finalint>0)
     
    why are you saying if finalint is NOT 0 AND finalint is greater then 0.. its the same thing unless it goes negative. Try removing one.

    yeah, i don't think repetition is causing a problem but i tried deleting it anyway and it didn't fix the problem.

  6. #5
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    take a look at this demo ive just done on console reading / writing:

    public demo() throws Exception{
    		// GET FIRST NUMBER
    		Scanner sc = new Scanner(System.in);
    		System.out.println("Please enter your first fraction: ");
    		String inputstr = sc.nextLine();
     
    		// TESTING IF INPUT ENTERED IS 444
    		if(inputstr.equals("444")){
    			System.out.println("Works!");
    		}
     
    		// GET SECOND VALUE
    		System.out.println("Please enter your second fraction: ");
    		String second = sc.nextLine();
    	}

    Now i've had a play around with your code, It seems that your not parsing the data that the user is giving u into a variable.

    try creating 3 different number variables..

    when your scanning the console.. make sure that you put
    VARIABLE = sc.readLine();

    Because as ive said.. the problem looks like the 3 end int values your trying to process are always staying as 0...

    You may also ask for a OPERATOR after every number they have entered... and get that.

  7. #6
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Correct me if im wrong but.. is this not what you're trying to do only simplified?

    	public demo() throws Exception{
    		// CREATE SCANNER
    		Scanner sc = new Scanner(System.in);
     
    		// GET FIRST NUMBER
    		System.out.println("Please enter your first number: ");
    		int first = Integer.parseInt(sc.nextLine());
     
    		// GET FIRST OPERATOR
    		System.out.println("Please enter your first operator: ");
    		String fOP = sc.nextLine();
     
    		// GET SECOND NUMBER
    		System.out.println("Please enter your second number: ");
    		int second = Integer.parseInt(sc.nextLine());
     
    		// GET SECOND OPERATOR
    		System.out.println("Please enter your second operator: ");
    		String sOP = sc.nextLine();
     
    		// GET THIRD NUMBER
    		System.out.println("Please enter your third number: ");
    		int third = Integer.parseInt(sc.nextLine());
     
     
    		System.out.println("The total value =  ");
    	}

    Only thing left for you to do there is to convert the operators so that they can read.. and put the numbers together with the specified operators entered.. Gutta leave something for you to do lol

  8. #7
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by macko View Post
    Correct me if im wrong but.. is this not what you're trying to do only simplified?

    	public demo() throws Exception{
    		// CREATE SCANNER
    		Scanner sc = new Scanner(System.in);
     
    		// GET FIRST NUMBER
    		System.out.println("Please enter your first number: ");
    		int first = Integer.parseInt(sc.nextLine());
     
    		// GET FIRST OPERATOR
    		System.out.println("Please enter your first operator: ");
    		String fOP = sc.nextLine();
     
    		// GET SECOND NUMBER
    		System.out.println("Please enter your second number: ");
    		int second = Integer.parseInt(sc.nextLine());
     
    		// GET SECOND OPERATOR
    		System.out.println("Please enter your second operator: ");
    		String sOP = sc.nextLine();
     
    		// GET THIRD NUMBER
    		System.out.println("Please enter your third number: ");
    		int third = Integer.parseInt(sc.nextLine());
     
     
    		System.out.println("The total value =  ");
    	}

    Only thing left for you to do there is to convert the operators so that they can read.. and put the numbers together with the specified operators entered.. Gutta leave something for you to do lol
    no this is a fraction calculator 2/3 + 1/3 + 1_2/3 not an integer calculator 1 + 2 + 3

  9. #8
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    simply change the value of first, second and third to String or w.e ur wanting lol I've clearly said that this is for demo only.

    As i've said tho try actualy sending the values from the console to a variable.. might help.

    I'm not here to complete your homework, I'm simply here to point you in the correct direction... remember that.

  10. #9
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by macko View Post
    take a look at this demo ive just done on console reading / writing:

    public demo() throws Exception{
    		// GET FIRST NUMBER
    		Scanner sc = new Scanner(System.in);
    		System.out.println("Please enter your first fraction: ");
    		String inputstr = sc.nextLine();
     
    		// TESTING IF INPUT ENTERED IS 444
    		if(inputstr.equals("444")){
    			System.out.println("Works!");
    		}
     
    		// GET SECOND VALUE
    		System.out.println("Please enter your second fraction: ");
    		String second = sc.nextLine();
    	}

    Now i've had a play around with your code, It seems that your not parsing the data that the user is giving u into a variable.

    try creating 3 different number variables..

    when your scanning the console.. make sure that you put
    VARIABLE = sc.readLine();

    Because as ive said.. the problem looks like the 3 end int values your trying to process are always staying as 0...

    You may also ask for a OPERATOR after every number they have entered... and get that.
    I don't think I understand what you are saying. If you could make the changes to my code and post your response that way it would be really helpful to me.

  11. #10
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by DUE IN 4 HOURS View Post
    I don't think I understand what you are saying. If you could make the changes to my code and post your response that way it would be really helpful to me.
    Sorry, As i have said:

    Quote Originally Posted by macko View Post
    I'm not here to complete your homework, I'm simply here to point you in the correct direction... remember that.
    You need to actually learn yourself rather then me simply giving the code to you, What will you do once you've finished java? so please follow mine and others guides that we display to you and learn the appropriate skills.

    As i've said:

    You're problem is:
    You are not parsing the entered data into a variable.. A variable that you are trying to calculate that is.. So hence the values of the 3 end variables are null..

    Please try doing a
    System.out.println(VARIABLE NAME);

    under your custom error message.. You will then see the values of the 2 variables are null..
    Last edited by macko; November 3rd, 2011 at 07:22 AM.

  12. #11
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    I think I've already done what your saying I should do.
    int firstnum = 0; //first numerator
    firstnum = Integer.parseInt(st1_sub2.nextToken());

  13. #12
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by macko View Post
    Why are you using?
    inputstr = sc.nextLine();
    It just looks like you trying to scan a line that isnt there... How can it scan the line if the user has not made input?

    I would use:
    String demo = System.console().readLine();
     
    OR
     
    String demo = System.console().reader().read();

    Which ever one works lol.. been awhile since ive made console based programs, If im helpful please remember to thank me =/ even though you should be doing your assignment yourself.
    O_oinvisiblefiller
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  14. The Following User Says Thank You to newbie For This Useful Post:

    KevinWorkman (November 3rd, 2011)

  15. #13
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    try saying

    int firstnum;
    int secondnum;
    int thirdnum;

    and then simply under your custom error message type
    System.out.println(firstnum + " " + secondnum + " " + thirdnum);

    You will then see what the values of those numbers are on the console.. if the output posts null that means that i was correct and that you need to listen to my previous advice....

  16. #14
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by newbie View Post
    O_oinvisiblefiller
    Forget my crappy first comment, Upon further reading i had discovered the real error obv.. as ive updated

  17. #15
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    int firstnum = 0; //first numerator
    firstnum = Integer.parseInt(st1_sub2.nextToken());
    this didn't do that?

  18. #16
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    True it's just that when you first declare firstnum = 0...

    its hard to do the debugging, Hence if you remove the = 0

    Then if the next line doesn't go through properly you can see that firstnum is equal to null...

    Otherwise it wills how 0 on the console and you wont know if it had calculated something or not unles you did further debugging.. so the easiest way is doin the above..

  19. #17
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    i added System.out.println(firstnum + " " + secondnum + " " + finalnum); to run after the error message and then input 2/3 + 1/3 which should produce an error because my calculator asks for 3 different numbers/fractions and System.out.println(firstnum + " " + secondnum + " " + finalnum); gave me 2 1 1

  20. #18
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    @DUE IN 4 HOURS: Better turn off the PC or laptop, go outside, have a walk for half an hour and come back with Fresh mind. I actually don't have the link to Kevin's blog, but this suggestion is taken from his blog. So, all credit goes to Kevin. Lol try it. you will solve it.

  21. #19
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    i removed the " = 0" from all my variables and i got this when i ran the program:
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable first_whole_int may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable second_whole_int may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstnum may not have been initialized
    The local variable secondnum may not have been initialized
    The local variable firstdenom may not have been initialized
    The local variable seconddenom may not have been initialized
    The local variable cmndenom may not have been initialized
    The local variable finalnum may not have been initialized
    The local variable finalnum may not have been initialized
    The local variable finalnum may not have been initialized
    The local variable finalnum may not have been initialized
    The local variable finalint may not have been initialized
    The local variable finalint may not have been initialized
    The local variable finalint may not have been initialized
    The local variable finalnum may not have been initialized
    The local variable finalnum may not have been initialized
    The local variable finalint may not have been initialized
    The local variable finalint may not have been initialized
    The local variable finalnum may not have been initialized
    The local variable finalint may not have been initialized

    at Fractioncalculator.main(Fractioncalculator.java:11 2)

  22. #20
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    There you go... you've got the debugging now.. work out how you would fix that..

    As ive said i will not help complete home work.. Now that you know what the outcome is doing.. try changing it and working out why that this is giving you that output.

    1 major step in java is the debugging, Maybe its reading the second value twice as you have not entered a third fraction, Try doing a third and seing if the anwser shows of the final..

    etc... work it out from there. take your code step by step.

    EDIT:
    There you go.. as i have been saying for the last 2000 posts lol.. You must initialize the variables.. dont just say = 0; as ull never know if your codes working or not.

    Remember before you start all your if statements you've got to write code to initialize all those values..

    and LOL @ Mr.777
    Last edited by macko; November 3rd, 2011 at 07:48 AM.

  23. #21
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by Mr.777 View Post
    @DUE IN 4 HOURS: Better turn off the PC or laptop, go outside, have a walk for half an hour and come back with Fresh mind. I actually don't have the link to Kevin's blog, but this suggestion is taken from his blog. So, all credit goes to Kevin. Lol try it. you will solve it.
    I wish, this is due in just under two hours and ive got a little more than an hour to work on it. i have no idea what the problem is i think i will have to skip class and get an excuse note somehow the other forums that i posted this on my username is: "imsof*cked"....

  24. #22
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Can you just read my posts and follow them O_O... nobody here will "give you the code" java can be frustrating at times, We all deal with it.

    If what you are doing is beginner java which it looks like it is due to the code.. You're code should really be under 50 lines long..


    Your if statements should be else if... and your code is just a mess mate.. as ive said 1000 times follow what ive said.. you'll find the awnser yourself and be proud that you learnt a new trick

  25. #23
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by Mr.777 View Post
    @DUE IN 4 HOURS: Better turn off the PC or laptop, go outside, have a walk for half an hour and come back with Fresh mind. I actually don't have the link to Kevin's blog, but this suggestion is taken from his blog. So, all credit goes to Kevin. Lol try it. you will solve it.
    Here it is: http://www.javaprogrammingforums.com...e-posting.html

    Although that's not really a blog, just an article I wrote containing some advice I was sick of repeating 10 times a day! :p
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  26. The Following User Says Thank You to KevinWorkman For This Useful Post:

    Mr.777 (November 3rd, 2011)

  27. #24
    Junior Member
    Join Date
    Nov 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    Quote Originally Posted by macko View Post
    There you go... you've got the debugging now.. work out how you would fix that..

    As ive said i will not help complete home work.. Now that you know what the outcome is doing.. try changing it and working out why that this is giving you that output.

    1 major step in java is the debugging, Maybe its reading the second value twice as you have not entered a third fraction, Try doing a third and seing if the anwser shows of the final..

    etc... work it out from there. take your code step by step.

    EDIT:
    There you go.. as i have been saying for the last 2000 posts lol.. You must initialize the variables.. dont just say = 0; as ull never know if your codes working or not.

    Remember before you start all your if statements you've got to write code to initialize all those values..

    and LOL @ Mr.777
    i know how to fix that "bug" you press ctrl z and reinitialize all the variables

  28. #25
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: FractionCalculator StringTokenizer with parsing DUE IN 4 HOURS

    OP, I highly suggest you stop mentioning your deadline. There are hundreds of posts here, each with its own urgent user waiting on a response, and your time is not more valuable than theirs, or ours for that matter. If you are facing a deadline, I assume your time would be better spent actually reading the responses you've received, trying things out, and following the advice in the article I posted, instead of making more posts complaining about your deadline. Chances are, you're going to have to chalk this one up to a lesson learned about time management.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Page 1 of 2 12 LastLast

Similar Threads

  1. Intparse error. I have been trying to fix for hours.
    By TBB3 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 16th, 2011, 01:38 PM
  2. StringTokenizer problem
    By daniel_wu in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 31st, 2010, 03:45 AM
  3. Hours worked help
    By glacier23 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 11th, 2010, 12:58 AM
  4. StringTokenizer error
    By mjpam in forum What's Wrong With My Code?
    Replies: 14
    Last Post: July 21st, 2010, 05:19 PM
  5. need in few hours help me
    By erinbasim in forum Java Theory & Questions
    Replies: 3
    Last Post: February 2nd, 2010, 06:39 PM