Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Homework 3 Questions - Computer Programming in Java | CS 140, Study notes of Computer Science

Homework Material Type: Notes; Professor: Sleem; Class: Computer Programming in Java; Subject: Computer Science; University: Texas Southern University; Term: Fall 2010;

Typology: Study notes

2009/2010

Uploaded on 12/16/2010

yvvy-2k5
yvvy-2k5 🇺🇸

3 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS140: Computer Programming using Java
Summer 2010
Homework 3
1. Write the Java class file for the class Account that represents a bank account. The
class should have the following data variables:
accountNumber: an integer that holds the account number.
balance: a double that is used to store the balance of the account.
Your class should provide the following methods:
setAccountNumber: This method will take the account number as an
integer parameter and stores it in the accountNumber data member. The
method does not return anything.
setBalance: This method will take the balance as a double parameter and
stores it in the balance data member variable. The method does not return
anything.
getAccountNumber: This method returns the account number.
getBalance: Which returns the current account balance.
debitAccount: This method deducts funds from the account. It takes the
amount to be deducted as a parameter then subtracts it from the balance.
creditAccount: This method adds funds to the account. It takes the amount
to be credited as a parameter then adds it to the balance.
2. Write a small Java program that tests the Account class. The program should:
Generate three objects from the Account class called checkingAccount,
savingAccount, and moneyMarketAcount. The three accounts should be
initialized as follows:
Object Name Account number Starting Balance
checkingAccount 10001 $1,000
savingAccount 10002 $2,000
moneyMarketAcount 10003 $200
Display the account numbers of the three accounts.
Display the starting balances of the three accounts.
Deposit $1,000 in the checkingAcount.
Withdraw $1000 from the savingAccount.
Deposit $500 to the moneyMarketAcount.
Display the new balances of the three accounts after performing the above
transactions.
pf2

Partial preview of the text

Download Homework 3 Questions - Computer Programming in Java | CS 140 and more Study notes Computer Science in PDF only on Docsity!

CS140: Computer Programming using Java

Summer 2010

Homework 3

  1. Write the Java class file for the class Account that represents a bank account. The class should have the following data variables: - accountNumber : an integer that holds the account number. - balance : a double that is used to store the balance of the account.

Your class should provide the following methods:

  • setAccountNumber: This method will take the account number as an integer parameter and stores it in the accountNumber data member. The method does not return anything.
  • setBalance: This method will take the balance as a double parameter and stores it in the balance data member variable. The method does not return anything.
  • getAccountNumber: This method returns the account number.
  • getBalance: Which returns the current account balance.
  • debitAccount: This method deducts funds from the account. It takes the amount to be deducted as a parameter then subtracts it from the balance.
  • creditAccount: This method adds funds to the account. It takes the amount to be credited as a parameter then adds it to the balance.
  1. Write a small Java program that tests the Account class. The program should:
  • Generate three objects from the Account class called checkingAccount, savingAccount, and moneyMarketAcount. The three accounts should be initialized as follows:

Object Name Account number Starting Balance checkingAccount 10001 $1, savingAccount 10002 $2, moneyMarketAcount 10003 $

  • Display the account numbers of the three accounts.
  • Display the starting balances of the three accounts.
  • Deposit $1,000 in the checkingAcount.
  • Withdraw $1000 from the savingAccount.
  • Deposit $500 to the moneyMarketAcount.
  • Display the new balances of the three accounts after performing the above transactions.

Programming Guidelines:

  1. Provide as much comments as you can to document your program.
  2. Use meaningful variable names and avoid using names like var1, var2, etc.
  3. Use indentation to make your program easy to read and trace.
  4. Submit the Java source file to the blackboard digital dropbox. Your submitted files must have the following name format:

LastName+last 4 digits of your TNumber + Account.java. LastName+last 4 digits of your TNumber + TestAccount.java.

For example, Sleem6457-Account.java For example, Sleem6457-TestAccount.java

5. Submit your work to the blackboard by Thursday July 22 nd^ 2010. 6. Submit a printed copy of your program at the end of the class on Thursday July 22 nd 2010.