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

) 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,...
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
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file...
Program Requirements: Write a C++ program according to the following requirements: 1.   Open the data file Electricity.txt and read each column into an array (8 arrays total). 2.   Also create 2 arrays for the following: Total Fossil Fuel Energy (sum of all fossil fuels) Total Renewable Energy (sum of all renewable sources) Electricity.txt: Net generation United States all sectors monthly https://www.eia.gov/electricity/data/browser/ Source: U.S. Energy Information Administration All values in thousands of megawatthours Year   all fuels   coal       natural gas   nuclear  ...
Please write queries based on the following requirements using labdata.sql. For each question, you are required...
Please write queries based on the following requirements using labdata.sql. For each question, you are required to submit 1) SQL query code; 2) a screen shot of your query result. You should copy and paste your SQL query code to the word document instead of taking a screenshot of your code. Missing either part for each question will result in 0 for this question. List all the order date and the number of orders placed on each date. Rank your...
You can complete this with Eclipse (or BlueJ if you like). Here are the requirements: Write...
You can complete this with Eclipse (or BlueJ if you like). Here are the requirements: Write a Person class. A Person has properties of name and age. You construct a Person object by providing the name and age in that order. We want to be able to get and set the name. We want to be able to get the age and to increase the age by 1 when the person has a birthday. What will the object need to...
Write  the following functions using the following structure for a point. struct Point { double x, y;...
Write  the following functions using the following structure for a point. struct Point { double x, y; }; (a) A function that passes a point and returns an integer (1, 2, 3, or 4) to indicate in which quadrant the point is located int findQuadrant(struct Point testpoint) { } (b) A function that passes two points and returns the distance between them. float distance(struct Point point1, struct Point point2) { } (c) A function that passes two points and generate the...
Write a program (your choice!) that fulfills all the requirements below. The final product should include...
Write a program (your choice!) that fulfills all the requirements below. The final product should include the pseudocode and flowchart for the entire program. Variables of each data type String, Integer, Real, Boolean Must contain at least one type of calculation Minimum of 3 modules/functions At least 2 decision structures IF, IF-ELSE, IF-ELSE IF At least 1 type of loop WHILE or FOR At least 1 array/list
Write a program that validates passwords based on the following requirements: • must be at least...
Write a program that validates passwords based on the following requirements: • must be at least 8 characters in length • must include at least 1 alphabet character • must include at least 1 number The program should implement the password checker using a function name validate_password, which takes two strings as input and returns one of the following: • 0 if the passwords match and fulfill all requirements • 1 if the passwords are not the same length •...
Write a program that validates passwords based on the following requirements: • must be at least...
Write a program that validates passwords based on the following requirements: • must be at least 8 characters in length • must include at least 1 alphabet character • must include at least 1 number The program should implement the password checker using a function name validate_password, which takes two strings as input and returns one of the following: • 0 if the passwords match and fulfill all requirements • 1 if the passwords are not the same length •...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT