Problem Statement:
Understand the below program and print the details of the student as shown in the sample test cases.
- Student class is defined with public variables name, age, group and report.
- Define setDetails() method that sets the student name, age, group and report values.
- Define getDetails() method that prints all the details of the student.
- Create an instance of class Student.
- Set the name, age, group and report values of the student by taking the input from the student and call the setDetails() values
- Now print the details of Student by calling the method getDetails()
Govardhan
37
IT
Pass
Sample Output:
Govardhan 37 IT Pass
Solution in | JAVA | PYTHON |
---|
import java.util.Scanner;
public class StudentDetails{
String name,group,report;
int age;
public void setDetails(String name,int age, String group,String report){
this.name = name;
this.age = age;
this.group = group;
this.report = report;
}
public void getDetails(){
System.out.println(name+" "+age+" "+group+" "+report);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
StudentDetails s = new StudentDetails();
String name = sc.nextLine();
int age = sc.nextInt();
sc.nextLine();
String group = sc.nextLine();
String report = sc.nextLine();
s.setDetails(name,age,group,report);
s.getDetails();
}
}
public class StudentDetails{
String name,group,report;
int age;
public void setDetails(String name,int age, String group,String report){
this.name = name;
this.age = age;
this.group = group;
this.report = report;
}
public void getDetails(){
System.out.println(name+" "+age+" "+group+" "+report);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
StudentDetails s = new StudentDetails();
String name = sc.nextLine();
int age = sc.nextInt();
sc.nextLine();
String group = sc.nextLine();
String report = sc.nextLine();
s.setDetails(name,age,group,report);
s.getDetails();
}
}