Guest User

Untitled

a guest
Jun 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. package com.nsbt.assignment2;
  2.  
  3. public class Student
  4. {
  5. String name;
  6. String id;
  7. double grade;
  8.  
  9. public Student(String name,String id,double grade) {
  10. this.name=name;
  11. this.id=id;
  12. this.grade=grade;
  13. }
  14.  
  15. public Student(String name, String id)
  16. {
  17. this(name,id,0.0);
  18. this.name=name;
  19. this.id=id;
  20.  
  21. }
  22.  
  23. public Student(String id)
  24. {
  25. this(null,id,0.0);
  26. this.id=id;
  27. }
  28.  
  29. void display()
  30. {
  31. System.out.println("Student name: "+name+" Student id: "+id+" Student grade: "+grade);
  32. }
  33.  
  34. void display(int currentYear)
  35. {
  36. System.out.println("Student name: "+name+" Student id: "+id+" Student grade: "+grade+" Current year of the student"+currentYear);
  37. display();
  38. }
  39. }
  40.  
  41.  
  42. //
  43.  
  44. package com.nsbt.assignment2;
  45.  
  46. import java.util.Scanner;
  47.  
  48. public class Application {
  49.  
  50. public static void main(String[] args)
  51. {
  52. Scanner sc=new Scanner(System.in);
  53. int input;
  54. System.out.println("you want enter \n 1. only id \n 2. Id with name \n 3. all three values(id,name and grade)");
  55. input=sc.nextInt();
  56. System.out.println("1. Display with current year or 2. normal display");
  57. int inputDisplay=sc.nextInt();
  58. if(inputDisplay==1)
  59. {
  60. switch(input)
  61. {
  62. case 1:
  63. {
  64. System.out.println("Enter Id");
  65. Student st=new Student(sc.next());
  66. System.out.println("Enter the year");
  67. st.display(sc.nextInt());
  68. break;
  69. }
  70. case 2:
  71. {
  72. System.out.println("Enter id and name");
  73. Student st=new Student(sc.next(),sc.next());
  74. System.out.println("Enter the year");
  75. st.display(sc.nextInt());
  76. break;
  77. }
  78. case 3:
  79. {
  80. System.out.println("Enter all three values");
  81. Student st=new Student(sc.next(), sc.next(), sc.nextDouble());
  82. System.out.println("Enter the year");
  83. st.display(sc.nextInt());
  84. break;
  85. }
  86. }
  87. }
  88. else
  89. {
  90. switch(input)
  91. {
  92. case 1:
  93. {
  94. System.out.println("Enter Id");
  95. Student st=new Student(sc.next());
  96. st.display();
  97. break;
  98. }
  99. case 2:
  100. {
  101. System.out.println("Enter id and name");
  102. Student st=new Student(sc.next(),sc.next());
  103. st.display();
  104. break;
  105. }
  106. case 3:
  107. {
  108. System.out.println("Enter all three values");
  109. Student st=new Student(sc.next(), sc.next(), sc.nextDouble());
  110. st.display();
  111. break;
  112. }
  113. }
  114. }
  115.  
  116. }
  117.  
  118.  
  119.  
  120.  
  121. }
Add Comment
Please, Sign In to add comment