The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
I would like solution for 2 java questions. Thanks.
Question 1.
A television rating service makes a telephone survey of the viewing audience to sample the popularity
of TV shows. When a call is made concerning a particular show, the age (in the range 1 to 110) and
gender (male/female) of the person called, as well as whether that person watches the show regularly
(Y/N), are recorded. Design, write in Java, test and document a program to process the data gathered for a show. The
program is to output the total number of people called, the number who said they watch the show
regularly, and the percentage of those who watch the show regularly as in the example below. The total number of people called = 20
The number of people who watch the show regularly = 8
The percentage of those who watch the show regularly = 40% The program should also print a table showing the percentages of those who watch the show regularly
according to gender and age categories as in the example below. Distribution of viewers who watch the show regularly
-------------------------------------------------------------------------------------------------Gender % Under 30 % 30 or Over % Total
-------------------------------------------------------------------------------------------------Female
Male 44
23 17
16 61
39 -------------------------------------------------------------------------------------------------Total 67 33 100 The percentages in the table are rounded to the nearest whole number and are percentages of all those
who watch the show regularly. Thus, the sum of percentages in the last column of the table must be
100% (ignoring any rounding error). Sample input:
Please enter next person’s age (1..110):
25
Please enter this person’s gender (M/F):
M
Please enter whether this person watches the show regularly (Y/N):
Y
Do you want to enter another person’s details (Y/N)?
Y The program should repeat until the user does not want to enter any more survey data for a particular
show.
The input data is to be validated. For example, if the user types in an integer outside the range 1 to 110
(for age), a letter other than ‘M’ or ‘m’ (for male), ‘F’ or ‘f’ (for female), ‘Y’ or ‘y’ (watches
regularly), ‘N’ or ‘n’ (does not watch regularly), the program should output an appropriate error
message and re-prompt for input until the user enters the correct data. Your program should have an outer loop that allows the user to repeat the above processing for a
different show. The processing is repeated until the user indicates that they want to end the program. The program should be well-structured and should have a reasonable set of methods in addition to the
main method.
Devise suitable test data to test all sections of program code. The test data together with test results
should be submitted as part of your external documentation. The program should also include a method (eg, StudentInfo( )) to output your student details (name,
student number, mode of enrolment (i.e., internal or external), tutor name, tutorial attendance day and
time) at the start of program results. Note that this question does not require you to define a separate class for the person record and a
separate client program. However you are welcome to do so if you wish. Also note that the question does not require the use of arrays. Question 2.
Design, write in Java, test and document a program to calculate the number of minutes between one
time and another. Here are some examples: Note that no classes for time and date are allow to be used for this question. TIME DIFFERENCE Enter first time (hh: mm a/pm): 12:56pm
Enter second time (hh: mm a/pm): 1:03pm The difference is 7 minutes Do you wish to continue (Y/N)?
Y TIME DIFFERENCE Enter first time (hh: mm a/pm): 1:03pm
Enter second time (hh: mm a/pm): 12:56pm The difference is 1433 minutes Do you wish to continue (Y/N)?
Y TIME DIFFERENCE Enter first time ( hh: mm a/pm): 1:03pm
Enter second time ( hh: mm a/pm): 12:65pm ERROR: the second time is not valid Do you wish to continue (Y/N)?
Y TIME DIFFERENCE Enter first time ( hh: mm a/pm): 8:30 am
Enter second time ( hh: mm a/pm): 5:30 pm The difference is 540 minutes Do you wish to continue (Y/N)?
N The times are to be entered (on one line) in the 12 hour format with hours (1-2 digits), colon, minutes
(2 digits) and then the string “am” or “pm”. You may also allow spaces. The program should be well-structured and should have a reasonable set of methods in addition to the
main method. It should use a good coding style, proper indentation, meaningful identifiers and
appropriate comments throughout. The program should also include a method (eg, StudentInfo( )) to output your student details (name, student number, mode of enrolment (i.e., internal or external), tutor name, tutorial attendance day and
time) at the start of program results. Devise suitable test data to test all sections of program code. The test data together with test results
should be submitted as part of your external documentation. Hint:
1. You may consider using the following methods from the Java String class:
indexOf(int char)
indexOf(int char, int fromIndex)
indexOf(String str)
indexOf(String str, int fromIndex)
to work out the index position of a character or a substring within a string; 2. and then use
substring(int beginIndex, int endIndex)
substring(int beginIndex)
to extract the different parts of a string; 3. and then use wrapper Integer class method Integer.parseInt(String str) to convert the string
such as “12” into its numerical representation (see pages 447-452 of Savitch 7 th Edition or
Topic 4 Lecture notes).
-----------