Slip17

 Q1) Design a Super class Customer (name, phone-number). Derive a class Depositor(accno , balance) from Customer. Again, derive a class Borrower (loan-no, loan-amt) from Depositor. Write necessary member functions to read and display the details of ‘n’customers. [10 marks] 

import java.util.*;

class Customer 

{

   String cname;

   int pno;

   Customer(String cname,int pno) 

 {       

this.cname=cname;

this.pno=pno;  

 }

void display() 

 {

       System.out.println("Customer Name: "+cname+"\nPhone No: "+pno);        

 }

}

class Depositor extends Customer 

{

   int accno , balance;

   Depositor(String cname,int pno,int accno, int  balance) 

 {

        super(cname,pno);

this.accno=accno;  

this.balance=balance;

 }

void display() 

 {

super.display();

       System.out.println("Account No : "+accno+"\nBalance: "+balance);        

 }

}

class Borrower extends Depositor

{

   int loanno, loanamt;

   Borrower(String cname,int pno,int accno, int  balance,int loanno, int loanamt) 

 {

       super(cname,pno, accno,balance);

this.loanno=loanno ;  

this.loanamt=loanamt;

 }

void display() 

 {

super.display();

       System.out.println("Loan No  : "+loanno+"\nLoan amt: "+loanamt);        

 }

}


 class Slip17_1

{

 public static void main( String args[] )

 {

  Borrower acc=new Borrower("abc",123456789,5000,1000,2000,1000);

acc.display();

 } 

}

Q2) Write Java program to design three text boxes and two buttons using swing. Enter different strings in first and second textbox. On clicking the First command button, concatenation of two strings should be displayed in third text box and on clicking second command button, reverse of string should display in third text box.

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

 

public class Slip17_2 implements ActionListener

{

JButton b1,b2;

JTextField t1,t2,t3;

    Slip17_2()

    {

        JFrame frame = new JFrame("ActionListenerExample");

        frame.setLayout(new FlowLayout());

b1=new JButton("Concat");

b1.addActionListener(this);

b2=new JButton("Reverse");

b2.addActionListener(this);

t1=new JTextField(15);

t2=new JTextField(15);

t3=new JTextField(15);

frame.add(t1);frame.add(t2);

frame.add(b1);frame.add(b2);

frame.add(t3);

frame.setSize(400,300);

        frame.setVisible(true);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

public void actionPerformed(ActionEvent ae) 

{

  String s1=t1.getText();

String s2=t2.getText();

if(ae.getSource() == b1)

t3.setText(""+(s1+s2));

if(ae.getSource() == b2)

{

StringBuffer sb=new StringBuffer(s1);

t3.setText(""+(sb.reverse()));

}

}

    public static void main(String[] args)

{  

new Slip17_2();

}

  }

Comments

Popular posts from this blog

Slip1

Slip3

Slip2