Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nsbt.assignment2;
- public class Student
- {
- String name;
- String id;
- double grade;
- public Student(String name,String id,double grade) {
- this.name=name;
- this.id=id;
- this.grade=grade;
- }
- public Student(String name, String id)
- {
- this(name,id,0.0);
- this.name=name;
- this.id=id;
- }
- public Student(String id)
- {
- this(null,id,0.0);
- this.id=id;
- }
- void display()
- {
- System.out.println("Student name: "+name+" Student id: "+id+" Student grade: "+grade);
- }
- void display(int currentYear)
- {
- System.out.println("Student name: "+name+" Student id: "+id+" Student grade: "+grade+" Current year of the student"+currentYear);
- display();
- }
- }
- //
- package com.nsbt.assignment2;
- import java.util.Scanner;
- public class Application {
- public static void main(String[] args)
- {
- Scanner sc=new Scanner(System.in);
- int input;
- System.out.println("you want enter \n 1. only id \n 2. Id with name \n 3. all three values(id,name and grade)");
- input=sc.nextInt();
- System.out.println("1. Display with current year or 2. normal display");
- int inputDisplay=sc.nextInt();
- if(inputDisplay==1)
- {
- switch(input)
- {
- case 1:
- {
- System.out.println("Enter Id");
- Student st=new Student(sc.next());
- System.out.println("Enter the year");
- st.display(sc.nextInt());
- break;
- }
- case 2:
- {
- System.out.println("Enter id and name");
- Student st=new Student(sc.next(),sc.next());
- System.out.println("Enter the year");
- st.display(sc.nextInt());
- break;
- }
- case 3:
- {
- System.out.println("Enter all three values");
- Student st=new Student(sc.next(), sc.next(), sc.nextDouble());
- System.out.println("Enter the year");
- st.display(sc.nextInt());
- break;
- }
- }
- }
- else
- {
- switch(input)
- {
- case 1:
- {
- System.out.println("Enter Id");
- Student st=new Student(sc.next());
- st.display();
- break;
- }
- case 2:
- {
- System.out.println("Enter id and name");
- Student st=new Student(sc.next(),sc.next());
- st.display();
- break;
- }
- case 3:
- {
- System.out.println("Enter all three values");
- Student st=new Student(sc.next(), sc.next(), sc.nextDouble());
- st.display();
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment