• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method to the madness  RSS feed

 
James Wolf
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I've been doing some community courses in Java we're about three weeks in and I'm struggling a bit with the material. Our assignment is to create a program that lets the user input two fractions (whole number and num/denom) then adds them together producing a proper fraction. I've gotten to this point where it will return the two fractions and even parses them but now I need to cap it off by writing a method that will add the two fractions together. I know how to do it using a simple System.out.print(MATH HERE) followed by a few if/else statements to handle special cases but one of the assignment learning points is to write a method that will do that and just to refer to it in the main. My problem is I have no clue how to start calling in the individual numbers.

If you can shove me, kick me, push me down a flight of stairs in the right direction I'd appreciate it. I'm very new and this code will probably look like cat puke to most of you pros.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I understand you're a beginner, I have some remarks about your code, I hope these will help you.

First of all, it's not complete; your class Mix_JW extends class Fraction_JW, but you didn't show us that class. The method displayMix() refers to variables 'first' and 'second' that aren't defined anywhere. Are they in the superclass Fraction_JW? Looking at how you use them in your displayMix() method, I guess that those variables are of type int. But in your main() method, at the bottom, you're calling: second.display2(). That does not work when 'second' is an int, because you cannot call methods on primitive type like int (and int certainly does not have a method called 'display2()').

Your code would become much more readable if you indent it properly and leave an empty line between parts of the code.

Why do you have methods get() and get2() which seem to be exactly the same?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code would also be much easier to understand if you change the names of your variables. iBot and sBot are quite confusing.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!