1)从键盘输入房屋面积(单位平方米)、房屋总价(单位元),以及房屋性质。 (2)给出对应的房屋契税税率(单位%),计算契税应纳税额(单位元),并将结果输出在屏幕上。并给出两个测试类使用java语言编写
时间: 2023-12-27 19:03:32 浏览: 35
好的,以下是使用 Java 语言编写的代码来回答你的问题:
```java
import java.util.Scanner;
public class PropertyTaxCalculator {
public static void main(String[] args) {
// 定义房屋性质和契税税率
final double[] TAX_RATE = {0.01, 0.03};
final String[] PROPERTY_TYPE = {"普通住房", "非普通住房"};
final int[] PROPERTY_TAX = {1, 2};
// 从键盘输入房屋面积、房屋总价和房屋性质
Scanner scanner = new Scanner(System.in);
System.out.print("请输入房屋面积(平方米):");
double area = scanner.nextDouble();
System.out.print("请输入房屋总价(元):");
double price = scanner.nextDouble();
System.out.print("请输入房屋性质(普通住房/非普通住房):");
String propertyType = scanner.next();
// 计算契税应纳税额
int propertyTax = 0;
for (int i = 0; i < PROPERTY_TYPE.length; i++) {
if (PROPERTY_TYPE[i].equals(propertyType)) {
propertyTax = PROPERTY_TAX[i];
break;
}
}
double taxRate = TAX_RATE[propertyTax - 1];
double taxAmount = area * price * taxRate;
// 输出结果
System.out.printf("契税应纳税额为:%f 元\n", taxAmount);
}
}
```
接下来是两个测试类:
```java
public class PropertyTaxTest {
public static void main(String[] args) {
// 测试类1:普通住房,面积:100 平方米,总价:200 万元
double area1 = 100;
double price1 = 2000000;
String propertyType1 = "普通住房";
// 计算契税应纳税额
int propertyTax1 = 0;
for (int i = 0; i < PropertyTaxCalculator.PROPERTY_TYPE.length; i++) {
if (PropertyTaxCalculator.PROPERTY_TYPE[i].equals(propertyType1)) {
propertyTax1 = PropertyTaxCalculator.PROPERTY_TAX[i];
break;
}
}
double taxRate1 = PropertyTaxCalculator.TAX_RATE[propertyTax1 - 1];
double taxAmount1 = area1 * price1 * taxRate1;
// 输出结果
System.out.printf("测试1:契税应纳税额为:%f 元\n", taxAmount1);
// 测试类2:非普通住房,面积:150 平方米,总价:300 万元
double area2 = 150;
double price2 = 3000000;
String propertyType2 = "非普通住房";
// 计算契税应纳税额
int propertyTax2 = 0;
for (int i = 0; i < PropertyTaxCalculator.PROPERTY_TYPE.length; i++) {
if (PropertyTaxCalculator.PROPERTY_TYPE[i].equals(propertyType2)) {
propertyTax2 = PropertyTaxCalculator.PROPERTY_TAX[i];
break;
}
}
double taxRate2 = PropertyTaxCalculator.TAX_RATE[propertyTax2 - 1];
double taxAmount2 = area2 * price2 * taxRate2;
// 输出结果
System.out.printf("测试2:契税应纳税额为:%f 元\n", taxAmount2);
}
}
```
希望这个代码能够回答你的问题。如果你有任何其他问题,欢迎随时问我。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)