When I initialize an object in testClass.java (aClass aClassObject = new aClass(aIncome, aRevenue, aCost)) eclipse states that the local variables aIncome, aRevenue, aCost may not have been initialized.
I am sorry if my code is difficult to read. I am a beginner and trying to learn little bit of programming before my class starts.
I am sorry if my code is difficult to read. I am a beginner and trying to learn little bit of programming before my class starts.
import javax.swing.JOptionPane; public class testClass { public static void main(String[] args) { double aIncome; String input = JOptionPane.showInputDialog("Please enter the Current assets "); double aRevenue = Double.parseDouble(input); String input1 = JOptionPane.showInputDialog("Please enter the Current assets "); double aCost = Double.parseDouble(input1); aClass aClassObject = new aClass(aIncome, aRevenue, aCost); System.out.println(aClassObject.toString(aClassObject)); } }
public class aClass { private double income; private double revenue; private double cost; public aClass(double aIncome, double aRevenue, double aCost) { income = aIncome; revenue = aRevenue; cost = aCost; income = revenue-cost; } public String toString (aClass aClassObject){ String answer = "the income should be" + income; return answer; } }