import java.util.*;
import java.text.NumberFormat;     //They can also use other formatting methodology
import java.util.Locale;
import java.util.Random;           //They can also use other random number generation tactics

public class TollwayCustomerDataBase 
   {

   static Scanner sc = new Scanner(System.in);
   public static void main (String args [])
      {
      
      //Pre loaded customer data: students will only get the string literals
      Customer cust1 = new Customer("Montana","Jose", "Ford", "F150", "ABC-123", 55.00);
      cust1.address = new MailingAddress ("3445 Rockhill Rd.", "Santa Fe", "New Mexico", "77777");
      
      
      
      String yesNo= ""; 
      //Checks that the customer object was created //////////////////////////////////////
      if(cust1 != null && cust1.address != null)
         System.out.println("Customer record import successful.");
      
      //Prompts the user to see if they want to update the record //////////////////////////////////////
      do{
         System.out.print("\nType in \"Yes\" if you want update this record:\nENTER: Yes or No: ");
         yesNo = getUserStringInput();    //helper method call
         if(yesNo.equals("yes"))
            setDepositCustomerRecord(cust1);   //helper method call
         }while (yesNo.equals("yes") == false && yesNo.equals("no") == false);
      
      //Prompts the user to see if they want to retrieve the record //////////////////////////////////////
      do{
         System.out.print("\nDo you want to retrieve this record?\nENTER: Yes or No: ");
         yesNo = getUserStringInput();       //helper method call
         if(yesNo.equals("yes"))
            consoleRecordCheck(cust1);       //helper method call
         else if(yesNo.equals("no")){
            System.out.print("\nGoodbye!");
            System.exit(0);                  //this is the only program exit
            } 
         } while (yesNo.equals("yes") == false && yesNo.equals("no") == false);                 
   
      }
   
   //Prompts the user to submit a deposit: calls other helper methods //////////////////////////////////////
   
   private static void setDepositCustomerRecord(Customer c)
      {
      System.out.println("\nAll new records require a new deposit. How much will the customer be depositing? ");
      double newDeposit = getUserNumberInput();  //helper method call
      c.setDeposit(newDeposit);
      setReferenceID(c);                         //helper method call
      String message = getDepositMessage(c);     //helper method call
      System.out.println(message);
   
      }
  
   //Creates and stores the reference ID (random letters and numbers) //////////////////////////////////////
   //helper method 
   private static void setReferenceID(Customer c)
      {
      String referenceString = "";
      char randomReferenceLetter;
      Random rand = new Random();
   
      for (int i=0; i<3; i++)
         {
         do
            {
            randomReferenceLetter = (char)(rand.nextInt(26)+'A');
            } while (randomReferenceLetter == 'O');
         referenceString += randomReferenceLetter;
         }
      int randomReferenceNumber;
      do{ randomReferenceNumber = rand.nextInt(100000);
         } while(randomReferenceNumber<10000);
      referenceString += randomReferenceNumber;
      c.setReferenceTicket(referenceString);
      }
   
   //Displays the message in console after a successful deposit entry //////////////////////////////////////
   //helper method 
   private static String getDepositMessage(Customer c)
      {
      
      NumberFormat d = NumberFormat.getCurrencyInstance(new Locale("en", "US"));
      return "\n" + c.getFN() + " " + c.getLN() + " deposited a total of " + d.format(c.getDeposit())+". \nReference ID: "+
         c.getReferenceTicket();
      }
   
   
   //Gets the user input for the yes or no prompts and turns it into LC //////////////////////////////////////
   //helper method 
   private static String getUserStringInput()
      {
      String temp = sc.nextLine().toLowerCase();
      
      return temp;
      }  
   
   //Gets the user input for the deposit prompt //////////////////////////////////////
   //helper method 
   private static double getUserNumberInput()
      {
      double temp;
      while(true){   
         try{
            do{
               System.out.print("Please enter in a value between $1.00 to $9,999.99: ");
               temp = sc.nextDouble();
               sc.nextLine();
               temp = 0.01 * Math.floor(temp *100);
               }while(temp >9999 || temp <1);
            return temp;
            
            }
         catch(InputMismatchException e)
            {
            sc.next();
            System.out.println("\nPlease enter a correct value.");
            }
         }
      
      }
         
   //Prints the final record to the console by using data from the object //////////////////////////////////////
   private static void consoleRecordCheck(Customer c)
      {
      NumberFormat d = NumberFormat.getCurrencyInstance(new Locale("en", "US"));
      System.out.println("\n"+c.getFN() + " " + c.getLN());
      System.out.println(c.address.getAdd());
      System.out.println("Deposit: " + d.format(c.getDeposit()));
      System.out.println("Car Information: " + c.getMake() + " " + c.getModel());
      System.out.println("Reference ID: " + c.getReferenceTicket());
      //System.out.println(c);  //This prints the record from its toString method
      }
   }


