import javax.swing.*;
public class Main {
private static int[] vins;
private static String[] manufactures;
private static int[] prices;
private static void loadArray() {
vins = new int[]{112367, 212367, 312367};
manufactures = new String[]{"AUDI", "BMW", "VOLVO"};
prices = new int[]{180000, 170000, 210000};
}
private static void searchArray(int vin) {
for (int i = 0; i < vins.length; i++) {
if (vins[i] == vin) {
JOptionPane.showMessageDialog(null, vin + " " + manufactures[i] + " R " + prices[i]);
return;
}
}
JOptionPane.showMessageDialog(null, "Vehicle not found");
}
public static void main(String[] args) {
loadArray();
while (true) {
int choice = Integer.parseInt(JOptionPane.showInputDialog(null,
"1. Search by VIN\n2. Display all vehicles\n0. Exit"));
switch (choice) {
case 1:
searchArray(Integer.parseInt(JOptionPane.showInputDialog(null,
"Enter the VIN")));
break;
case 2:
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < vins.length; i++) {
buffer.append(vins[i]).append(" ").append(manufactures[i]);
buffer.append(" R ").append(prices[i]).append("\n");
}
JOptionPane.showMessageDialog(null, buffer.toString());
break;
case 0:
System.exit(0);
}
}
}
}
Comments
Leave a comment