Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you help me with a Java Code: We are to write software for the checkout syst

ID: 3753405 • Letter: C

Question

Can you help me with a Java Code:

We are to write software for the checkout system of a video game rental store. Note: You are not writing the entire checkout system. You are responsible for writing (and testing!) only the age-restricted part of the system.

The specification for your system is as follows: At the start of each rental transaction, the system will first scan a barcode to do a customer lookup. (Assume other people in the company will be writing the database software. Your software only needs to be passed a date of birth, followed by a progression of ratings. In other words, you will be using test stubs to test your software.)

After the date of birth is received, the system will scan barcodes on each game being rented. This time, instead of being passed a date of birth, the test stubs will return a series of video game ratings. Video game ratings and restrictions are shown in the accompanying table. This process loops until the cashier signal the end of the transaction (in other words, no more games to be scanned).

The software must (1) correctly calculate an age given a date of birth and today’s date, and (2) correctly determine whether or not each item being rented passes the store’s age restriction policy or not.

Note:

**The program should be continued till the cashiers hit the end, the date format for current date and Birthdate is MM/DD/YYYY**

Ratings: EC E E10 T M AO Age Restrictions: None None Must be 10 or older Must be 13 or older Must be 17 or older Must be 18 or older

Explanation / Answer

import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.MonthDay; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class PolicyChecker { public static int getAge(String date) { SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy"); int age = 0; try { Date date1 = dateFormat.parse(date); Calendar now = Calendar.getInstance(); // System.out.println("Date current:"+now); Calendar dob = Calendar.getInstance(); // System.out.println("Date dob:"+dob); dob.setTime(date1); int year1 = now.get(Calendar.YEAR); int year2 = dob.get(Calendar.YEAR); age = year1 - year2; int month1 = now.get(Calendar.MONTH); int month2 = dob.get(Calendar.MONTH); if (month2 > month1) { age--; } else if (month1 == month2) { int day1 = now.get(Calendar.DAY_OF_MONTH); int day2 = dob.get(Calendar.DAY_OF_MONTH); if (day2 > day1) { age--; } } } catch (ParseException e) { e.printStackTrace(); } return age; } public static String checkPolicy(int age,String rating){ if(rating.equalsIgnoreCase("E10")){ return age >= 10 ? "Policy check passed" : "Policy check failed"; } else if(rating.equalsIgnoreCase("T")){ return age >= 13 ? "Policy check passed" : "Policy check failed"; } else if(rating.equalsIgnoreCase("M")){ return age >= 17 ? "Policy check passed" : "Policy check failed"; } else if(rating.equalsIgnoreCase("AO")){ return age >= 18 ? "Policy check passed" : "Policy check failed"; } return "Invalid rating: "+rating; } public static void main(String args[]){ int ch=0; String date,rating; Scanner sc=new Scanner(System.in); do{ System.out.println("1.Check Policy"); System.out.println("2.End"); System.out.println("Enter your choice:"); ch=sc.nextInt(); switch (ch) { case 1: System.out.println("Enter DOB(MM/DD/YYYY):"); date = sc.next(); System.out.println("Enter Rating of video game"); rating=sc.next(); System.out.println(checkPolicy(getAge(date),rating)); break; case 2: break; } }while(ch!=2); } }