Hi, my names Robert and I'm an introductory Java student.
I have an assignment where the program receives an array of integers, runs them all through a formula, and then displays the results of each instance of the formula in a table. For the moment, I'm just trying to get the actual equation working, I can focus on the table once that's done. After a few attempts with no success, I decided to try running the program with a method. It looks like it will work but theres an error where the IF statement begins, telling me it cannot call a non-static method cannot be referenced from a static context. And that makes sense, I just don't know what I should do to fix it. Here's the code:
import java.util.Scanner;
public class Salary {
public int aSalary(int salary) {
if (salary <= 0){
return 0;
} else {
salary = (sales * 0.09) + 200;
}
}
public static void main(String[] args) {
Scanner input = new Scanner ( System.in );
System.out.print( "Please enter the amount of items sold by the employees:");
String sales = input.nextLine();
String salesArray[] = sales.split(" ");
for(int i=0; i<salesArray.length; i++){
System.out.print(salesArray[i] + " ");
if(aSalary(Integer.parseInt(salesArray[i…
System.out.println("is even");
else
System.out.println("not even");
}
}
}
I would greatly appreciate any help or advice. Thank you