Where am I going wrong? :)
I'm trying to figure out this whole java thing... maybe I should gone into agriculture.. :-)
Code :
public class TipCalculator
{
public static void main(String[] args)
{
double myCheck = 50.00;
double yourCheck = 19.95;
double RATE = 0.15;
double bill = 50;
System.out.println("Tips are" );
calcTip(myCheck);
calcTip(yourCheck);
}
public double calcTip(double bill, double RATE)
{
double tip;
tip = bill * RATE;
System.out.println("The tip should be at least " + tip);
}
}
Getting error codes on the two calcTip calls?
Re: Where am I going wrong? :)
Re: Where am I going wrong? :)
Still throwing errors? :(
Code :
calcTip(myCheck,RATE);
calcTip(yourCheck,RATE);
Re: Where am I going wrong? :)
add return tip; to your function
Re: Where am I going wrong? :)
I fixed some of the problems; still getting some errors:
Code :
public class DebugThree1
{
public static void main(String[] args)
{
double myCheck = 50.00;
double yourCheck = 19.95;
double RATE = 0.15;
final double bill = 50;
System.out.println("Tips are" );
calcTip(myCheck,RATE);
calcTip(yourCheck,RATE);
}
public static double calcTip(double bill, double RATE)
{
double tip;
tip = bill * RATE;
System.out.println("The tip should be at least " + tip);
}
}
Gettoing error on second method, saying I have no return statement.. but it's right there?
Re: Where am I going wrong? :)
change the System.out.println("The tip should be at least " + tip); to return tip;. Then print out the returned value in your main method.
Re: Where am I going wrong? :)
or make it a void method instead of double
public static void calcTip(double bill, double RATE)
Re: Where am I going wrong? :)
technically, yes that would work. However, that's bad programming practice. The reason is any calling method has no way to access that value. Not to say all side effects are bad, in fact it's quite necessary sometimes. However, in this case it's much better to return the value.
Re: Where am I going wrong? :)
another knowledge here... so declaring a method void is NOT NECESSARY AT ALL TIMES..(but sometimes it is). hmmm
the hardest part of that is what am i going to return? if i dont know what to return?..
i remember what chris told me about :))
Re: Where am I going wrong? :)
Code :
public static double calcTip(double bill, double RATE)
{
double tip;
tip = bill * RATE;
System.out.println("The tip should be at least " + tip);
return tip; // try to return the value of the tip
}
try to return the value of the tip because your method is calculating for the tip right?
and you need its value.. (unless you will make another method that will return the tip) something like
getCalculatedTip() method. that wil lreturn the value of the tip...
so after calculating all the bills and rate.. and assigining it to the tip,then
return the value of the tip
i agree with them.. in this case you must declare a return value for the method calcTip..
if you make that void.. that will be limitted in use(almost not usefull) because you are just calculating the tip..
you have to get the value of the tip right? so you have to return it...