[JAVA] Can't compile code, don't know how to fix error
Go to solution
Solved by madknight3,
Thanks man, but how did you fix them up. As you can probably tell by my not so helpful posts, this isn't actually something I created myself. My skills are web dev based. So how did you fix them?
I'm not sure if this is what was intended, but here's how I'd change it so it makes sense to me. The only changes are at the bottom of the method and I made comments about them. Note this still assumes you use JDK 7+ for issue #2 I mentioned. If you don't have it, you'll have to install and use it.
private static String produceAnswer(String input) { // parse input String t[] = input.split(" "); if (t.length != 3) return "Check format!"; MixedFraction a = parseFraction(t[0]); a.check(); String operator = t[1]; MixedFraction b = parseFraction(t[2]); b.check(); MixedFraction result; //addition switch(operator) { case "+": result = a.add(b); break; case "-": result = a.subtract(b); break; case "*": result = a.multiply(b); break; case "/": result = a.divide(b); break; default: //return a + " " + operator + " " + b + " = " + result; return "Invalid operation"; // I don't know what this was supposed to do so I changed it } return result.toString(); // Returned a result here }

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now