DUE: 11:59 pm on Wednesday, September 25

Question 1

For this question, you will write a program that prints all real zeroes to any quadratic equation. A quadratic equation is one in the form of ax^2 + bx + c. Your program will read the coefficients a, b, c and use the quadratic formula to solve the equation. You can assume that the coefficients will be written by the user as valid doubles. You can also assume that all of a, b, c are non-zero.

Part I:

QuadraticEquation.java Autograded

Create a class QuadraticEquation whose constructor accepts as its three arguments the three coefficients a, b, and c. Write a method evaluate() in the class that returns the value of the quadratic equation given a specific input x. You should also write getters for a, b, and c called getA, getB, and getC respectively.

As a brief refresher on getters: a getter is a method that returns the value of one of the object’s fields. It takes no inputs, and has a return type that matches the type of the field it’s returning. For example here, getA() might look like the following:

public double getA() {
    return a;
}

Once implemented correctly, you can test your work like this in main:

// 3x^2 + 4x - 2
QuadraticEquation qe = new QuadraticEquation(3.0, 4.0, -2.0);
System.out.println(qe.getA());
>>> 3.0

// 3*4 + 4*2 - 2
double output = qe.evaluate(2.0);
System.out.println(output);
>>> 18.0

Part II

QuadraticEquationZeroes.java Autograded

Create a class QuadraticEquationZeroes whose constructor receives an object of type QuadraticEquation. Write methods getSmallerSolution() and getLargerSolution() that get the solutions to ax^2 + bx + c = 0, using the quadratic formula, or 0 if no real-valued solution exists.

The quadratic equation helps find the values of x where ax^2 + bx + c = 0. The equation is as follows:

-b ± √(b^2 - 4ac)
------------------
       2a

Extra details:

  • The part under the square root (b^2 - 4ac) is the discriminant, and when the discriminant is negative, there are no real-valued solutions.
  • The ± indicates “plus or minus”, meaning that one solution is found by subtracting that value and the other is found by adding it.
  • getSmallerSolution() should return the smaller value of x that solves the equation. If there is only one solution, then getSmallerSolution() and getLargerSolution() should return the same value.

Part III

QuadraticEquationRunner.java Autograded

Finally, implement a QuadraticEquationRunner class that runs your program. This class should contain a main method that reads user input (i.e. from a Scanner) for a, b, and c, constructs the appropriate objects, and then prints out a message in the form "<a>x^2 + <b>x + <c> has solutions <smaller_solution> and <bigger_solution>". The terms in brackets (e.g. <a> and <smaller_solution>) should be replaced with the appropriate values for that particular run of the program.

For example, when a = 3.0, b = 4.0, c = 1.0, the output should be: 3.0x^2 + 4.0x + 1.0 has solutions -1.0 and -0.3333333333333333.

Note: this portion is automatically graded, so please pay close attention to the expected output formatting. We will take a manual pass at grading this as well, but if you want the automatic points, you’ll need to match the formatting closely.

Question 2 Manually Graded

Have you ever tried to plan a meeting for a group of very busy people with vastly differing schedules? It can be quite challenging. For this question, you will tackle this issue on a micro scale using programming.

Use a class Scheduler to write two methods: projectGroup1() and projectGroup2(). These methods will model two different groups and their members’ schedules. Each method should use a Scanner to ask for the following inputs:

  • a specified day (as Mon, Tue, Wed, Thu, Fri, Sat, or Sun)
  • a specified hour (as a double between 0 and 23)
  • a meeting duration (as a double representing hours, must be at least 0.5)

If any of the provided inputs are not valid (either the wrong type, or not in the acceptable ranges), then the program should exit with a relevant message.

You can assume that the specified hour is only in 15 minute intervals. That is, the hour and duration the user input can only use increments of 0.25. For example:

  • 7:00 AM would be 7.0
  • 4:45 PM would be 16.75
  • A duration of 3 hours and 15 minutes would be 3.25

The methods should each evaluate the input against the members’ schedules, then present a series of messages telling the user whether or not the group can meet at the specified time. More specifically, each problem should print messages based on one of the following results:

  • If all members of the group can meet, print that the group can meet and the meeting time slot.
  • If any one of the group members cannot attend the meeting, print each group member that cannot meet and why that member cannot. Then, print that the meeting cannot be held and how many members would be absent.
  • If none of the group members can attend the meeting, print that no members can attend the meeting along with all of their time conflicts.

The following restrictions apply to all of the problems:

  • No meeting can be scheduled before 9 AM or after 6 PM. Meetings can start at 9 AM at the earliest and end at 6 PM at the latest.
  • A meeting duration must be at least 0.5 hours, or 30 minutes.
  • The bounds of times will be inclusive. For example:
    • A 1 hour meeting starting at 5 PM and going until 6 PM will be allowed
    • A 1 hour meeting starting at 2:15 PM and going to 3:15 PM will be allowed, even if someone has a commitment starting at 3:15 PM.
  • Include every time conflict in your messages. This means that if 3 people in a group cannot attend a meeting, 3 messages should be printed detailing the conflict.

These requirements are very intricate! Try to map out with pencil and paper the schedules and their overlaps to understand all possible cases. Your program will be tested very thoroughly.


Example: projectGroup0()

Alfonso and Cynthia are working on a project together over summer break. They are generally not very busy over the summer, but Cynthia works a part time job on Fridays at a coffee shop from 6 AM to 10 AM. Alfonso has to cook dinner starting at 4 PM every day and cannot do anything afterwards. Use projectGroup0() to model when Alfonso and Cynthia can schedule their meeting.

