Answer to Question #192218 in Java | JSP | JSF for joe

Question #192218

Create a Spending application to help examine the spending patterns of a user. The application should prompt the user for the amount spent last month on food, clothing, entertainment, and rent, and then displays a table showing the percentage of expenditures in each category.



1
Expert's answer
2021-05-12T10:20:37-0400
import java.util.Scanner;

public class Spending {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double sum = 0;
        double food;
        double clothing;
        double entertainment;
        double rent;
        System.out.print("Enter the amount spent on food: ");
        food = in.nextDouble();
        sum += food;
        System.out.print("Enter the amount spent on clothing: ");
        clothing = in.nextDouble();
        sum += clothing;
        System.out.print("Enter the amount spent on entertainment: ");
        entertainment = in.nextDouble();
        sum += entertainment;
        System.out.print("Enter the amount spent on rent: ");
        rent = in.nextDouble();
        sum += rent;
        System.out.printf("\n%-40s %.2f %%\n", "The percentage spent on food:", (food / sum) * 100);
        System.out.printf("%-40s %.2f %%\n", "The percentage spent on clothing:", (clothing / sum) * 100);
        System.out.printf("%-40s %.2f %%\n", "The percentage spent on entertainment:", (entertainment / sum) * 100);
        System.out.printf("%-40s %.2f %%\n", "The percentage spent on rent:", (rent / sum) * 100);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS