Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: MinMaxAccount

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MinMaxAccount

    Hi everyone just learning to get back into Java 2 programming, so be gentle with me lol. So my directions for class are
    "Design a new class MinMaxAccount whose instances can be used in place of a BankingAccount object but include new behavior of remembering the minimum and maximum balances ever recorded for the account. You should provide the same methods as the superclass, as well as the following new behavior:"


    Method/Constructor Description
    public MinMaxAccount(Startup s) constructs a MinMaxAccount object using information in the Startup object s
    public int getMin() returns minimum balance in pennies
    public int getMax() returns maximum balance in pennies

    so my code is as follows thus far,

    public class MinMaxAccount extends BankingAccount{
        	private int holdMax;
        	private int holdMin=200;
     
        	public MinMaxAccount(Startup s)
        	   {    holdMax=s.startup_getBalance();
        	   		holdMin=s.startup_getBalance();
        	   		if(Startup s)
        	   	        balance += c.credit_getBalance();
     
     
     
        	   }
     
     
     
     
        	public int getMin(){
        		return holdMin;
        	}
     
     
        	public int getMax(){
        		return holdMax;
        }
     
    }

    I had no idea how to proceed, i feel pretty stuck and everytime i ask for help they give me some abstract way of thinking about it, however i just don't know what the code would look like. They said to override the debit() method and check so im guessing a boolean somewhere to return true or false based on if debit was accessed. This is what debit() looks like

    public void debit(Debit d) {
            balance += d.debit_getBalance();
     
            historyTransaction.add(valueToHistory(d.debit_getBalance()));
            historyBalance.add(toString());
        }

    Really any advice or help is greatly appreciated been stuck on this for 2 days and it's been bugging me.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Location
    Nigeria
    Posts
    12
    My Mood
    Cheerful
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: MinMaxAccount

    Am a beginner too but an idea of how the other classes look like would be really help me in helping you solve this problem.

    Also
    They said to override the debit() method
    if the debit method is in the superclass you can override it in the subclass by creating a method;

    public void debit(){
    ...
    }

    in the subclass.
    I AM MONEY B-)

  3. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: MinMaxAccount

    Really it's not possible to offer anything but the most general observation given what you've posted. No-one can do anything but guess what the BankingAccount looks like, or the Startup class.

    (Yes, we could guess that you're working on CIS 211: Challenge Problem Set 3, but no-one is going to do that. You need to describe the problem clearly. It'll give others a clue and, more importantly, it'll clarify your own thinking.)

    Work one method/constructor at a time. And justify each line of code you write in terms of what is actually stated in the question. Compile as you go and address compiler messages as they arise.

    So, to begin with the new class's constructor:

    public class MinMaxAccount extends BankingAccount{
        private int holdMax;
        private int holdMin=200;
     
        public MinMaxAccount(Startup s) {
            holdMax=s.startup_getBalance();
            holdMin=s.startup_getBalance();
            if(Startup s)
                balance += c.credit_getBalance(); // (I advise you to use braces)
        }    
    }

    Why is holdMin initialised to 200? (What part of the assignment instructions suggested that it should be?)

    Does this code compile? If not, and you can't understand the compiler's messages, post them there. And post enough code and description that others can compile and see what you see.

    -----

    To repeat: don't rush headlong into code. Work one small step at a time, keeping to the assignment's instructions, and understanding and addressing the compiler messages.