
write a program to define a student class with attributes student no student no student age student gender declare a default constuctor one method to accept the details from the user ( set details()) and method to display the details 9 get details()).

import java.util.*;
public class Student{
String name;
int age;
String gender;
Scanner input=new Scanner(System.in);
Student(){
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return age;
}
public void setGender(String gender){
this.gender=gender;
}
public String getGender(){
return gender;
}
public void setDetails(){
System.out.println("Enter Name: ");
String n=input.nextLine();
System.out.println("Enter Age: ");
int a=input.nextInt();
System.out.println("Enter Gender: ");
String g=input.next();
setName(n);
setAge(a);
setGender(g);
}
public void getDetails(){
System.out.println();
System.out.println("Details of a student: ");
System.out.println("Name is: "+getName());
System.out.println("Age is: "+getAge());
System.out.println("Gender is: "+getGender());
}
public static void main(String args[]){
Student s=new Student();
s.setDetails();
s.getDetails();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.