forked from adityabiswal2147207/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcept.java
More file actions
67 lines (59 loc) · 1.83 KB
/
Copy pathexcept.java
File metadata and controls
67 lines (59 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.Scanner;
class invalidusername extends Exception
{
public invalidusername(String str)
{
//calling the parent of parent exception
super(str);
}
}
class Testusername
{
void validate() throws invalidusername{
Scanner sc = new Scanner(System.in);
try
{
String name;
System.out.println("Enter your username for the account");
name = sc.next();
if(name.length()<6 || name.length() == 0)
{
System.out.println("Sorry the username cannot be less than 6 characters");
throw new invalidusername("Check your username again!!!");
}
else
{
System.out.println("Welcome "+ name);
}
}
catch(invalidusername ex)
{
System.out.println("Exception caught");
System.out.println("Exception occured: "+ex);
}
}
}
public class except{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Testusername obj1 = new Testusername();
int ch;
System.out.println("Welcome to student online exam portel");
System.out.println("Please select one of the options from below");
System.out.println("1.Press 1 to login");
System.out.println("2.Press 2 to register");
System.out.println("0.Press 0 to exit");
lp : while(true)
{
System.out.println("Enter your choice:- ");
ch = sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Welcome to the login portal for online examination portal");
Testusername obj = new Testusername();
obj.validate();
}
}
}
}