daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Johan Qin
  3.  * 5th Period AP Comp Sci
  4.  */
  5.  
  6. import java.util.*;
  7. import java.lang.*;
  8.  
  9. public class CarRental
  10. {
  11.     private Scanner input;
  12.     private String make;
  13.     private String model;
  14.     private double letter1;
  15.     private double letter2;
  16.     private double letter3;
  17.     private int digit;
  18.     private double rentalCode;
  19.    
  20.     public CarRental()
  21.     {
  22.         input = new Scanner(System.in);
  23.     }
  24.    
  25.     public void input()
  26.     {
  27.         System.out.println("Enter make: ");
  28.         make = input.next();
  29.         System.out.println("Enter model: ");
  30.         model = input.next();
  31.         System.out.println("Enter 1st license plate letter: ");
  32.         letter1 = input.next();
  33.         System.out.println("Enter 2nd license plate letter: ");
  34.         letter2 = input.nextDouble();
  35.         System.out.println("Enter 3rd license plate letter: ");
  36.         letter3 = input.nextDouble();
  37.         System.out.println("Enter license plate digit: ");
  38.         digit = input.nextInt();
  39.     }
  40.    
  41.     public double getRentalCode()
  42.     {
  43.         int sum1 = (int)letter1;
  44.         int sum2 = (int)letter2;
  45.         int sum3 = (int)letter3;
  46.         int ascii = sum1 + sum2 + sum3;
  47.         int sum = ascii + digit;
  48.         int remainder = sum % 26;
  49.         double letter = (char)(remainder + 65);
  50.         rentalCode = letter + sum;
  51.         return rentalCode;
  52.     }
  53.    
  54.     public void output()
  55.     {
  56.         System.out.println("Make = " + make);
  57.         System.out.println("Model = " + model);
  58.         System.out.print(letter1 + letter2 + letter3 + " " + digit + " =");
  59.         System.out.println(rentalCode);
  60.     }
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top