Results 1 to 14 of 14
Like Tree2Likes
  • 2 Post By JosAH

Thread: Driver Class Program Help

  1. #1
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Driver Class Program Help

    Sample Output:

    Savings account balance = $1,050.00
    Checking account balance = $50.00
    Checking account balance = $49.00


    I am not getting the desired output. The program asks me to set the balance to zero if the withdrawal amount is more than the actual cash amount. But my program remembers the overdraft amount and causes problem in the output. Below is the work i have done so far.....



    Java Code:
    public class BankAccount {
    	
    public double balance;
    
    public BankAccount(double initialbalance)
    {
    	if (initialbalance>0.0)
    		
    		this.balance=initialbalance;
    
    }
    
    public void deposit(double amount)
    {
    	this.balance+=amount;
    }
    
    public void withdraw(double amount)
    {
    	this.balance-=amount;
    }
    
    public double getbalance()
    {
    	return balance;
    }
    public void displaymessage()
    {
    	System.out.printf("Balance is $ %.2f\n",getbalance());
    }
    	
    
    }



    Java Code:
    public class Checkings extends BankAccount {
    	public Checkings(double initialbalance) {
    		super(initialbalance);
    
    		
    	
    	}
    
    	
    
    	public void writeacheck(double check) {
    			
    		
    		this.balance=this.balance-check-1;
    		
    				
    	}
    
    
    
    	public void displaymessage()
    	{
    		System.out.printf("Checkings Balance is $  %.2f\n",getbalance());
    	}
    		
    }


    Java Code:
    public class Savings extends BankAccount {
    	
    	public Savings(double initialbalance, double interest) {
    		super(initialbalance);
    		
    		this.balance+=initialbalance*interest;
    	
    	}
    
    	public void addinterest() {
    		
    		
    	}
    	public void displaymessage()
    	{
    		System.out.printf("Savings Balance is $  %.2f\n",getbalance());
    	}
    		
    	}


    Java Code:
    public class driver {
    
    	public static void main (String [] args)
    	{
    	
    	BankAccount[] accounts = new BankAccount[100];
    
    	  accounts[0] = new Savings (1100,0.05);
    	  accounts[0].deposit(100);
    	  accounts[0].withdraw(200);
    	  ((Savings) accounts[0]).addinterest();
    
    	  accounts[1] = new Checkings(-100);
    	  accounts[1].deposit(50);
    
    	  accounts[2] = new Checkings(200);
    	  accounts[2].withdraw(210);
    	  accounts[2].deposit(100);
    	  ((Checkings) accounts[2]).writeacheck(50);
    	  
    	    
    	  for (int i=0; i<accounts.length && accounts[i] != null; i++)
    	  {
    	    accounts[i].displaymessage();
    	  }
    	
    	}
    }
    Last edited by smarty84handsome; 12-06-2013 at 06:07 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Driver Class Program Help

    problem in the output
    Please post the output and add some comments saying what is wrong with it.

    Also edit your post and change the quote tags to code tags.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Re: Driver Class Program Help

    Quote Originally Posted by Norm View Post
    Please post the output and add some comments saying what is wrong with it.

    Also edit your post and change the quote tags to code tags.
    Here is my output !

    Savings Balance is $ 1055.00
    Checkings Balance is $ 50.00
    Checkings Balance is $ 39.00--->Here in checkings balance i do not see my desired result. I should get $ 49 but because in driver class there is overdraft of $ 210 out of $ 200 the $ 10 gets carried so when i deposit $ 100 into checkings and then write a check of $ 50 with service fee of $ 1 then my desired result should be [/COLOR]

    100-50-1=49 But in my program this is what its happening 100-50-1-10=39
    Last edited by smarty84handsome; 12-06-2013 at 06:06 AM.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: Driver Class Program Help

    Your sums are wrong.
    You start with $200.
    You then withdraw $210, leaving $-10.
    Then deposit $100, giving $90.
    Finally write a check for $50 which, with the $1 fee, leaves you with $39.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Re: Driver Class Program Help

    The key is that my balance should set to zero if the withdraw amount if more than the balance !
    Last edited by smarty84handsome; 12-07-2013 at 07:17 AM.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default Re: Driver Class Program Help

    Quote Originally Posted by smarty84handsome View Post
    When the withdraw amount if more than the actual balance then my program sets the balance to zero and it starts from all over.
    ...
    The key is that my balance should set to zero if the withdraw amount if more than the actual balance !
    That's really a nice and friendly bank; you should implement it in line #20 of your first class.

    kind regards,

    Jos
    smarty84handsome and Norm like this.
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Re: Driver Class Program Help

    Thanks experts it was a pleasure dealing with you ! Can someone allow me to edit my classes . I would sincerely appreciate your permission !

  8. #8
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Re: Driver Class Program Help

    Thanks experts it was a pleasure dealing with you ! Can someone allow me to edit my classes . I would sincerely appreciate your permission !

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default Re: Driver Class Program Help

    Quote Originally Posted by smarty84handsome View Post
    Thanks experts it was a pleasure dealing with you ! Can someone allow me to edit my classes . I would sincerely appreciate your permission !
    That's not how forums work; when you post text in this forum, the text belongs to the forum; of course you can edit/change your copy of the text. We won't allow you to change the text in the forum though because it would rip this thread apart (the responses probably wouldn't make sense anymore).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Re: Driver Class Program Help

    Sir i m requesting to edit the unnecessary part coz this is class assignment and my hardwork code. I m sure my classmates will copy this. I promise i wont break forum rules.There are certain keyword tht is cached in google and it can easily be found. I will remove the unnecessary class only rest of the stuff will stay as it is.
    Last edited by smarty84handsome; 12-07-2013 at 03:35 PM.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default Re: Driver Class Program Help

    Quote Originally Posted by smarty84handsome View Post
    Sir i m requesting to edit the unnecessary part coz this is class assignment and my hardwork code. I m sure my classmates will copy this. I promise i wont break forum rules.There are certain keyword tht is cached in google and it can easily be found. I will remove the unnecessary class only rest of the stuff will stay as it is.
    Why did you post that code in the first place? You could've and should've known that your posted code will be in the public domain; b.t.w. the code is incorrect w.r.t. the requirements, so anyone copying it and turning it in blindly will get a bad mark; after you've made your changes will get a better mark ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default Re: Driver Class Program Help

    I agree with JosAH, which is why I'm ignoring your appeal sent in the PM quoted below.

    db

    Sir,

    I noticed you are from madgaon india and i am from india as well ! I am going through a dilemma in this forum past two days and perhaps i am wondering if you can help me. I posted my handwritten code in this website without knowing that editing functionality will be taken away. 100 % of code is written by me and there is no where in the internet that the program was solved. After much deliberation my program is working but when i came back to edit my post i was unable to take off the class. I was intending to keep the thread but take off the classes and leave the driver class however the moderators of that forum are not allowing. The problem with me is that my college does plagiarism scanning on google and anything detected with put me in problem. I promise i will adhere to forum rules properly from next time but wondering if you could make an exception and allow me to edit my post ! The discussion on that thread was for logical call and without mentioning code one of the member have replied and my problem is fixed now. I would appreciate if you could help me edit my post !
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  13. #13
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Re: Driver Class Program Help

    Quote Originally Posted by DarrylBurke View Post
    I agree with JosAH, which is why I'm ignoring your appeal sent in the PM quoted below.

    db

    If you are ignoring my request then just reply in the same mode in which i contacted you which was Private message. It was not necessary to mention my private message on the forum. Jst be a man you ass hole. This is nothing but a torture ! No more request ! Jst fuck off and thanks to those people who helped but unfortunately i cannot do anything with that program because of this shit. I bet this post will be deleted in matter of few seconds and thread will be closed right away (I may be banned frm this site) ! Becoz reality sucks ! Isn't it !

    Is this your standard - show some professionalism Mr. countrymen ! I tell you what i won't ask you to edit this post ! coz i want everyone to see what i have written here !

    This is called real Hard Core Java Code !
    Last edited by smarty84handsome; 12-08-2013 at 11:05 AM.

  14. #14
    Join Date
    Dec 2013
    Posts
    9
    Rep Power
    0

    Default Re: Driver Class Program Help

    Quote Originally Posted by smarty84handsome View Post
    If you are ignoring my request then just reply in the same mode in which i contacted you which was Private message. It was not necessary to mention my private message on the forum. Jst be a man you XXXXXXX. This is nothing but a torture ! No more request ! Jst XXXX off and thanks to those people who helped but unfortunately i cannot do anything with that program because of this XXXX. I bet this post will be deleted in matter of few seconds and thread will be closed right away (I may be banned frm this site) ! Becoz reality XXXXX ! Isn't it !

    Is this your standard - show some professionalism Mr. XXXXXXXXXX ! I tell you what i won't ask you to edit this post ! coz i want everyone to see what i have written here !

    This is called real Hard Core Java Code !

    [ Foul language removed; smarty84handsome will be banned if he does it again -- mod ]
    Sir pls do remove me - i opt out voluntarily !

Similar Threads

  1. Replies: 0
    Last Post: 03-03-2012, 02:01 AM
  2. Replies: 6
    Last Post: 02-08-2012, 07:42 PM
  3. Replies: 10
    Last Post: 04-20-2011, 03:03 AM
  4. using a driver with a class
    By vendetta in forum New To Java
    Replies: 7
    Last Post: 01-11-2010, 07:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •