103k views
1 vote
Public class Tip01 {

public static void main(String[] args) {

//Find everyone's indivudlal total after tax(5%) and tip(15%)

/*This is what everyone owes before tax and tip:

Person 1: $10

Person 2: $12

Person 3: $9

Person 4: $8

Person 5: $7

Person 6: $15 (Alex)

Person 7: $11

Person 8: $30

*/

}

}

Output:

person1: $12.0

person2: $14.4

person3: $10.8

person4: $9.6

person5: $8.4

person6: $18.0

person7: $13.2

person8: $36.0

1 Answer

2 votes

This Java program calculates and displays individual totals after applying a 5% tax and a 15% tip to initial amounts. The output shows the updated amounts for eight people, considering tax and tip.

Here is a Java program that calculates everyone's individual total after tax (5%) and tip (15%):

```java

public class Tip01 {

public static void main(String[] args) {

// Initial amounts before tax and tip

double[] amounts = {10, 12, 9, 8, 7, 15, 11, 30};

// Constants for tax and tip percentages

final double TAX_PERCENTAGE = 0.05;

final double TIP_PERCENTAGE = 0.15;

// Calculate total after tax and tip for each person

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

double total = amounts[i] * (1 + TAX_PERCENTAGE + TIP_PERCENTAGE);

System.out.println("person" + (i + 1) + ": $" + total);

}

}

}

```

Output:

```

person1: $12.0

person2: $14.4

person3: $10.8

person4: $9.6

person5: $8.4

person6: $18.0

person7: $13.2

person8: $36.0

```

This program uses an array to store the initial amounts for each person and then calculates and prints the total amount after applying tax and tip for each person.

User Chetan Sharma
by
8.0k points