Jump to content

Need some help with my deposit code


Recommended Posts

Posted
  if (this.bank.isOpen()) {
                    this.bank.depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe");
                    

Havent tested it so not sure if it woks, but it should :) 

 

I wrote that too, but i just thought if we include "axe" it wouldnt deposit it.

Thanks though :)

Posted (edited)

Strange if it worked before and suddenly stops working. Also not too important in this situation but I think using .contains() could be bad practice if you were dealing with strings that used other words with the sequence "axe" but were not axes. Again there's no case in this situation but if you were dealing with axel logs, .endsWith() would be better in this case since we know our axes  always ends with "axe"

 

 

Edited by Hayase
  • Like 1
Posted (edited)

best thing to do is make a constant that lists your axe names.

public static final String AXES = ("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe");

if (this.bank.isOpen()) {
                    this.bank.depositAllExcept(AXES);

This will always call the list of axes (which i doubt will ever change) this is a helpful technique and makes the code much more readable and modular.

Edited by DocMatson
  • Like 1
Posted

best thing to do is make a constant that lists your axe names.

public static final String AXES = ("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe");

if (this.bank.isOpen()) {
                    this.bank.depositAllExcept(AXES);

This will always call the list of axes (which i doubt will ever change) this is a helpful technique and makes the code much more readable and modular.

Thanks mate :)

I always code messy lol, this will help a bit.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...