
private String name = "No name"; private int age= 20; private double marks = 0.0; private double percentage = 0.0;
In the class Student, create a constructor with three parameters. This constructor will assign the three parameters to the objectâ??s data name, age and marks. Define a method called calculatePercentage() that can be called from other classes. The calculatePercentage() method will divide the objectâ??s marks with 100 and assign the new value to percentage. Define another method called displayStudent() that will display the objectâ??s name, age, marks, and percentage.
Define another class called TestStudent that will test the Student class. Using appropriate methods from JOptionPane, ask three inputs which are studentâ??s name, studentâ??s age, and studentâ??s marks from user. From these inputs, define and create a Student object. Calculate the objectâ??s percentage and display all the data in the object using the two methods from class Student.

Hi Friend,
Try the following code:
import javax.swing.*;
class Student{
private String name="No name";
private int age=20;
private double marks=0.0;
private double percentage=0.0;
Student(String n, int a, double mm){
name=n;
age=a;
marks=mm;
}
public void displayStudent(){
System.out.println("Name: "+name+"\nAge: "+age+"\nMarks: "+marks+"\nPercentage: "+percentage+"%");
}
public void calculatePercentage(){
percentage=marks/100;
}
}
public class TestStudent{
public static void main(String[]args){
String name=JOptionPane.showInputDialog(null,"Enter Name:");
int age=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter Age:"));
double mm=Double.parseDouble(JOptionPane.showInputDialog(null,"Enter Marks:"));
Student s=new Student(name,age,mm);
s.calculatePercentage();
s.displayStudent();
}
}
Thanks