0
私はクラスの税金控除の簡単な計算を作成しました。今度は、ユーザーが自分の税金を何回でも計算できるようにループを追加する必要があります。ループを理解するのが難しい。 建設的なフィードバックは感謝の意を表します。Loop、new to programming
/**
*
* @author James
* Assignment 3 Taxes Owned
*/
import java.util.Scanner;
public class TaxOwned {
public static void main(String[] args) {
//Initializing input Scanner
Scanner input = new Scanner(System.in);
//Declare and initialize gender, age, martial status, income and name variables
//Ask user to enter name
System.out.println("Enter you first name:");
String name = input.next();
//Asks user to enter age
System.out.println("Enter age in years:");
Byte age = input.nextByte();
// Asks user to enter gender
System.out.println("Enter your gender(M/F):");
char gender = input.next().charAt(0);
//Ask user to enter martial status
System.out.println("Enter your martial status(S/M/D/W):");
char martial_status = input.next().charAt(0);
// Ask user to enter taxable income
System.out.println("Enter your taxable income for 2016:");
long income = input.nextLong();
//Declaring variables to store name prefix and tax amount
String name_prefix;
double tax_amount;
//Checking gender and age to assign correct prefix
if (gender == 'M')
{
name_prefix = (age < 18) ? "Master." : "Mr.";
}
else
{
name_prefix = (martial_status == 'M') ? "Mrs." : "Ms.";
}
// Calculating tax based on martial status and income
switch (martial_status)
{
case 'M':
if (income < 8500)
{
tax_amount = 0;
System.out.println(name_prefix + "" + name + ", based on the income provided, you owe no tax for the fiscal year 2016");
}
else
{
if (income < 24000)
{
tax_amount= income * 0.01;
}
else
{
tax_amount = income * 0.025;
}
System.out.println(name_prefix + "" + name + ",based on the income provided, you owe a tax of $" + tax_amount + " for the fiscal year 2016");
}
break;
case 'S':
if (income < 8500)
{
tax_amount = 0;
System.out.println(name_prefix + "" + name + ",based on the income provided, you owe no tax for the fiscal year 2016");
}
else
{
if(income < 24000)
{
tax_amount = income * 0.015;
}
else
{
tax_amount = income * 0.034;
}
System.out.println(name_prefix + " " + name + ",based on the income provided, you owe a tax of $" + tax_amount + " for the fiscal year 2016");
}
break;
case 'D':
if (income > 8500)
{
tax_amount = 0;
System.out.println(name_prefix + " " + name + ", based on the income provided, you owe no tax for the fiscal year 2016");
}
else
{
if (income < 2400)
{
tax_amount = income * 0.01;
}
else
{
tax_amount = income * 0.025;
}
System.out.println(name_prefix + " " + name + ",based on the income provided, you owe a tax of $" + tax_amount + " for the fiscalyear 2016 ");
}
break;
case 'W':
if (income < 8500)
{ tax_amount = income * 0.015;
}
else
{
tax_amount = income * 0.034;
}
System.out.println(name_prefix + " " + name + ", based on the income you provided, you owe a tax $" + tax_amount + " for the fiscal year 2016");
break;
default : System.out.println(" Sorry! Our system is unable to calculate your tax at this time.");
}
System.out.println("Thank you!");
//closing all objects
input.close();
}
を与えるだろう。 –
正確にはどのようなループが混乱を引き起こしていますか? – nitind