Design a java application that will allow a traffic department user to search for and view fines
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;
}
}
}
}
Comments
Leave a comment