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: 3753437 • 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

package chegg2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Scanner;

public class VideoRental {

public static final List<String> ratings = new ArrayList<String>();

public static void main(String args[]) throws Exception {

ratings.add("EC");
ratings.add("E");
ratings.add("E10");
ratings.add("T");
ratings.add("M");
ratings.add("AO");
Scanner s = new Scanner(System.in);
/*
Prompting user to input first name
*/
System.out.println("Enter your date of birth in MM/DD/YYYY format ");
String rawdate = s.nextLine();
SimpleDateFormat dateFormat2 = new SimpleDateFormat("MM/dd/yyyy");
Calendar dob = Calendar.getInstance();
dob.setTime(dateFormat2.parse(rawdate));
System.out.println("Your date of birth is is " + dateFormat2.format(rawdate));
System.out.println("Age is:" + getAge(dob));
final int age = getAge(dob);
LocalDate localDate = LocalDate.now();
System.out.println("Todays current date is " + DateTimeFormatter.ofPattern("MM/dd/yyyy").format(localDate));

for(String rating: ratings){
switch(rating){
case "EC":
System.out.println("No Age restrictions" );
break;
case "E":
System.out.println("No Age restrictions" );
break;
case "E10":
if(age >= 10){
System.out.println("He is 10 or older" );
}else{
System.out.println("He is not 10 or older" );
}
break;
case "T":
if(age >= 13){
System.out.println("He is 13 or older" );
}else{
System.out.println("He is not 13 or older" );
}
break;
case "M":
if(age >= 17){
System.out.println("He is 17 or older" );
}else{
System.out.println("He is not 17 or older" );
}
break;
case "AO":
if(age >= 18){
System.out.println("He is 18 or older" );
}else{
System.out.println("He is not 18 or older" );
}
break;
}

// Use for(;;) to have the repeated calling of the code
System.out.println("Press 1 to Exit");
int i = s.nextInt();
if(i == 1){
System.exit(0);
}

}

}

// Returns age given the date of birth
public static int getAge(Calendar dob) throws Exception {
Calendar today = Calendar.getInstance();

int curYear = today.get(Calendar.YEAR);
int dobYear = dob.get(Calendar.YEAR);

int age = curYear - dobYear;

// if dob is month or day is behind today's month or day
// reduce age by 1
int curMonth = today.get(Calendar.MONTH);
int dobMonth = dob.get(Calendar.MONTH);
if (dobMonth > curMonth) { // this year can't be counted!
age--;
} else if (dobMonth == curMonth) { // same month? check for day
int curDay = today.get(Calendar.DAY_OF_MONTH);
int dobDay = dob.get(Calendar.DAY_OF_MONTH);
if (dobDay > curDay) { // this year can't be counted!
age--;
}
}

return age;
}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote