Skip to content

Instantly share code, notes, and snippets.

@WesJD
Created December 2, 2016 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WesJD/b5629b23d629d0619f8145e27ada33b0 to your computer and use it in GitHub Desktop.
Save WesJD/b5629b23d629d0619f8145e27ada33b0 to your computer and use it in GitHub Desktop.
import javax.swing.JOptionPane;
public class CarRental {
private CarRental() {
final String make = JOptionPane.showInputDialog("What is the car make?");
final String model = JOptionPane.showInputDialog("What is the car model?");
final String licensePlate = JOptionPane.showInputDialog("What is the license plate value?");
final int digits = Integer.parseInt(licensePlate.substring(4));
int charTotal = 0;
for(char c : licensePlate.substring(0, 3).toCharArray()) charTotal += c;
final int sum = digits + charTotal;
final char letter = (char) ('A' + (sum % 26));
JOptionPane.showMessageDialog(null,
"Make = " + make + "\nModel = " + model + "\n" + licensePlate + " = " + letter + "" + sum);
}
public static void main(String[] args) {
new CarRental();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment