Student
-name: String
-studentNumber: long
-loanAmount: double
+<<constructor>> Student()
+<<constructor>> Student(String, long, double)
+getName(): String
+getStudentNumber(): long
+getLongAmount(): double
+setName(String): void
+setStudentNumber(long): double
+setLoanAmount(double): void
+toString(): String
+show(): void
+interest(): double
show() method This method is void and does not have any parameters. This method displays the details of a Student object as follows:
Student details Name: Smittie
Student number: 12345
Loan amount: 10000.0
Coding for interest() method public double interest() { return loanAmount*.05; }
Source code
public class Main
{
public static void main(String[] args) {
Student s1=new Student();
s1.setName("Smittie");
s1.setStudentNumber(12345);
s1.setLoanAmount(10000);
s1.show();
}
}
class Student{
private String name;
private long studentNumber;
private double loanAmount;
public Student(){
}
public Student(String n, long sn, double la){
name=n;
studentNumber=sn;
loanAmount=la;
}
public String getName(){
return name;
}
public long getStudentNumber(){
return studentNumber;
}
public double getLongAmount(){
return loanAmount;
}
public void setName(String nm){
name=nm;
}
public void setStudentNumber(long sn){
studentNumber=sn;
}
public void setLoanAmount(double a){
loanAmount=a;
}
public String toString(){
return "";
}
public void show(){
System.out.println("Student Details");
System.out.println("Name: "+getName());
System.out.println("Student number: "+getStudentNumber());
System.out.println("Loan amount: "+getLongAmount());
System.out.println("Interest: "+interest());
}
public double interest(){
return loanAmount*.05;
}
}
Output
Comments
Leave a comment