In: Computer Science
3.44444444 The following are requirements of ALL programs that you write from this point on!
You must write instructions to the screen to tell the user exactly what you want him/her to do. Your instructions must be very clear and descriptive, and should not contain any spelling or grammar errors.
You MUST choose variable names that describe the contents of the variable. Unless I specifically tell you to do so, single character variable names will not be acceptable unless you are using them to hold temporary data.
In addition to putting your name at the top of the program, you should also add a comment, 1-2 lines long, to briefly describe what the program does.
You MUST follow proper indention techniques in your code as discussed in class, and seen in the examples in your book. If you aren't sure you have the indention correct, you can use the correct indention option from the source menu in Eclipse.
Your source code must be NEAT and easy to read. Declare all of your variables at the beginning of the program. Add blank lines between sections of code to space out your program more and make the sections easier to see.
You MUST add comments all throughout your code to explain what your code is trying to do.
Pay close attention to the directions!! Make absolutely certain that you are doing exactly what the assignment asks you to do. If you don't understand the problem, make sure to ask your instructor or an assistant.
This is the last time you will be reminded of these requirements-- you must remember to start doing them in all of your programs from now on!
Part 3
Create a new Java class inside your project folder.
The name of the class should be: MeetingTimes
Write a program that determines the best possible meeting time for four people. The possibilities for meeting times are 8:00-12:00, 12:00-18:00 or 18:00-23:00.
You should begin by asking the first user to choose a meeting time. The user should enter the number 1 for the 8:00-12:00 meeting time, the number 2 for the 12:00-18:00 meeting time, or the number 3 for the 18:00-23:00 meeting time.
Make sure that you display the three options on the screen for the user.
The program will then proceed to do the same thing three more times (for the other three people).
At the conclusion, the program should display on the screen the best possible meeting time. For our purposes, this will be the time block chosen by a majority of the people. In the event that there is a tie for time blocks, choose the earliest one.
The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics:
Meeting Times:
1) 8:00-12:00 2) 12:00-18:00 3) 18:00-23:00
Choose option 1, 2, or 3.
Enter the best time available for person 1: 2
Enter the best time available for person 2: 1
Enter the best time available for person 3: 3
Enter the best time available for person 4: 2
The best meeting time available is:
12:00 - 18:00
Here is another example run of the program:
Meeting Times:
1) 8:00-12:00 2) 12:00-18:00 3) 18:00-23:00
Choose option 1, 2, or 3.
Enter the best time available for person 1: 3
Enter the best time available for person 2: 1
Enter the best time available for person 3: 1
Enter the best time available for person 4: 3
The best meeting time available is:
8:00 - 12:00
Hint:
Use three separate counter variables to keep track of the total number of people who entered option 1, total number for option 2, and total for option 3. As the user enters each option, use IF statements to decide which option was chosen, and then update the appropriate counter accordingly
package myProject;
import java.util.*;
//Class MettingTime definition
public class MeetingTime
{
//To display menu
static void menu()
{
System.out.println("1) 8:00-12:00
2) 12:00-18:00 3) 18:00-23:00");
System.out.println("Choose option
1, 2, or 3.");
}//End of method menu
//Main method
public static void main(String ss[])
{
//Method menu called
menu();
//Scanner class object created to
accept data
Scanner sc = new
Scanner(System.in);
//option variable to accept user
time option. c variable for loop counter
int option, c;
//integer type array with size 3
created to store the frequency of time entered by the user
int timeFrequency[] = new
int[3];
//Loops zero to 3 for 4 person
time
for(c = 0; c < 4;)
{
System.out.println("Enter the best time available for person : " +
(c + 1));
//Accepts user
option
option =
sc.nextInt();
//If option is
one, then zero index position of the timefrequency is incremented
by one
if(option ==
1)
{
timeFrequency[0]++;
//Loop Counter is incremented for valid
entry
c++;
}//End of
if
//If option is
two, then one index position of the timefrequency is incremented by
one
else if(option
== 2)
{
timeFrequency[1]++;
//Loop Counter is incremented for valid
entry
c++;
}//End of else
if
//If option is
three, then two index position of the timefrequency is incremented
by one
else if(option
== 3)
{
timeFrequency[2]++;
//Loop Counter is incremented for valid
entry
c++;
}
//Otherwise
invalid option error message displayed. Counter is not
incremented.
else
System.out.println("Wrong Option! Try
again.");
}//End of for loop
//Initially timeFrequency zero
index position considered as maximum
int max = timeFrequency[0];
//Initially time is set to
zero
int time = 0;
//Loops from 1 to 2 for 3 frequency
index position.
//Loop starts from 1 because zero
position is already considered above.
for(c = 1; c < 3; c++)
{
//If current
timeFrequency is greater than the max
if(timeFrequency[c] > max)
{
//max is update to the timeFrequency current
position
max = timeFrequency[c];
//time is updated to loop current value
time = c;
}//End of
if
}//End of loop
//Displays the best time for
meeting
System.out.println("The best
meeting time available is:");
//If time is
zero
if(time ==
0)
System.out.println("8:00 - 12:00");
//If time is
1
else if(time ==
1)
System.out.println("12:00-18:00");
//otherwise
else
System.out.println("18:00-23:00");
}//End of main method
}//End of class
Output 1:
1) 8:00-12:00 2) 12:00-18:00 3) 18:00-23:00
Choose option 1, 2, or 3.
Enter the best time available for person : 1
5
Wrong Option! Try again.
Enter the best time available for person : 1
1
Enter the best time available for person : 2
2
Enter the best time available for person : 3
1
Enter the best time available for person : 4
1
The best meeting time available is:
8:00 - 12:00
Output 2:
1) 8:00-12:00 2) 12:00-18:00 3) 18:00-23:00
Choose option 1, 2, or 3.
Enter the best time available for person : 1
1
Enter the best time available for person : 2
3
Enter the best time available for person : 3
3
Enter the best time available for person : 4
2
The best meeting time available is:
18:00-23:00
Output 3:
1) 8:00-12:00 2) 12:00-18:00 3) 18:00-23:00
Choose option 1, 2, or 3.
Enter the best time available for person : 1
2
Enter the best time available for person : 2
1
Enter the best time available for person : 3
2
Enter the best time available for person : 4
3
The best meeting time available is:
12:00-18:00