You are on page 1of 3

CE251 Java Programming Practical Exam on 19th Nov 2021

Practical Task 2:
Use the concept of user defined exception in this program.
One Expert talk was organized for the subject CE251 Java Programming.
5 students gave the feedback for expert.
Only one Question was asked to each Student:
1. How was the content delivered by the expert.
Options were: Excellent, Very Good, Average, Poor
Print the following data:
Name of the Expert:
Display the percentage of feedback given by students for the expert.
For example 70% gave excellent feedback,
15 % gave very good feedback,
10% gave average feedback.
5% gave poor feedback.

Code :

package practicals;

import java.lang.reflect.Array;
import java.util.Scanner;

@SuppressWarnings("unused")
class UserException extends Exception
{
/**
*
*/
private static final long serialVersionUID = 1L;

public UserException(String s)
{
super(s);
}
}
class Feedback1 {
Scanner sc=new Scanner(System.in);
byte Fback;
void Question()
{
System.out.println("How was the content delivered by the expert : ");
System.out.println("Enter 1.Excellent\n2.Very good\n3.Average\n4.Poor");
Fback=sc.nextByte();
try
{
if (Fback > 4)
{
Fback=0;
throw new UserException("Enter valid input");
}

}
catch (UserException ex)
{
System.out.println(ex.getMessage());
}
}
}

public class Task {

public static void main(String[] args) {


Scanner in = new Scanner(System.in);
Feedback1 S[]=new Feedback1[5];
S[0]=new Feedback1();
S[1]=new Feedback1();
S[2]=new Feedback1();
S[3]=new Feedback1();
S[4]=new Feedback1();
int calc[]=new int[5];
for (int a:calc) {
a=0;
}

for (int i=0;i<5;i++)


{
S[i].Question();
calc[S[i].Fback]++;
}
System.out.println("Name of Expert : Aayushi Chaudhary");

System.out.println((calc[1]*20)+"% gave excellent feedback" );


System.out.println((calc[2]*20)+"% gave very good feedback" );
System.out.println((calc[3]*20)+"% gave average feedback" );
System.out.println((calc[4]*20)+"% gave poor feedback" );
in.close();
}

Output :

You might also like