I seem to have done something wrong, but I can't figure out with it is. Everytime I compile I get the error "reached end of file while parsing". Can anyone help me find where this error is?

public class ElectricBill
{


private double k;
private boolean s;


public ElectricBill(double pKwh, boolean pSummer)
{
k = pKwh;
s = pSummer;
}


public double getUsage()
{
return k;
}


public boolean isSummerRate()
{
return s;
}


private double calcSummerCost()
{
double sumCost = 5 + 0.0825*k + 0.0169*k;
return sumCost;
}


private double calcWinterCost()
{
if ( k <= 400)
{
return 5 + 0.0760*k + 0.0169*k;
}
if ( (k >400) && (k < 1000))
{
return 5 + 0.0760*400 + 0.0637*(k-400) + 0.0169*k;
}
if ( k > 1000)
{
return 5 + 0.0760*400 + 0.0637*(400+600) + 0.0604*(k-(400+600)) + 0.0169*k;
}
}


public double getTotal()
{
if (s)
{
return calcSummerCost();
{
if (!s)
{
return calcWinterCost();
}
}
}

since you are not using code tags, it's hard to see, but i will just guess and say you haven't closed your brackets properly.

When properly formatted

public double getTotal()
  {
    if (s)
    {
      return calcSummerCost();
      {
        if (!s)
        {
          return calcWinterCost();
        }
      }
    }

Do you see your problem?

I have the feeling that you used the wrong brace after return calcSummerCost();

public double getTotal()
{
if (s)
{
return calcSummerCost();
{
if (!s)
{
return calcWinterCost();
}
}
}

Problem is Over Here :) ..

public double getTotal()
{
if (s)
{
return calcSummerCost();
{
if (!s)
{
return calcWinterCost();
}
}
}

in End 2 Closing Braces } are missing dude ..

@umairsario : Do you think you have added any thing in your post apart from whats already mentioned ? I appreciate you are trying to help someone but if you care to look at the post of masijade, he exactly mentions the same thing. You, actually degrade the value of the solution by not writing it in code tags, and making it even more confusing to understand. masijade had hinted towards the solution using code tags.

EDIT : Not to mention that sillyboy already mentions the disadvantage of posting without code tags.

Aside from the fact that he is wrong. ;-)

Doing that will lead to an "unreachable code" error, as well as a "missing return statement" error, because both return statements are inside the original if, and the first line of that if block is a return statement, which would make the rest of it unreachable, and if the "if" is false, there would be no return. As I said, simply change the { after return calcSummerCost(); to a }.

P.S. you can also change "if (!s)" to "else" if you wish, or simply delete that statement and the { and } after it (although not the contents between them), as well (in addition to the afore mentioned brace change, of course).

there's been a few of these threads recently, and the originator hasn't even replied... there is seriously no need to repeat solutions and bump an old thread (which I realise I am doing right now :p)

@masijade : Actually I didn't even take an evaluative look at his code and just assumed that he was saying the same thing what you did.

Sorry if you thought I was aiming at you. I wasn't. ;-)

@masijade : No don't feel so, not at all, Actually since you said he was wrong altogether, I mentioned the thing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.