TV Show Ratings Program In Java
Requirement/Specification
This program is to show the percentages of those who watch a TV show regularly. The distribution of the percentages is on the basis of gender (male and female) and age (below 30 or over 30). The Title of the program is TV show ratings developed by Wong Zhi Hui Chester, student number 33369733 on October 12, 2018. This program is developed in Java using netbeans. A file named ques1.java is developed for the same.
Requirement/Specification
The program is supposed to provide a distribution of percentages of people who watch a particular TV show for which survey is done. The distribution of the percentages is divided into males and females and for the people who are of age 30 or above or below 30. Each survey entered by the user is stored in a memory for the evaluation and corresponding calculations are done for the same. When all the surveys are entered by the user, then a table distribution is shown to the user for analysis.
User Guide
To access, compile and run the program, please follow the following commands:
- Open terminal and navigate to the directory in which ques1.java file is saved using “cd” command.
- Type – javac ques1.java This command will compile the program and a .class file will be generated.
- Then, to run the program type – java ques1
- The program will be executed and you can enter the surveys and execute it.
Limitations
There is only one limitation to this program, while entering the age of any person in the program, if user enters anything other than an integer, the program will abort. As there is no exception handling in the program.
public static void StudentInfo(){
System.out.println(“Name:tttWong Zhi Hui Chester”);
System.out.println(“Student no.tt33369733”);
System.out.println(“Mode of enrollmenttfull time”);
System.out.println(“Tutor namettMr Chong“);
System.out.println(“AttendancettEvery Thursday, 10:30am to 1230pm”);
public static int inputAge(Scanner scan){
System.out.println(“Please enter the person’s age (1..110):”);
age = Integer.parseInt(scan.nextLine());
}while(age < 1 || age > 110);
return age;
public static String input(Scanner scan, String display, String option1, String option2){
System.out.println(display);
ans = scan.nextLine();
}while(!ans.equalsIgnoreCase(option1) && !ans.equalsIgnoreCase(option2));
return ans.toUpperCase();
public static void main(String[] args)
StudentInfo();
System.out.println(“nnn”);
String anotherShow;
Scanner scan = new Scanner(System.in);
double femaleBelow30 = 0, femaleOver30 = 0;
double maleBelow30 = 0, maleOver30 = 0;
String repeat;
int age = inputAge(scan);
String gender = input(scan, “Please enter the person’s gender (M/F):”, “m”, “f”);
String watchShow = input(scan, “Please enter whether the person watches the show regularly (Y/N):”, “y”, if (watchShow.equals(“Y”)) {
switch (gender) {
case “M”:
if (age < 30) {
maleBelow30++;
} else {
maleOver30++;
break;
case “F”:
if (age < 30) {
femaleBelow30++;
} else {
repeat = input(scan, “Do you want to enter another person’s details (Y/N)?”, “y”, “n”);
} while (!repeat.equalsIgnoreCase(“n”));
double total = femaleBelow30 + femaleOver30 + maleBelow30 + maleOver30;
System.out.println(“Distribution of viewers who watch the show regularly”);
System.out.println(“————————————————————————————————–“);
System.out.println(“Gendert% Under 30t% 30 or Overt% Total”);
System.out.println(“————————————————————————————————–“);
femaleBelow30 = (femaleBelow30 / total) * 100;
femaleOver30 = (femaleOver30 / total) * 100;
double female = femaleBelow30 + femaleOver30;
maleBelow30 = (maleBelow30 / total) * 100;
maleOver30 = (maleOver30 / total) * 100;
double male = maleBelow30 + maleOver30;
System.out.println(“Femalett” + Math.round(femaleBelow30) + “tt” + Math.round(femaleOver30) + “tt” + Math.round(female));
System.out.println(“Malett” + Math.round(maleBelow30) + “tt” + Math.round(maleOver30) + “tt” + Math.round(male));
System.out.println(“————————————————————————————————–“);
System.out.println(“Totaltt” + Math.round(femaleBelow30 + maleBelow30) + “tt” + Math.round(femaleOver30 + maleOver30) + “tt” + Math.round(female + male));
anotherShow = input(scan, “Do you want to enter for another show (Y/N)?”, “y”, “n”);
}while(!anotherShow.equalsIgnoreCase(“n”));