Here is the code:
import java.io.*; class Change { double cost; double tax; double payment; public void setCost(double x) { cost = x; } public double getCost() { return cost; } public void setTax(double x) { tax = x; } public double getTax() { return (cost+tax); } public void setPayment(double x) { payment = x; } public double getPayment() { return (payment-tax); } public static void main (String [] args) throws Exception { BufferedReader object = new BufferedReader (new InputStreamReader (System.in)); Change change = new Change(); System.out.println("Welcome to the Supermarket!"); System.out.println(""); System.out.println("How much is the total cost?"); System.out.println("Input here: "); cost = Double.parseDouble (object.readLine()); change.setCost(cost); System.out.println(""); System.out.println("The cost is: "+change.getCost()); System.out.println(""); tax = cost * 0.06; System.out.println(""); System.out.println("The tax is: "+tax); change.setTax(tax); System.out.println("The total cost is: "+change.getTax()); System.out.println(""); System.out.println("How much will you pay?"); System.out.print("Input here:"); payment = Double.parseDouble(object.readLine()); System.out.println(""); change.setPayment(payment); System.out.println("Your change is "+change.getPayment()); System.out.println(""); System.out.println("Have a nice day!"); } }
But it has 8 errors of the same origin:
Main.java:43: non-static variable cost cannot be referenced from a static context cost = Double.parseDouble (object.readLine()); ^ Main.java:44: non-static variable cost cannot be referenced from a static context change.setCost(cost); ^ Main.java:48: non-static variable tax cannot be referenced from a static context tax = cost * 0.06; ^ Main.java:48: non-static variable cost cannot be referenced from a static context tax = cost * 0.06; ^ Main.java:50: non-static variable tax cannot be referenced from a static context System.out.println("The tax is: "+tax); ^ Main.java:51: non-static variable tax cannot be referenced from a static context change.setTax(tax); ^ Main.java:56: non-static variable payment cannot be referenced from a static context payment = Double.parseDouble(object.readLine()); ^ Main.java:58: non-static variable payment cannot be referenced from a static context change.setPayment(payment); ^ 8 errors
What do those errors mean? Can someone please explain and/or correct them? Thank you so much! ^___^