/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/*****************CUSTOMER*****************************/
/*Student will only get the .class files for this */
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
class Customer 
   {
   private String last_Name;
   private String first_Name;
   private String carMake;
   private String carModel;
   private String carLicensePlate;
   private double deposit;
   private String reference = "";
   //private List<String> references = new ArrayList<>();  //This is in the next round

   public MailingAddress address;
   
   public Customer (String ln, String fn, String cMa, String cMo, String lp, Double de)
      {
      this.last_Name = ln;
      this.first_Name = fn;
      this.carMake = cMa;
      this.carModel = cMo;
      this.carLicensePlate = lp;
      this.address = new MailingAddress();
      this.deposit = de;
      }
   
   public String getLN()  //gets last name
      {
      return this.last_Name;
      }
            
   public void setLN(String ln)  //sets last name
      {
      this.last_Name = ln;
      }
   
   public String getFN()  //gets first name
      {
      return this.first_Name;
      }

   public void setFM(String fn)  //sets first name
      {
      this.first_Name = fn;
      }
   
   public String getMake()  //gets make of car
      {
      return this.carMake;
      }
      
   public void setMake(String ma)  //sets make of car
      {
      this.carMake = ma;
      }
      
   public String getModel()  //gets model of car
      {
      return this.carModel;
      }
      
   public void setModel(String mo) //sets model of car
      {
      this.carModel = mo;
      }

   public Double getDeposit() //gets deposit
      {
      return this.deposit;   
      }
   
   public void setDeposit(Double d) //sets deposit amount
      {
      this.deposit = d;   
      }
      
   public String getLicensePlate()  //gets plate #
      {
      return this.carLicensePlate;  
      }
    
   public void setLicensePlate(String lp)  //sets plate #
      {
      this.carLicensePlate = lp;
      }
    
   public void setReferenceTicket(String d)
      {
      
      reference = d;
      }
      
   public String getReferenceTicket()
      {
      return reference;
    
      }

    
   //This is not used in the program. If a student tries to print the object we will get a similiar output and its wrong
   /*
        Customer[ Jose Montana
     Ford F150
     ABC-123
     456.0]    
   */
   public String toString()
      {
      return this.getClass().getName() + "[ " + this.getFN() + " "
            + this.getLN() + "\n" + this.getMake() + " " + this.getModel() +
            "\n" + this.getLicensePlate() + "\n" + this.getDeposit() + "]";
      }
   } 
   
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/*****************Mailing Address*****************************/
/*Student will only get the .class files for this */
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

class MailingAddress 
   {
   private String street;
   private String city;
   private String state;
   private String zipCode;
      
   public MailingAddress()
      {
      this.street = " "; 
      this.city = " ";
      this.state = " ";
      this.zipCode = " ";
      }     
   
   public MailingAddress(String s, String c, String st, String zc)
      {
      this.street = s; 
      this.city = c;
      this.state = st;
      this.zipCode = zc;
      
      }
   public String getAdd()
      {
      return this.street + "\n" + this.city + ", "+ this.state + " " + this.zipCode;
      }     
   
   }  

