-1

so I'm running a program in java and I can't really find the main error this is my code:

public class Main

{
    public static void main(String[] args) {
        double myCheck = 50.00;
        double yourCheck = 19.95;
        double fiinalRATE = 0.15;
        System.out.println("Tips are");
        calcTip(myCheck);
        calcTip(yourCheck);
        public void calcTip(double bill);
        {
        tip = bill * fiinalRATE;
        System.out.println("The tip should be at least " + tip);
    }
}

and this is the error that I'm getting I think its the header but I don't really know what to put I'm kinda new at java though enter image description here

Percivalenss
  • 15
  • 1
  • 5

2 Answers2

1

You cannot declare a method inside another method. So the compiler gets crazy :) Just move you calcTip() function outside main() function (after closing curly bracket of main() or before declaration of main()).

public class Main
{
    public static void main(String[] args) {
        double myCheck = 50.00;
        double yourCheck = 19.95;
        double fiinalRATE = 0.15;
        System.out.println("Tips are");
        calcTip(myCheck);
        calcTip(yourCheck);
    }

    public static void calcTip(double bill) {
        // fiinalRate must be declared as parameter of calcTip()
        // or as static field in Main class,
        // otherwise the code doesn't compile.
        double tip = bill * fiinalRATE;
        System.out.println("The tip should be at least " + tip);
    }
}
Nimtar
  • 188
  • 2
  • 11
  • 2
    this doesn't compile since `fiinalRATE` is not known inside of `calcTip` – f1sh Jan 21 '21 at 15:51
  • @f1sh you're right, as well as Gal Fudim who suggested edition with 'static' key-word for caclTip(). I'll edit – Nimtar Jan 22 '21 at 09:28
1

You can't declare function inside function. You have to pull function out from main() to the Main.class