Answer to Question #254811 in Java | JSP | JSF for PeterLover

Question #254811

The government has decided to charge 0.5% tax on every car purchased from KTA. You are to write a Java program. Your program should: 


a. Request for a username and password to be inputted. Your username and password should grant access to the program if they are correctly inputted 


b. Your program should have a method that calculates and displays the tax on any car purchased. 


c. Your program should be able to perform “b” above at least 10 times. 


d. Assuming sales have now gone up and the government has scraped the tax incentive. A tax of 25% imposed on each car sale. Modify a portion of the code to reflect the new development. 


e. Explain how the Ghana Revenue Agency (GRA) can use your program to calculate tax on goods imported into the country.


1
Expert's answer
2021-10-22T00:49:03-0400
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static final double TAX = 0.25;
    private static String username = "admin";
    private static String password = "admin";

    public static void calculateTax(double price) {
        System.out.printf("Price: %.2f, TAX: %.2f %%, Result: %.2f\n", price, TAX * 100, price * TAX);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Username: ");
        String inUsername = in.nextLine();
        System.out.println("Password: ");
        String inPassword = in.nextLine();
        if (inUsername.equals(username) && inPassword.equals(password)) {
            for (int i = 0; i < 10; i++) {
                calculateTax(new Random().nextInt(51) + 50);
            }
        } else {
            System.out.println("Invalid username or password.");
        }
    }
}


Set a specific tax for each product or product category and calculate the total values by entering the cost of the product.


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