我已经创建了一个业务程序,它带有一个循环的double值并计算净利润。我需要将主类中的输入值添加到名为Business的自定义类中。然后,我应该计算Business类中的净利润并将最终值输出到主类。当我运行我的当前程序时,结果是“0.0”。 Business类没有从我的主类获取我的输入值,但我找不出原因。下面主要类:为什么我的程序返回“0.0”?
public class BusinessProject {
public static double revenue;
public static double expenses;
public static double TotalRevenue;
public static double TotalExpenses;
public static void main(String[] args) {
Business calc = new Business();
getTotalRevenue();
getExpense();
calc.Profit();
}
public static double getTotalRevenue() {
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Enter your revenue: \nJust type 0 when you've finished inputting all values");
revenue = scan.nextDouble();
TotalRevenue += revenue;
if(revenue==0) {
break;
}
}
return TotalRevenue;
}
public static double getExpense() {
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Enter your expenses: \nJust type 0 when you've finished inputting all values");
expenses = scan.nextDouble();
TotalExpenses += expenses;
if(expenses==0) {
break;
}
}
return TotalExpenses;
}
}
第二个自定义类别:
public class Business {
public static double ExpenseInput;
public static double RevenueInput;
public void REVENUE() {
BusinessProject TOTAL = new BusinessProject();
double RevenueInput = BusinessProject.TotalRevenue;
}
public static void EXPENSE() {
BusinessProject TOTAL2 = new BusinessProject();
double ExpenseInput = BusinessProject.TotalExpenses;
}
public void Profit() {
double difference = (RevenueInput - ExpenseInput);
if (difference <=1000) {
System.out.println("Net Profit: " + (difference - (difference * 0.00175)));
}
}
}
'商务类不是从我的主类让我的输入值,但我可以”不知道为什么 - 你没有做任何事情来传递值,那么你为什么期望通过输入? – Eran