使用java编写财务信息类,创建一个 FinancialInfo 类的实例,传入公司名称、定金收入、押金收入、租金收入、其它收入、员工成本、房租、水电、税收及其它费用,输出收入计算、成本计算、净收入计算。
时间: 2023-09-30 22:05:05 浏览: 42
好的,以下是我根据您的要求编写的 Java 代码:
```java
public class FinancialInfo {
private String companyName; // 公司名称
private double depositIncome; // 定金收入
private double securityDepositIncome; // 押金收入
private double rentIncome; // 租金收入
private double otherIncome; // 其它收入
private double employeeCost; // 员工成本
private double rent; // 房租
private double utilities; // 水电费用
private double taxes; // 税收
private double otherExpenses; // 其它费用
public FinancialInfo(String companyName, double depositIncome, double securityDepositIncome, double rentIncome, double otherIncome, double employeeCost, double rent, double utilities, double taxes, double otherExpenses) {
this.companyName = companyName;
this.depositIncome = depositIncome;
this.securityDepositIncome = securityDepositIncome;
this.rentIncome = rentIncome;
this.otherIncome = otherIncome;
this.employeeCost = employeeCost;
this.rent = rent;
this.utilities = utilities;
this.taxes = taxes;
this.otherExpenses = otherExpenses;
}
public void printIncomeCalculation() {
double totalIncome = depositIncome + securityDepositIncome + rentIncome + otherIncome;
System.out.println("收入计算:");
System.out.println(" 定金收入: " + depositIncome);
System.out.println(" 押金收入: " + securityDepositIncome);
System.out.println(" 租金收入: " + rentIncome);
System.out.println(" 其它收入: " + otherIncome);
System.out.println(" 总收入: " + totalIncome);
}
public void printCostCalculation() {
double totalCost = employeeCost + rent + utilities + taxes + otherExpenses;
System.out.println("成本计算:");
System.out.println(" 员工成本: " + employeeCost);
System.out.println(" 房租: " + rent);
System.out.println(" 水电费用: " + utilities);
System.out.println(" 税收: " + taxes);
System.out.println(" 其它费用: " + otherExpenses);
System.out.println(" 总成本: " + totalCost);
}
public void printNetIncomeCalculation() {
double totalIncome = depositIncome + securityDepositIncome + rentIncome + otherIncome;
double totalCost = employeeCost + rent + utilities + taxes + otherExpenses;
double netIncome = totalIncome - totalCost;
System.out.println("净收入计算:");
System.out.println(" 总收入: " + totalIncome);
System.out.println(" 总成本: " + totalCost);
System.out.println(" 净收入: " + netIncome);
}
public static void main(String[] args) {
FinancialInfo info = new FinancialInfo("ABC Company", 10000.0, 5000.0, 20000.0, 8000.0, 15000.0, 8000.0, 3000.0, 5000.0, 2000.0);
info.printIncomeCalculation();
info.printCostCalculation();
info.printNetIncomeCalculation();
}
}
```
在这个 `FinancialInfo` 类中,我们定义了多个私有属性来表示公司的各种财务信息,例如定金收入、员工成本等等。我们还定义了三个方法来计算和输出收入、成本、净收入。
在 `main` 方法中,我们创建了一个 `FinancialInfo` 类的实例,并传入了一些示例数据。然后调用了三个方法来输出结果。您可以根据需要修改示例数据来测试不同的情况。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)