StudentAccount
-studentName: String
-studentCourse: String
-balance: double
+StudentAccount()
+StudentAccount(String,String,double)
+getters()
+setters()
+toString(): String
+pay(double): double
+addFees(double): double
+refund(): void
Code the StudentAccount class according to the class diagram
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
StudentAccount s=new StudentAccount();
}
}
class StudentAccount{
private String studentName;
private String studentCourse;
private double balance;
public StudentAccount(){
}
public StudentAccount(String n,String c,double b){
studentName=n;
studentCourse=c;
balance=b;
}
public String getStudentName(){
return studentName;
}
public String getStudentCourse(){
return studentCourse;
}
public double getBalance(){
return balance;
}
public void setStudentName(String name){
studentName=name;
}
public void voidsetStudentCourse(String course){
studentCourse=course;
}
public void setBalance(double b){
balance=b;
}
public String toString(){
return "Student name is "+getStudentName()+"\nStudent course is "+getStudentCourse()+"\nBalance= "+getBalance();
}
public double pay(double p){
return (balance-p);
}
public double addFees(double a){
return (balance+a);
}
public void refund(){
double amount;
Scanner in=new Scanner(System.in);
amount=in.nextDouble();
balance=balance-amount;
}
}
Comments
Leave a comment