0% found this document useful (0 votes)
59 views8 pages

Universidad Autónoma de Santo Domingo (UASD) : Programación II

This document contains Java code that defines classes for bank accounts including an abstract bank account class, account class, credit account class, and test classes. The abstract bank account class defines abstract methods for deposit, withdraw, get balance, and get bank name. The account class implements these methods along with methods to set the account name, number, and balance. The credit account class extends the account class and adds a credit limit. The test classes create instances of the account and credit account classes and call their methods.

Uploaded by

WhilmarMolina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views8 pages

Universidad Autónoma de Santo Domingo (UASD) : Programación II

This document contains Java code that defines classes for bank accounts including an abstract bank account class, account class, credit account class, and test classes. The abstract bank account class defines abstract methods for deposit, withdraw, get balance, and get bank name. The account class implements these methods along with methods to set the account name, number, and balance. The credit account class extends the account class and adds a credit limit. The test classes create instances of the account and credit account classes and call their methods.

Uploaded by

WhilmarMolina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Universidad Autónoma de Santo Domingo

(UASD)
Programación II
Asignatura
Silverio Del Orbe Abad
Profesor
Oracle Academic JP, Lección 3
Tema
Whilmar Molina
Estudiante
100209302
Matricula
INF5140-1
Sección
Domingo, 8 de septiembre de 2022, 22:15
Fecha de entrega

abstract public class AbstractBankAccount


{
public final String BANK = "JavaBanks";

abstract public void deposit (int amt);


abstract public void withdraw (int amt);
abstract public int getBalance ();
abstract public String getbankName ();

public class Account


{

String accountname;

int accountnum;

int balance;

Account ()
{

this.accountname = "EMPTY";

this.accountnum = 0;

this.balance = 0;

Account (String name, int num, int amt)


{

accountname = name;

accountnum = num;

balance = amt;

public void deposit (int amt)


{

balance = balance + amt;


}

public void withdraw (int amt)


{

balance = balance - amt;

public void setaccountname (String name)


{

accountname = name;

public void setaccountnum (int num)


{

accountnum = num;

public void setbalance (int num)


{

balance = num;

public String getaccountname ()


{

return accountname;

public int getaccountnum ()


{

return accountnum;

}
public int getbalance ()
{

return balance;

public void print ()


{

System.out.println (accountname + " " + accountnum + " " + balance);

}
}

public class CreditAccount extends Account


{

int creditLimit;

CreditAccount ()
{

super ();

this.creditLimit = 100;

}
CreditAccount (String name, int num, int amt, int credit)
{

super (name, num, amt);

this.creditLimit = credit;

public void setcreditlimit (int num)


{

creditLimit = num;
}
public int getcreditlimit ()
{

return creditLimit;

public void print ()


{

System.out.println (accountname + " " + accountnum + " " + balance +


" " + creditLimit);

}
}

public class testCreditAccount


{

public static void main (String[]args)


{

// Instantiate 3 accounts
// Using constructor with values
Account A1 = new Account ("Sanjay Gupta", 11556, 300);

// Using default constructor


Account A2 = new Account ();

Account A3 = new Account ();

// Instantiate 2 credit accounts


// Using default constructor
Account C1 = new CreditAccount ();

// Using constructor with values which will call constructor from super
Account C2 = new CreditAccount ("Another", 66778, 1000, 500);

//Set values of Instances created using default constructor


A2.setaccountname ("He Xai");

A2.setaccountnum (22338);
A2.setbalance (500);

A3.setaccountname ("Ilya Mustafana");

A3.setaccountnum (44559);

A3.setbalance (1000);

C1.setaccountname ("A.N Other");

C1.setaccountnum (88776);

C1.setbalance (500);

// Print accounts
A1.print ();

A2.print ();

A3.print ();

C1.print ();

C2.print ();

}
}

public class TestBank


{
public static void main ()
{

Account A1 = new Account ("Sanjay Gupta", 11556, 300);

Account A2 = new Account ();

Account A3 = new Account ();

A2.setaccountname ("He Xai");

A2.setaccountnum (22338);

A2.setbalance (500);

A3.setaccountname ("Ilya Mustafana");

A3.setaccountnum (44559);

A3.setbalance (1000);

A1.print ();

A2.print ();

A3.print ();

}
}

You might also like