This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Tina Smith

Ranch Hand
+ Follow
since Jul 21, 2011
Tina likes ...
Eclipse IDE Firefox Browser Java
Cows and Likes
Cows
Total received
9
In last 30 days
0
Total given
0
Likes
Total received
37
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tina Smith

A quick google search on that error says that there is somewhere in that line/those lines where you are specifying the type (eg int) when it is not required. Like you had before you changed it back.

Obvious question: you did save the file, right?
3 years ago
But you changed it back to what it was before, right?

3 years ago
What is the exact text of the error message you're getting? (and the relevant lines of code)
3 years ago
You were creating the object correctly before. Put those lines back to the way they were. (but keep the variable declarations)
3 years ago
First case: Scroll to the bottom of this page for an example of switch with strings. http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

Second case: Not sure what you mean by initialized in the class package. Inside FractionsMain.java this is the first place I see those variables.
You cannot declare variables when calling a method. They have to be declared on a separate line and initialized to a meaningful value before they are used.
3 years ago
First case: you're comparing a string value with an int value. (input is typed as string, and the values in your switch are typed as ints) For all the compiler knows you could be comparing "hello" with 1. It has no idea how to convert "hello" to an int.
What you can do to get it working, assuming you are compiling in Java 7 or later, is to put your "1", "2" etc in quotes to force the compiler to compare strings to strings.

Second case: Where are variables a, b, c, and d declared and initialized?
3 years ago
The compiler is probably concerned that you are missing the default case.
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

You may want to add a println statement to your default case telling you what the value that was entered is. (because I guarantee it will be hit)

I recommend you do not use nextDouble() to read input from the keyboard for a character. The letter "a" is not a decimal (double) number such as 3.14. You should use a method that reads either a character or a string.

Oh, and "switch" is lowercase, and does not end with a ;
3 years ago
One of the most important things to learn when asking for help (especially on an online forum) is how to explain your problem. Just posting code and saying "this is what I have" doesn't help me, because I don't know what you need. My immediate reaction to that code is
1. "that's nice"
2. "you're missing the closing braces on your class"
3. "no code tags"

To make things easier for me (and also for you), clearly explain what you have, and how it is different from what you need in english (i.e. not code). If you have tried any solutions, state those too. This does two things.
1. It takes the guesswork out on my end.
2. It makes you think about your problem, and makes sure that you can explain what that problem is.

By the way I think your english is excellent.

My guess for your problem right now is that it prints out the options for what to do, prompts and accepts input for numerator and denominator. Then prompts for the operation, but pressing a, b, c, or d does nothing?
3 years ago
That would work. Does everything compile now?
3 years ago
We're just talking about toString right now. What does a fraction look like when you type it out?

When you know that, can you write a line of code that will concatenate a string to get the same answer?
3 years ago
Okay, and what do you want your output string to look like?
3 years ago
Sev,
Let's take a step back. Can you tell me (in english, not code) what your toString() method is supposed to return?
3 years ago
The second one. If you add in another getDenominator method you will have two methods with the same signature and the code won't compile (because it doesn't know which one to call).
And use this.getDenominator in your toString method, not your getDenominator method or you will get a stack overflow due to something called recursion (a method calling itself, which calls itself, which calls itself ... and so on).
3 years ago
To put this in different terms?


You can translate this line into two method calls.

See the problem?
3 years ago
I like to think I am experienced (been programming Java for about 5 years total although I have a lot to learn), and I have taken both the OCJA and the OCJP. I have both the OCJA and OCJP on Java 7 and I passed the OCJA 8 exam when it was in beta.

Being an 'experienced' Java programmer, I spent only a few hours studying for the OCJA, because I know and use most of the stuff on a daily basis. So there is a lot less time investment into studying than a person who has never seen Java before. It's also interesting to see what I get on the exam because it shows me what I don't know about programming, both during the exam ("I wonder if you can do that"), and after ("I got what wrong?"). Granted, a lot of the questions you get on a certification exam are different from everyday life (because you are totally going to put the main method in an enum on your company's flagship software), but they're great for showing you what you don't know about Java, and conversely, what you do.

Getting the piece of paper is also nice, although it means less because it's not something I had to work towards. If I were to switch jobs, that piece of paper may or may not be useful to me depending on who sees the credential. If I stay at the same job, my employer recognizes that I wrote the exam as continuous improvement, which gets me brownie points (and hopefully more $$).