You are on page 1of 2

Student details

Student class :

public class Student{


private int studentId;
private String studentName;
private String studentAddress;
private String collegeName;

public Student(int stuId,String stuName,String stuAddress){


this.studentId=stuId;
this.studentName=stuName;
this.studentAddress=stuAddress;
this.collegeName="NIT";
}
public Student(int studentId,String studentName,String studentAddress,String
collegeName){
this.studentId=studentId;
this.studentName=studentName;
this.studentAddress=studentAddress;
this.collegeName=collegeName;
}

public int getStudentId(){


return this.studentId;
}
public String getStudentName(){
return this.studentName;
}
public String getStudentAddress(){
return this.studentAddress;
}
public String getCollegeName(){
return this.collegeName;
}
}

Student main class :

import java.util.Scanner;
public class StudentMain{
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Student's Id:");
int id=sc.nextInt();
System.out.println("Enter Student's Name:");
String name=sc.next();
System.out.println("Enter Student's address:");
String add=sc.next();
System.out.println("Whether the student is from NIT(Yes/No):");
String clg=sc.next();
String c="no";
String d="NO";
if(clg.equals(c) || clg.equals(d)){
System.out.println("Enter the college name:");
String clgname=sc.next();
Student s=new Student(id,name,add,clgname);
System.out.println("Student id:"+s.getStudentId());
System.out.println("Student id:"+s.getStudentName());
System.out.println("Student id:"+s.getStudentAddress());
System.out.println("Student id:"+s.getCollegeName());
}
else if(clg.equals("yes") || clg.equals("YES")){
Student s=new Student(id,name,add);
System.out.println("Student id:"+s.getStudentId());
System.out.println("Student id:"+s.getStudentName());
System.out.println("Student id:"+s.getStudentAddress());
System.out.println("Student id:"+s.getCollegeName());
}
else{
System.out.println("Wrong Input");
}
}
}

You might also like