public static void projectGroup0() {

    // Set up the Scanner for taking user input
    Scanner scan = new Scanner(System.in);

    // Prompt for day of week and reject if invalid
    System.out.println("Enter meeting day (Mon, Tue, Wed, Thu, Fri, Sat, Sun)");
    String day = scan.next();
    if (!day.equals("Mon") && !day.equals("Tue") && !day.equals("Wed") 
            && !day.equals("Thu") && !day.equals("Fri")
            && !day.equals("Sat") && !day.equals("Sun")) {
        System.out.println("Invalid day!");
        return;
    }

    // Prompt for hour of day (24 hour time) and reject if invalid
    System.out.println("Enter meeting start time (hours only, 00 to 23)");
    double startHour = scan.nextDouble();
    if (startHour < 0 || startHour > 23) {
        System.out.println("Invalid hour!");
        return;
    }

    // Prompt for duration and reject if invalid
    System.out.println("Enter meeting duration (in hours, >= 30 minutes)");
    double duration = scan.nextDouble();
    if (duration < 0.5) {
        System.out.println("Invalid duration!");
        return;
    }

    double endHour = startHour + duration;
    int absentees = 0;
    // No meetings before 9 AM or after 6 PM
    if ((startHour < 9 || startHour > 18) || (endHour < 9 || endHour > 18)) {
      System.out.println("Beyond working hours.");
    } else {
      // Alfonso cooks dinner starting at 4 PM every day
      if (endHour > 16) {
        System.out.println("Alfonso cannot attend this meeting, as it would conflict with his dinner.");
        absentees++;
      }
      // Cynthia works part-time on Fridays from 6 AM to 10 AM
      if (day.equals("Fri") && (startHour < 10)) {
        System.out.println("Cynthia cannot attend this meeting, as it would conflict with her part time job.");
        absentees++;
      }
      // Check absentees
      if (absentees == 2) {
        System.out.println("Nobody can attend this meeting!");
      } else if (absentees != 0) {
        System.out.println("This meeting cannot be scheduled, there would be " + absentees + " attendee(s) absent.");
      } else {
        // There are no conflicts
        System.out.println("This meeting can be scheduled. It will be on: " + day + ", from " + startHour + " to " + endHour);
      }
    }
}

Sample Input/Output

Invalid Day

Enter meeting day (Mon, Tue, Wed, Thu, Fri, Sat, Sun)
gru

Beyond Working Hours

Enter meeting day (Mon, Tue, Wed, Thu, Fri, Sat, Sun)
Sun
Enter meeting start time (hours only, 00 to 23)
4
Enter meeting duration (in hours, >= 30 minutes)
3
Beyond working hours.

Valid Meeting

Enter meeting day (Mon, Tue, Wed, Thu, Fri, Sat, Sun)
Wed
Enter meeting start time (hours only, 00 to 23)
10
Enter meeting duration (in hours, >= 30 minutes)
3
This meeting can be scheduled. It will be on: Wed, from 10.0 to 13.0

Alfonso Absent

Enter meeting day (Mon, Tue, Wed, Thu, Fri, Sat, Sun)
Fri
Enter meeting start time (hours only, 00 to 23)
17
Enter meeting duration (in hours, >= 30 minutes)
1
Alfonso cannot attend this meeting, as it would conflict with his dinner.
This meeting cannot be scheduled, there would be 1 attendee(s) absent.

Cynthia Absent

Enter meeting day (Mon, Tue, Wed, Thu, Fri, Sat, Sun)
Fri
Enter meeting start time (hours only, 00 to 23)
9
Enter meeting duration (in hours, >= 30 minutes)
2
Cynthia cannot attend this meeting, as it would conflict with her part time job.
This meeting cannot be scheduled, there would be 1 attendee(s) absent.

Project Group 1

Marshall wants to meet up with his partner Hank to discuss their final project for CIT 5910. They are both first-year MCIT students with the exact same schedule:

  • CIT 5910 on Monday & Wednesday, 3:30-5:00 PM
  • CIT 5920 on Tuesday & Thursday, 5:15-6:45 PM
  • CIT 5930 on Tuesday & Thursday, 12:00-1:30 PM

Additionally,

  • Assume there is no recitation for any of the classes
  • Marshall has tennis practice on Saturdays from 1 PM to 4 PM.

Write a method projectGroup1() to model when Marshall and Hank can schedule their meeting.

Project Group 2

A group of friends play board games once a week. They want to plan when they can play board games, and they will only play when all 3 members are available.

  • All three agree to not play board games on Fridays.
  • Chase has a Math class on Mondays and Wednesdays from 10:15-11:45 AM and a Design class on Monday from 1:45-3:15 PM.
  • Janine cannot attend on Tuesday or Thursday at all due to her class schedule. She has band practice on the weekends (Saturday and Sunday) from 8 AM to 1 PM.
  • Emilia cannot attend on Monday or Wednesday due to her class schedule. If an event is scheduled on the weekend (Saturday or Sunday), she will only attend if the event is at most 2 hours long.

Write a method projectGroup2() to model when this group can host their weekly board game sessions.

Submission

Submit QuadraticEquation.java, QuadraticEquationZeroes.java, QuadraticEquationRunner.java from Q1 and Scheduler.java from Q2 to Gradescope.

Ensure that your files do not have a package header! Specifically, the first lines of your file should not read package xyz or similar.

Specifically, please find these files locally on your file system. By default, they will be found in a folder called IdeaProjects, often in your user’s directory. You should select each of the files from the specific project’s src directory and upload them as files (not as a directory, and preferably not as a .zip either). If you need help, please reach out on Ed or in Office Hours.