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).
| 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 |
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**
ANS:
CODE:
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;
}
}
OR
CODE:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Calendar;
import java.util.Scanner;
public class GFG
{
public static int calculated_year,calculated_month,calculated_date;
static void findAge(int current_date, int current_month,
int current_year, int birth_date,
int birth_month, int birth_year)
{
int month[] = { 31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31 };
//if birth date is greater then current
// birth_month, then donot count this month
// and add 30 to the date so as to subtract
// the date and get the remaining days
if (birth_date > current_date)
{
current_month = current_month - 1;
current_date = current_date + month[birth_month - 1];
}
// if birth month exceeds current month,
// then do not count this year and add
// 12 to the month so that we can subtract
// and find out the difference
if (birth_month > current_month)
{
current_year = current_year - 1;
current_month = current_month + 12;
}
// calculate date, month, year
calculated_date = current_date - birth_date;
calculated_month = current_month - birth_month;
calculated_year = current_year - birth_year;
// print the present age
System.out.println("Present Age");
System.out.println("Years: " + calculated_year +
" Months: " + calculated_month + " Days: " +
calculated_date);
}
public static void main(String[] args)
{
String regex = "^(1[0-2]|0[1-9])/(3[01]|[12][0-9]|0[1-9])/[0-9]{4}$";
Scanner input=new Scanner(System.in);
String date;
while(true)
{
System.out.print("Enter Your bday in mm/dd/yyyy format:");
date=input.nextLine();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(date);
if(matcher.matches())
break;
else
System.out.println("Invalid date format. Please re-enter date.");
}
// present date
input.close();
Calendar cal = Calendar.getInstance();
int current_month = cal.get(Calendar.MONTH); // 5 int year = cal.get(Calendar.YEAR); // 2016
int current_date = cal.get(Calendar.DATE);
int current_year = cal.get(Calendar.YEAR); // 2016
// birth dd// mm// yyyy
String b_day=date.substring(0,date.indexOf("/"));
int birth_date = Integer.parseInt(b_day);
int birth_month=Integer.parseInt(date.substring(date.indexOf("/")+1, 5));
int birth_year = Integer.parseInt(date.substring(6));
// function call to print age
findAge(current_date, current_month, current_year,birth_date, birth_month, birth_year);
System.out.println("Rating\t\tAligibility");
if(calculated_year>=18)
{
System.out.println("EC\t\tPassed");
System.out.println("E\t\tPassed");
System.out.println("E10\t\tPassed");
System.out.println("T\t\tPassed");
System.out.println("M\t\tPassed");
System.out.println("AO\t\tPassed");
}
else if(calculated_year==17&& calculated_date<18)
{
System.out.println("EC\t\tPassed");
System.out.println("E\t\tPassed");
System.out.println("E10\t\tPassed");
System.out.println("T\t\tPassed");
System.out.println("M\t\tPassed");
}
else if(calculated_year==13&& calculated_date<17)
{
System.out.println("EC\t\tPassed");
System.out.println("E\t\tPassed");
System.out.println("E10\t\tPassed");
System.out.println("T\t\tPassed");
}
else if(calculated_year==10&& calculated_date<13)
{
System.out.println("EC\t\tPassed");
System.out.println("E\t\tPassed");
System.out.println("E10\t\tPassed");
}
else
{
System.out.println("EC\t\tPassed");
System.out.println("E\t\tPassed");
}
}
}
output
![Java-Age Calc/src/GFG.java-Eclipse IDE Eile Edit Source Refactor Navigate Search Projec Bun Window Help Quick Access: E | 巵ち ▽-B D GFGjava × Package Explorer 3 Age Calc Console ittcaLcutatea_year-) sterminated> GFG lJava Application) C:Program Files Javaljdk1.8.0 131bin javaw.exe (21-Sep-2018, 9:14:0S PM) 82 83 Enter Your bday in mm/dd/yyyy format:11/86/1989 Present Age Years: 29 Months: 2 Days: 10 Rating EC JRE System Library ljdk1.8.0 131] System.out.println(Ct tPassed System.out.println(EltitPassed System.out.println(E18 titPassed System.out.println(TthtPassed System.out.printlnMt\tPassed) System.out.println(A0titPassed (defoult package 85 86 Aligibility Passed Passed Passed Passed Passed Passed GFG,javia Game Word Wars GorceryStoreSimple Integer Class Poem Inhenitence Simple Validation for date E10 90 else if(calculated year 178& calcula A0 92 93 94 95 96 System.out.printin(ECYttPassed System.out.println(EltltPassed System.out.println(E1 titPassed System.out.println(TitltPassed) System.out.printinMt tPassed) 98 else if(calculated-year=138& calcula 01 182 183 System.out.printin(ECYttPassed System.out.println(EltltPassed System.out.println( E1 titPassed System .out printlnTt tPassed) else if(calculated year--188& calcula 106 187 System.out.println( ECt tPassed System.out.println(EltitPassed System.out.println(E1 titPassed 110 else 112 System.out.println(ECht tPassed System.out.println(Et\tPassed 114 115 116 118 119 O Type here to search sf ^ ) ENG 21:14 21-09-2018](http://img.homeworklib.com/questions/c644a080-260c-11eb-9b81-b9d92008f12b.png?x-oss-process=image/resize,w_560)
Can you help me with a Java Code: We are to write software for the checkout...
please write program in java and comment the code clearly. I am providing previous classes Media and payment codes to be used for this class.(its not a big code to write , it seems ,because i added previous classes , pleases help. public class Media { String name; int year; // a constructor which initializes the media with the provided name and publication year. public Media(String name, int year) { this.name = name; this.year = year; } //...
Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...
Java Project For this assignment, you will write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: delete the addfirst, addlast, and add(index) methods and instead include a single add method...
can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...
Can you help me to write a Java code for this:
The program must satisfy the following
requirements:
The program should ask the user the following information
The site names for 6 locations (into
an array)
The cash donation for 6 locations
(into an array)
The food donations in pounds for 6
locations (into an array)
Is there another test they want to
process, meaning do they want to run the program again?
Based on the input, the program will...
CAN SOMEONE HELP WITH THIS? Part 1: power() method We want to write a method that will enable us to calculate a number to a given power. In other words, we are writing a method to mimic what the Math.pow() method we have seen before does. To write this method use the following requirements: The method should return an integer. It should have two parameters x and y both integers. The name of this method will be power(). For the...
Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.) 2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...
For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...
n-Class Exercise 1 Instructions: Submit your work through Blackboard by the due date. Late submissions are not allowed. You can take photos of or scan your solutions Calculate or write the formulas for each test statistic and p-value for each hypothesis test question (questions 7-10). It is true you will never have to calculate these in real life, however, you should know what Megastat, or any other statistical software, is calculating. 1) According to an IRS study, it takes a...
Hi can you help me make a summary about this short article and
how it affects me economically as US citizen ?
Supported by
Federal Shutdown’s Uneven Toll: Some Americans Are Devastated,
Others ObliviousFederal Shutdown’s Uneven Toll: Some Americans Are
Devastated, Others Oblivious
“It has been terrible,” said Andrea Caviedes, a furloughed loan
processor in the Agriculture Department’s rural development
program.CreditMichael B. Thomas for The New York Times
Image
“It has been terrible,” said Andrea Caviedes, a furloughed loan
processor...