Kruithne's Profile User Rating: -----

Reputation: 99 Whiz
Group:
Expert
Active Posts:
439 (0.25 per day)
Joined:
28-July 09
Profile Views:
3,171
Last Active:
User is offline Aug 29 2013 02:09 PM
Currently:
Offline

Previous Fields

Country:
GB
OS Preference:
Linux
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0
Expert In:
JavaScript

Latest Visitors

Icon   Kruithne is a million miles away from home.

Posts I've Made

  1. In Topic: Why does it say I need to return when I am?

    Posted 30 Jul 2013

    @jon - We shall have to agree to disagree on the latter!
  2. In Topic: Why does it say I need to return when I am?

    Posted 30 Jul 2013

    @jon.kiparsky: According to IntelliJ (the IDE I wrote that quick line up in), the line of code I pasted is below the code guideline for clean code, which I am sure follows the Java conventions as it does with everything else. Splitting it up like that for me makes it look a lot messier. As for storing it into a value and returning that, I would say that is not a good thing to do at all. Why store it? You can split it onto multiple lines whilst simply returning it.
  3. In Topic: Why does it say I need to return when I am?

    Posted 30 Jul 2013

    Following from what Verbose said, you could make it a ternary statement, which is generally more accepted in this case! Also, don't compress white-space, it makes things harder to read and makes no difference once it is all compiled.
    return (denominator == 1 || numerator == 0) ? String.valueOf(numerator) : numerator + "/" + denominator;
    
  4. In Topic: Why does it say I need to return when I am?

    Posted 30 Jul 2013

    Perhaps taking a look at some things already in the internet should give you an idea of how to go about setting up this class? Example: http://www.ecs.umass...onalNumber.java
  5. In Topic: Why does it say I need to return when I am?

    Posted 30 Jul 2013

    Hello there!

    First issue I can see is, you are not returning something from the function in all outcomes, if none of your statements are true, there is no fallback return! Two other pointers, firstly you don't need to add "" to the end of your number to make it a string, just use String.valueOf and secondly, you can condense two of your statements down into one, as you are returning the same thing from both! Take a look at the edited code below.
    public String toString() {
    	if (denominator == 1 || numerator == 0)
    		return String.valueOf(numerator);
    
    	if (numerator != 0 && denominator != 1)
    		return numerator + "/" + denominator;
    
    	return ""; // You need to return something here!
    }
    

My Information

Member Title:
D.I.C Regular
Age:
20 years old
Birthday:
December 13, 1993
Gender:
Location:
United Kingdom
Interests:
Programming, Systems Development, Web Design
Full Name:
Stanley Batch
Programming Languages:
HTML, CSS, JavaScript, jQuery, PHP, MySQL, ColdFusion, ASP.NET, Java, LUA, Node.JS

Contact Information

E-mail:
Click here to e-mail me
Twitter:
Kruithne

Friends

Comments

Kruithne has no profile comments yet. Why not say hello?