Answer to Question #235737 in Java | JSP | JSF for Ema

Question #235737

Design a java application that will allow a traffic department user to search for and view fines


1
Expert's answer
2021-09-10T18:51:29-0400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String[] licencePlates = {"fg333af", "hh224aa", "vv334ah"};
        double[] fines = {10.5, 20, 11};
        Scanner in = new Scanner(System.in);
        String choice;
        boolean isFound;
        while (true) {
            System.out.println("\n1. Search\n2. View\n0. Exit\n");
            choice = in.nextLine();
            switch (choice) {
                case "1":
                    isFound = false;
                    System.out.print("Enter the licence plate: ");
                    String licencePlate = in.nextLine();
                    for (int i = 0; i < licencePlates.length; i++) {
                        if (licencePlates[i].equalsIgnoreCase(licencePlate)) {
                            System.out.println("Fine: " + fines[i]);
                            isFound = true;
                            break;
                        }
                    }
                    if (!isFound) {
                        System.out.println("There are no fines.");
                    }
                    break;
                case "2":
                    for (int i = 0; i < licencePlates.length; i++) {
                        System.out.println(licencePlates[i] + " fine: " + fines[i]);
                    }
                    break;
                case "0":
                    System.exit(0);
                    break;
            }
        }
    }
}

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