87.8k views
5 votes
The below program uses an array salaryBase to hold the cutoffs for each salary level and a parallel array taxBase that has the corresponding tax rate. Run the program and enter annual salaries of 40000 and 60000, then enter 0. Modify the program to use two parallel arrays named annualSalaries and taxesToPay, each with 10 elements. Array annualSalaries holds up to 10 annual salaries entered; array taxesToPay holds up to 10 corresponding amounts of taxes to pay for those annual salaries. Print the total annual salaries and taxes to pay after all input has been processed. Run the program again with the same annual salary numbers as above. Challenge: Modify the program from the previous step to use a 2-dimensional array of 10 elements named salariesAndTaxes instead of two one-dimensional parallel arrays. The 2D array's first column will hold the salaries, the second the taxes to pay for each salary. "java"

User Lightning
by
5.6k points

1 Answer

3 votes

Answer:

Check the explanation

Step-by-step explanation:

1. After running the program for annual salary 40000 and 50000 and then enter 0

a) For annual salaries of 40000

taxRate will be . 20

taxToPay will be 40000 x .20 = 8000

b)For annual salaries of 50000

taxRate will be . 30

taxToPay will be 50000 x .30 = 15000

2. Modify the program to use two parallel arrays named annualSalaries and taxesToPay

a) For implementing array of anuualSalaries that take input from user, refer following given code:

Scanner s=new Scanner(System.in);

System.out.println("enter number of anuualSalaries");

int n=s.nextInt();

int anuualSalaries[]=new int[n];

System.out.println("enter anuualSalaries");

for(int i=0;i<n;i++){//for reading array

anuualSalaries[i]=s.nextInt();

b) For implementing array of taxestoPay refer following code

int taxestoPay[] = new int[anuualSalaries.length];

for (int i = 0; i < taxestoPay.length; i++) {

taxestoPay[i] = "enter the result value of tax to pay"

}

4. For two dimensional array of salariesAndTaxes refer following given code

int[][] salariesAndTaxes = new int[2][];

salariesAndTaxes[0] = new int[10];

salariesAndTaxes[1] = new int[10];

User Michal Mau
by
4.9k points