Skip to content

Commit 6e24eed

Browse files
Create 30.1 Stdent_Class_Do_While_Loop.java
1 parent 0144f43 commit 6e24eed

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

30.1 Stdent_Class_Do_While_Loop.java

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Create a class Student with attributes name(String) and registrationNo(int) and a method show to display the attributes of the Student. Write a menu driven program with 2 choices to take the input of the student attributes and display the attributes.
3+
4+
Input Format
5+
6+
Your program should take the 2 choice as input. • If the first input will be 1 then also ask to user to enter the details of the student. If the entered registrationNo is negative, do not accept the input and prompt again to take new input until user will not entered the positive registrationNo. • If the first input will be 2 then display the default values of Student attributes separated by comma in the same line. • If the first input will be any other int value, display the message “Wrong Choice”.
7+
8+
Constraints
9+
10+
Student registrationNo should be positive value(excluding 0).
11+
12+
Output Format
13+
14+
Your program should display the attributes of Student or the message “Wrong Choice” as the User choice at the runtime.
15+
16+
Sample Input 0
17+
18+
1
19+
John
20+
10
21+
Sample Output 0
22+
23+
John,10
24+
Sample Input 1
25+
26+
2
27+
Sample Output 1
28+
29+
null,0
30+
*/
31+
import java.io.*;
32+
import java.util.*;
33+
34+
class Student
35+
{
36+
String name;
37+
int registrationNo;
38+
39+
void diplay()
40+
{
41+
System.out.println(name+","+registrationNo);
42+
}
43+
}
44+
45+
public class Solution {
46+
47+
public static void main(String[] args) {
48+
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
49+
Scanner sc = new Scanner(System.in);
50+
int choice = sc.nextInt();
51+
if(choice==1)
52+
{
53+
Student s = new Student();
54+
do
55+
{s.name = sc.next();
56+
s.registrationNo = sc.nextInt();}
57+
while(s.registrationNo<=0);
58+
s.diplay();
59+
}
60+
else if(choice==2)
61+
{
62+
Student s = new Student();
63+
s.diplay();
64+
}
65+
else
66+
System.out.print("Wrong Choice");
67+
}
68+
}

0 commit comments

Comments
 (0)