Question

In: Computer Science

3.44444444 The following are requirements of ALL programs that you write from this point on! You...

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

Solutions

Expert Solution

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


Related Solutions

Requirements:   You are to write a class called Point – this will represent a geometric point...
Requirements:   You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints).   Point should have the following: Data:   that hold the x-value and the y-value. They should be ints and must be private. Constructors: A default constructor that will set the values to (2,-7) A parameterized constructor that will receive 2 ints (x then y) and set the data to what is received. A copy...
Requirements:   You are to write a class called Point – this will represent a geometric point...
Requirements:   You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints).   Point should have the following: Data:   that hold the x-value and the y-value. They should be ints and must be private. Constructors: A default constructor that will set the values to (2,-7) A parameterized constructor that will receive 2 ints (x then y) and set the data to what is received. A copy...
) Use functions and arrays to complete the following programs. Requirements: • You should use the...
) Use functions and arrays to complete the following programs. Requirements: • You should use the divide-and-conquer strategy and write multiple functions. • You should always use arrays for the data sequences. • You should always use const int to define the sizes of your arrays. a. Write a C++ program. The program first asks the user to enter 4 numbers to form Sequence 1. Then the program asks the user to enter 8 numbers to form Sequence 2. Finally,...
1. Write a Java program from scratch that meets the following requirements: a. The program is...
1. Write a Java program from scratch that meets the following requirements: a. The program is in a file called Duplicates.java that defines a class called Duplicates (upper/lower case matters) b. The program includes a Java method called noDuplicates that takes an array of integers and returns true if all the integers in that array are distinct (i.e., no duplicates). Otherwise it returns false. Make sure the method is public static. example tests: noDuplicates({}) returns true noDuplicates({-1, 1}) returns true...
Write a program in C as per following requirements: a) It takes two fields from the...
Write a program in C as per following requirements: a) It takes two fields from the user 1) NAME and 2) age. Hint: (Take the name of employee in an array of 50 characters). b) It saves the data given by the user in a doubly link list. c) As soon a record is entered by the user it should be given a record number or serial number. d) Program should have a menu for a. Entering new data. b....
Write some python programs which demonstrate the following concepts: Input data of all the variable types...
Write some python programs which demonstrate the following concepts: Input data of all the variable types we've covered so far (https://realpython.com/python-variables/) Test input of strings with various quoting styles as previously discussed Output all the variables you read. Format output of all variables to create columnar output. Format output of numbers to 2 decimal places Output using both the string formatting and the 'f' formatted string literals notation. TURN IN Submit your source code and execution of your code.
projectOne (Please be sure to include screenshots of the test runs for all programs) A. write...
projectOne (Please be sure to include screenshots of the test runs for all programs) A. write a program the computes nx and store the result into y You can use y = Math.pow( Mantissa, exponent) Requirements: Besides main() your program must have one method with two parameters, one double and one int n and x are positive numbers read from the keyboard if the user makes an entry that does not meet this criteria, the user must be given to...
Write any java programming to meet the following requirements. Your project must meet the following requirements:...
Write any java programming to meet the following requirements. Your project must meet the following requirements: 1. Specify input specification      Design input 2. Specify Output Specification     Design Output 3. The class must include set methods and get methods ( with or without parameters both) 4. Must include Array structure 5. Must include Input or Output Files or both 6. Demonstrate your knowledge of an Applet
check the following code: is the requirements correct ? if not solve it . All the...
check the following code: is the requirements correct ? if not solve it . All the styles must be in a document style sheet. YOU ARE NOT ALLOWED TO USE THE type ATTRIBUTE ON THE LIST, you must use CSS to apply the style. <!DOCTYPE html> <html> <head> <title> car list</title> <style> body {background-color: powderblue;} h1   {color: blue;} p    {color: red;} </style> </head> <body> <style type="text/css"> ol{list-style-type:upper-roman;} ol ol{list-style-type:upper-alpha;} ol ol ol{list-style-type:decimal;} li.compact{background-color:pink;} li.midsize{background-color:blue;} li.sports{background- color:red;} ol.compact{background-color:pink;} ol.midsize{background-color:blue;} ol.sports{background-color:red;} </style>...
write these programs in c++ using getch() function Write a program that reads 20 integers from...
write these programs in c++ using getch() function Write a program that reads 20 integers from a user using a while loop and determines and prints whether each of those integers is an even number. Write a program that uses a while statement to read integers from a user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters -1.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT