You are on page 1of 9

BCSL-043

Q1import java.util.Date; public class Account { //define var1, var2 private int id = 0; private double balance= 0; private static double annualInterestRate = 0; private Date dateCreated = new Date(); //no arg constructer Account() { id = 0; balance = 0.0; annualInterestRate = 0.0; } //constructor with specific id and initial balance public Account(int newId, double newBalance) { id = newId; balance = newBalance; } Account(int newId, double newBalance, double newAnnualInterestRate) {

id = newId; balance = newBalance; annualInterestRate = newAnnualInterestRate; } //accessor/mutator methods for id, balance, and annualInterestRate public int getId() { return id; } public double getBalance() { return balance; } public double getAnnualInterestRate() { return annualInterestRate; } public void setId(int newId) { id = newId; } public void setBalance(double newBalance) { balance = newBalance; }

public static void setAnnualInterestRate(double newAnnualInterestRate) { annualInterestRate = newAnnualInterestRate; } //accessor method for dateCreated

public Date getDateCreated() { return dateCreated; } //define method getMonthlyInterestRate double getMonthlyInterestRate() { return annualInterestRate/12/100 * balance; } //define method withdraw double withdraw(double amount) { return balance -= amount; } //define method deposit double deposit(double amount) { return balance += amount; }

public class SavingsAccount extends Account { public SavingsAccount(int newId, double newBalance) { super(newId, } newBalance);

//Establishes current date and Preset date public class PresetDate { public DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); public Date currentDate = new Date(); public Date PreSet = new Date("2012/10/01"); }

//a savings account cannot be overdrawn public double withdraw (double amount, Date currentDate, Date PreSet) { if (getBalance() < amount) { System.out.println("Amount is larger than current balance.");

} if (currentDate.after(PreSet)) { System.out.println("Amount exceeds balance or account has not reached preset date."); }

return super.withdraw(amount); } }

public class FixedDepositAccount extends Account { private double FDLimit;

public CheckingAccount(int newId, double newBalance) { super(newId, newBalance); setFDLimit(FDLimit);

} public void FDLimit(double o) { FDLimit = o; }

public double FDLimit() { return FDLimit; }

public double withdraw(double amount) { if(getBalance() + FDtLimit < amount) System.out.print("Cannot be done"); else return super.withdraw(amount); } }

Q2Import java.io.*; Class student implements Serializable { Int enrollno; String sname; String Addr; String course; Int sem; String Fathernm;0

Public student(int r,String snm,String ad,String c,int sm,String fnm) { Enrollno=r; Sname=snm; Addr=ad; Course=c; Sem=sm; Fathernm=fnm; } }

Public class storedetails { Public static void main(String args[]) { Try { Student obj=new Student(101,rohit,Delhi,BCA,4,Mr.A); FileOutputStream fw=new FileOutputStream(student.txt); ObjectOutputStream ob=new ObjectOutputStream(fw); Ob.writeObject(obj); Ob.flush(); Ob.close();

} Catch(Exception e) { } } }

Q3
import java.awt.*; import java.applet.*; import java.awt.event.*; public class AppletTabe extends Applet implements ActionListener { TextField text1,output; Label label1,label2; Button button; public void init() { setLayout(null); label1 = new Label("Enter Number: "); label1.setBounds(20,20,100,20); add(label1); text1 = new TextField(5); text1.setBounds(150,20,100,20); add(text1); label3 = new Label("Table of Number: "); label3.setBounds(20,80,130,20); add(label3); output = new TextField(5); output.setBounds(150,80,100,20); add(output); button = new Button("Print Table"); button.setBounds(150,110,100,20); add(button); button.addActionListener(this); } public void actionPerformed(ActionEvent ae) { int num=Integer.parseInt(text1.getText()); int m;

for(int i=1;i<=10;i++) { m=i*num; output.setText(Integer.toString(m)); } }

You might also like