Thread: Class help
View Single Post
  #22 (permalink)  
Old 11-15-2007, 12:22 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Code:
public class Trans { private Operation op; /*Deposit or Withdrawal*/ private Account acc; /*account for which a transaction*/ /*amount of money involved in that transaction, deposit or withdrawal*/ private double amt; public Trans(Account acct, Operation op, double amt) { this.acc = acc; this.op = op; this.amt = amt; } public double getAmount() { return amt; } public static void main(String[] args) { // What is the type of Operation.WITHDRAWAL? // If is is an int you'll hava to change the Trans // constructor to: // public Trans(Account acct, int op, double amt) Trans t1 = new Trans( account1, Operation.WITHDRAWAL, 100 ) ; // Use the variable "t1" to access fields and methods in // this instance of Trans System.out.println("amt = " + t1.getAmount()); } }
Reply With Quote