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

Question Is-- •Write a program that allows students to schedule appointment at e

ID: 3899690 • Letter: Q

Question

Question Is--

•Write a program that allows students to schedule appointment at either 1 , 2, 3, 4, 5, or 6 o’clock pm. Use an array of six strings to store the names for the time slots. Write a loop that iterates as long as the array has a free space. Within a try block, allow the user to enter a time and a name. IF the time is free, put the name in the array. If the time is not free, throw a TimeInUseException. If the time is not valid, throw an InvalidTimeException. Use a catch block for each different kind of exception.

import java.util.Scanner;
import java.io.*;
import java.util.*;

public class Scheduler {
public static void main(String[] args) {
  String[][] table = new String [6][2];
  String studentName;
  String time = "";
  
  table[0][0] = "1";
  table[1][0] = "2";
  table[2][0] = "3";
  table[3][0] = "4";
  table[4][0] = "5";
  table[5][0] = "6";
  
  System.out.println("Welcome to the Appointment sceduler");
  System.out.println("You can schedule an appointment at "
    + "1, 2, 3, 4, 5, or 6PM.");
  Scanner keyboard = new Scanner(System.in);
  boolean isFree = true;
  int fullCounter = 0;
  while(isFree) {
   if(fullCounter < 6) {
    System.out.println("What is your name?");
    studentName = keyboard.nextLine();
    System.out.println(studentName);
    System.out.println("When would you like the appointment?");
    time = keyboard.nextLine();
    try {
     for(int i = 0; i < 6; i++)
      if((!time.equals(table[i][0])) &&
        (Integer.parseInt(time)) > 6)
       throw new InvalidTimeException();
       
    }catch(InvalidTimeException e) {
     System.out.println(e.getMessage());
    }
    for(int i = 0; i < 6; i++) {
     try {
      if(time.equals(table[i][0])) {
       if(table[i][1] != null) {
        throw new TimeInUseException();
       }
       else {
        table[i][1] = studentName;
        fullCounter++;
        break;
       }
      }
     }catch(TimeInUseException e) {
      System.out.println(e.getMessage());
     }
    }
   }
   else {
    System.out.println("time table is full of appointment");
    isFree = false;
   }
  }
}
class InvalidTimeException extends Exception{
  public InvalidTimeException() {
   super();
  }
  public InvalidTimeException(String message) {
   super(message);
  }
}
class TimeInUseException extends Exception{
  public TimeInUseException() {
   super();
  }
  public TimeInUseException(String message) {
   super(message);
  }
}
}

try {
     for(int i = 0; i < 6; i++)
      if((!time.equals(table[i][0])) &&
        (Integer.parseInt(time)) > 6)
       throw new InvalidTimeException();
    }

throw new InvalidTimeException(); <<<<< this part occur error! why?? please tell meee!!!

eclipse says"No enclosing instance of type Scheduler is accessible. Must qualify the allocation with an enclosing instance of
type Scheduler (e.g. x.new A() where x is an instance of Scheduler)."

the language is JAVA!

Explanation / Answer

Mistake: You defined classes InvalidTimeException  and TimeInUseException inside Scheduler class. So, if you want to use these inner classes then you need to create a Scheduler object. Instead you can keep these two classes outside the Scheduler class.

Modified Code:

import java.util.Scanner;

import java.io.*;

import java.util.*;

public class Scheduler {

public static void main(String[] args) {

String[][] table = new String [6][2];

String studentName;

String time = "";

table[0][0] = "1";

table[1][0] = "2";

table[2][0] = "3";

table[3][0] = "4";

table[4][0] = "5";

table[5][0] = "6";

System.out.println("Welcome to the Appointment sceduler");

System.out.println("You can schedule an appointment at "

    + "1, 2, 3, 4, 5, or 6PM.");

Scanner keyboard = new Scanner(System.in);

boolean isFree = true;

int fullCounter = 0;

while(isFree) {

   if(fullCounter < 6) {

    System.out.println("What is your name?");

    studentName = keyboard.nextLine();

    System.out.println(studentName);

    System.out.println("When would you like the appointment?");

    time = keyboard.nextLine();

    try {

     for(int i = 0; i < 6; i++)

      if((!time.equals(table[i][0])) &&

        (Integer.parseInt(time)) > 6)

       throw new InvalidTimeException();

      

    }catch(InvalidTimeException e) {

     System.out.println(e.getMessage());

    }

    for(int i = 0; i < 6; i++) {

     try {

      if(time.equals(table[i][0])) {

       if(table[i][1] != null) {

        throw new TimeInUseException();

       }

       else {

        table[i][1] = studentName;

        fullCounter++;

        break;

       }

      }

     }catch(TimeInUseException e) {

      System.out.println(e.getMessage());

     }

    }

   }

   else {

    System.out.println("time table is full of appointment");

    isFree = false;

   }

}

}

}

class InvalidTimeException extends Exception{

public InvalidTimeException() {

   super();

}

public InvalidTimeException(String message) {

   super(message);

}

}

class TimeInUseException extends Exception{

public TimeInUseException() {

   super();

}

public TimeInUseException(String message) {

   super(message);

}

}

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