Question
JAVA Please help me fix my time validation on my program so that it will work The hours of operation are 7am to 3pm. I
JAVA
Please help me fix my time validation on my program so that it will work
The hours of operation are 7am to 3pm. I made what might be the problem areas bold.
//Import the neccesary libraries import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; import java.text.SimpleDateFormat; import java.util.Date;
//Create the Pet Groomer class public class PetGroomer { //Declare neccesary class variables static String customerName; //Variable for customer name static String serviceType; //Variable for the type of grooming service the customer wants preformed static double servicePrice; //Variable for the cost of the service static String apptDate; //Variable for an appointment day static String apptTime; //Variable for an appointment time static boolean homeOption; //Option for home grooming static double homeFee = 25.0; //Variable for home grooming fee (additional charge) static String startTime = 07; static String closingTime = 03;
//Create main method public static void main(String[] args) { //Create scanner for user input Scanner sc = new Scanner(System.in);
//Display welcome message System.out.print("Welcome to Lucy's Pet Spa!");
//Display pet spa hours of operation displayTimes(); //Collect & store user information System.out.print("Please enter your name: "); customerName = sc.nextLine();
//Display menu with service options and prices & get user input displayMenu(); int menuOption = sc.nextInt();
//Switch statement for menu options switch (menuOption) { case 1: serviceType = "Bath with Brush and Blowout"; servicePrice = 65.50; break; case 2: serviceType = "Full Grooming"; servicePrice = 150.0; break; case 3: serviceType = "Tooth Brush & Nail Trim"; servicePrice = 20.75; break; case 4: serviceType = "Anal Expression"; servicePrice = 15.75; break; default: System.out.println("Invalid option. Please Select an option from the menu."); break; }
//Ask for and get an appointment day from the customer System.out.print("Please enter your prefered appointment day in the following format (MM/dd/yyyy): "); apptDate = sc.next();
//Ask for and get an appointment time from the customer System.out.print("Enter appointment time (hh:mm): "); apptTime = sc.next();
//Check appointment time is within the operating hours of the pet spa if (appTimeInput.equals(startTime) || appTimeInput.equals(closingTime)) { System.out.println("Sorry we are not open at that time. Please pick a time that is within our operating hours.");
//Ask for and get an appointment time from the customer System.out.print("Enter appointment time (hh:mm): "); apptTime = sc.next(); }
//Ask if the customer would like a home groom System.out.print("Would you like us to come to your home to groom your pet? (yes/no): "); String homeOptionInput = sc.next();
//If statement to add home grooming fee if necessray if (homeOptionInput.equalsIgnoreCase("yes")) { homeOption = true; servicePrice += homeFee; } else { homeOption = false; }
//Display customer order summary with price System.out.println(" Order Summary: "); System.out.println("Customer name: " + customerName); System.out.println("Service type: " + serviceType); System.out.println("Service price: $" + servicePrice); System.out.println("Appointment date: " + apptDate); System.out.println("Appointment time: " + apptTime); System.out.println("House service: " + homeOption);
//Check for errors durning execution try { FileWriter writer = new FileWriter("order.txt"); writer.write("Order summary: "); writer.write("Customer name: " + customerName + " "); writer.write("Service type: " + serviceType + " "); writer.write("Service price: $" + servicePrice + " "); writer.write("Appointment date: " + apptDate + " "); writer.write("Appointment time: " + apptTime + " "); writer.write("House service: " + homeOption + " "); writer.close(); } catch (IOException e) { System.out.println("An error occurred while creating the file."); } }
//Method for displaying the services menu public static void displayMenu() { System.out.println("Please select the service that you would like: "); System.out.println("Services and Prices:"); System.out.println("1. Bath with Brush and Blowout....$65.50"); System.out.println("2. Full Grooming..................$150.0"); System.out.println("3. Tooth Brush & Nail Trim........$20.75"); System.out.println("4. Anal Expression................$15.75"); }
//Method to display hours of operation public static void displayTimes() { System.out.println("Come any seven days of the week to groom your furry friend!"); System.out.println("We are open Sunday through Saturday."); System.out.println("We are open from 7am to 3pm."); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started