Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Help on writing a simple program

Posted by barty1 (barty1), 20 April 2003
Hi, not sure if this forum is intended for help on course work so apologies if not.  I just really want someone to check over the program I have written and let me know if there are any glaring errors
I must:
1. Create a class for each type of account
2. Create constructors for eash class, using inheritance where possible
3. Create methods for depositing and withdrawing funds as wel as for diplaying the current balance
4. Create additional methods to check that the account balance against the agreed overdraft limit.

I think it almost fulfills all criteria now and i need to get 65% to pass. I would be very grateful for any further constructive criticism before I submit it.

/* A program to create 3 bank accounts from an abstract superclass
  with methods to accept deposits and withdrawals and show balance
*/

class bankAccount //Declares superclass

{
  private String accountName; //Account Holder Name
  private String accountNo; //Account Number
  private double accountBalance;//Account balance
  private double accountRate;//Interest Rate
     
   
    public bankAccount(String name, String number,double balance, double rate) //Class Constructor    
   
    {
      accountName = name;
          accountNo = number;
          accountBalance = balance;
          accountRate = rate;
    }      

 /*get and set methods to allow main program full access
  */
 
    public String getName () {return accountName;}
    public void setName(String s) {accountName = s;}
    public String getNumber() {return accountNo;}
    public void setNumber(String n) {accountNumber = n;}
    public double getBalance() {return accountBalance;}
    public void setBalance(double balance) {accountBalance = balance;}
    public double getRate() {return accountRate;}
    public void setRate(double rate) {accountRate = rate;}
   
 /*methods to allow deposit and withdrawals
  */
 
    public void deposit (double amount) {accountBalance +=amount;}
    public void withdraw (double amount) {accountbalance -=amount;}
   
}  
       

  /*code block to add deposit to balance and check withdrawal is allowed
    */
 {
      public bankAccount(double initialAmount)
     { balance = initialAmount;}

     public void deposit(double amount)
     {balance += amount;}

     public void withdraw(double amount)
     {if (balance >= amount)
     balance -= amount;
     else
     System.out.println("Insufficient funds");}

     public double getBalance()
     {return balance;}
             
}    

/* Current Account class
*/

public final class currentAccount extends bankAccount
{
   public currentAccount( String name, String number, double balance, double rate, double odLimit)
   
    {
      super (name, number, balance, rate);
    }              
 
}          
   
/* Student Account Class
*/    

public final class studentAccount extends bankAccount
{
    private double overdraftLimit;
    private double accountrate;

 
     public studentAccount( String name, String number, double balance, double rate, double odLimit)
   
    {
      super (name, number, balance, rate);
      overdraftLimit = balance * 2.5;
      accountRate = balance * 0.2;
    }        
       
       
        public double getodLimit() {return overdraftLimit;}
        public double getaccountRate(){return accountRate:}
       
}
/* Platinum Account Class
 */
 
public final class platinumAccount extends bankAccount
{
    private double overdraftLimit;

 
     public platinumAccount( String name, String number, double balance, double rate, double odLimit)
   
     {
      super (name, number, balance, rate);
      overdraftLimit = balance * 2.5;
      accountRate = balance * 0.2;
    }        
       
       
       
        public double getodLimit() {return overdraftLimit;}
        public double getaccountRate(){return accountRate:}
}  



/* Main method to create Account Objects
*/

      public static void main (String [args])
     
      {  
         bankAccount account1 = new currentAccount
         ("Steve Bart", "100987", "250.00", "2.5");
     
         System.out.println (account1.accountName + ""+account1.accountNumber+""+
       account1.accountBalance+""+account1.accountRate+""+);
       

   
       bankAccount account1 = new studentAccount
         ("Steve Bart", "102345", "450.00", "1.5");
     
         System.out.println (account1.accountName + ""+account1.accountNumber+""+
       account1.accountBalance+""+account1.accountRate+""+);  
   
     
   
       bankAccount account1 = new platinumAccount
         ("Steve Bart", "202934", "650.00", "3.5");
     
         System.out.println (account1.accountName + ""+account1.accountNumber+""+
       account1.accountBalance+""+account1.accountRate+""+);
    }

} // ends program
       

Posted by admin (Graham Ellis), 21 April 2003
Hi, Barty1 ... welcome.

The site is really intended for folk who are looking to solve a specific problem in a "real life" application but which the books don't seem to obviously answer, and in the past I have objected to folks posting up coursework questions hoping someone will do their work for them.    However - you're asking for something different - a review of work you've done already, and I'm very happy to add my 2c or 2p (or whatever your currency is worth.

The answer basically fills the criteria set in the question - good.  A few minor thoughts (BUT I don't know the setter of the question / context ;/ what you have learnt so I may be off key)

a) I would suggest a getodLimit method in the base class that returns a zero - that way the method could be called on any account type including those that don't have an overdraft facility.

b) I'm concerned that the overdraft limit set appears to be 2.5 times the initial balance.   Why?

c) I'm also concerned at the printed error message from withdraw; have you considered throwing an excpetion?

There ... just some initial thoughts.  Overall looks pretty good mind!

Graham

Posted by barty1 (barty1), 21 April 2003
Thanks Graham,

The course is with Computeach and I have taken on board what you've said - much appreciated.

I note you are in Melksham.  Im in Bristol and the 'mo and am looking to get into Web Development or a juniore programmers role after completing the SCJP in, say, 6 months time.  

Could you give me any idea what the climate is like out there at present.  Predictably I'm getting bad vibes as someone with no prior experience (save for some web design).  I would seriously love to get some work experience somewhere even if this means working for nothing part time.

Cheers!

Posted by admin (Graham Ellis), 21 April 2003
I don't know where to start in answering about the jobs / work climate; for sure, things are very much tighter than they were a few months back .... which in turn was very much tighter than it was a year back .... BUT if you're determined and lucky (and you can make your own luck) and you have the ability and dedication to learn to do this sort of work, you'll make it.

Personally, I'm primarily a trainer although I do a small amount of contract work too to avoid going rusty.   Training has a slightly different "busyness" cycle and training companies tend to be rushed off their feet at times of high growth where the supply of trained people cannot meet the demand ... the training business has been in the doldrums for a while (present company excepted, I'm relieved to say   ) ... I mention this to warn you that I get a somewhat biased view of the market.

For six month's time?  I GUESS (note I've said "guess") that there will be something of a recovery.   With the uncertainty over Iraq a month or two ago, everyone was battening down the hatches and they'll open up again in due course - same thing happened with 9/11.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho