Professional Documents
Culture Documents
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());
}
}
}
Output :