<img id=“image” src=C:jku log.png”> <> 1. Introduction #This project presents an automated system designed for Jinka University to manage cafeteria access using R programming. This assignment is submitted to the Department of Statistics within the College of Natural and Computational Sciences.

##The system ensures that only eligible students enter during specific meal hours and effectively prevents double entries. — 1. Database Generation — Define the allowed digits digits <- 0:3

```{r} Create all combinations of the 4 digits for 4 positions combinations <- expand.grid(d1 = digits, d2 = digits, d3 = digits, d4 = digits)

Combine the individual columns into a single string for each ID

student_ids <- apply(combinations, 1, function(x) paste0(x, collapse = ““))

Sort them numerically (optional)

student_ids <- sort(student_ids)

Display the results

print(student_ids) length(student_ids) ```

```{r}Create the master database students_db <- data.frame( id = student_ids, # Logic: starts with 0 or 2 status = ifelse(grepl(“1”, student_ids), “cafe”, “non-cafe”), stringsAsFactors = FALSE )

Initialize the global attendance log

attendance_log <- data.frame( id = character(), meal = character(), timestamp = character(), stringsAsFactors = FALSE )

— 2. Helper Function for Time Logic —

case_when_custom <- function(tm) { if (tm >= “06:30” && tm <= “08:30”) return(“Breakfast”) if (tm >= “11:00” && tm <= “13:00”) return(“Lunch”) if (tm >= “16:00” && tm <= “18:30”) return(“Dinner”) return(“none”) }

— 3. The Improved Main Function —

check_cafeteria <- function(input_id, test_time = NULL) {

# Standardize input: Ensure 4-character string (padding with zeros if numeric) input_id <- sprintf(“%04s”, as.character(input_id))

# Time Logic: Use system time or provided test time current_time <- if(is.null(test_time)) format(Sys.time(), “%H:%M”) else test_time

# Determine the meal type based on time meal_type <- case_when_custom(current_time)

# — LOGIC CHECKS —

# 1: Time Check if (meal_type == “none”) { return(sprintf(“CLOSED: Current time is %s. Please return during meal hours.”, current_time)) }

# 2: Registration Check if (!(input_id %in% students_db$id)) { return(sprintf(“INVALID: ID %s is not Registration.”, input_id)) }

# 3: Eligibility Check student_status <- students_db\(status[students_db\)id == input_id] if (student_status == “non-cafe”) { return(sprintf(“DENIED: ID %s is a Non-cafe student.”, input_id)) }

# 4: Double-dipping Check (Frequency Control) already_eaten <- any(attendance_log\(id == input_id & attendance_log\)meal == meal_type) if (already_eaten) { return(sprintf(“DENIED: ID %s already you have eaten %s today.”, input_id, meal_type)) }

# 5: SUCCESS # Update log in global environment using <<- new_entry <- data.frame(id = input_id, meal = meal_type, timestamp = current_time) attendance_log <<- rbind(attendance_log, new_entry)

return(sprintf(“SUCCESS: Welcome ID %s! Enjoy your %s.”, input_id, meal_type)) }{r} Test 1: Valid Breakfast Access print(check_cafeteria(“0000”, “07:00”))

Test 2: Double Entry Attempt (Same student, same meal)

print(check_cafeteria(“0000”, “07:30”))

Test 3: Non-cafe Student Attempt

print(check_cafeteria(“1000”, “12:00”))

Test 4: Unregistered/Invalid ID

print(check_cafeteria(“9999”, “12:00”))

Test 5: Out of Hours Attempt

print(check_cafeteria(“0112”, “12:35”))

Test 6: Dinner Access

print(check_cafeteria(“2201”, “17:35”))

Test 7: Double Entry Attempt for Dinner

print(check_cafeteria(“2201”, “17:59”))``` ## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.


  1. 02↩︎