Jump to content

Banking with names!


TheScrub

Recommended Posts

just something i wrote

 

  • This will be able to return the id of the item name inside your bank
  • With this snippet you will need to check if the bank is open
  • With this snippet you must keep the anotation
  • Wrote more around the core so it will return an int
    public int bankItemIdByName(String Item_Name){
        Item items[] = client.getBank().getItems();
        int item_id = 0;
        for (Item single_item : items) {
            if (single_item.getName().equals(Item_Name)) {
             item_id =    single_item.getId();
             return item_id;
            }
        }
        return item_id;
    }
/*
 * This will return the id of the item by name
 * This was written by "TheScrub"
 * John of
 * Adelaide South Australia
 */                      




   /*Example use of the method provided above*/

  client.getBank().withdraw1(bankItemIdByName("Salmon"));
Edited by TheScrub
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

 

just something i wrote

 

  • This will be able to return the id of the item name inside your bank
  • With this snippet you will need to check if the bank is open
  • With this snippet you must keep the anotation
  • Wrote more around the core so it will return an int
    public int bankItemIdByName(String Item_Name){
        Item items[] = client.getBank().getItems();
        int item_id = 0;
        for (Item single_item : items) {
            if (single_item.getName().equals(Item_Name)) {
             item_id =    single_item.getId();
             return item_id;
            }
        }
        return item_id;
    }
/*
 * This will return the id of the item by name
 * This was written by "TheScrub"
 * John of
 * Adelaide South Australia
 */                      




   /*Example use of the method provided above*/

  client.getBank().withdraw1(bankItemIdByName("Salmon"));

Looks good but make use of naming conventions. It helps make understanding it easier for the person reading it. 

For example your method name is using correct naming conventions. Use mixed casing for parameter values with a prefix such as a or an. variables use mix casing as well and constants should utilize capitalizing each word with a underscore. 

 

for example:

public int getBankItemByName(aItemName){
        int itemID = 0;
        for (Item singleItem : client.getBank().getItems()) {
            if (single_item.getName().equals(aItemName)) {
             itemID =    singleItem.getId();
             return itemID;
            }
        }
        return -1;
    }
Edited by Exarticus
Link to comment
Share on other sites

 

 

just something i wrote

 

  • This will be able to return the id of the item name inside your bank
  • With this snippet you will need to check if the bank is open
  • With this snippet you must keep the anotation
  • Wrote more around the core so it will return an int
    public int bankItemIdByName(String Item_Name){
        Item items[] = client.getBank().getItems();
        int item_id = 0;
        for (Item single_item : items) {
            if (single_item.getName().equals(Item_Name)) {
             item_id =    single_item.getId();
             return item_id;
            }
        }
        return item_id;
    }
/*
 * This will return the id of the item by name
 * This was written by "TheScrub"
 * John of
 * Adelaide South Australia
 */                      




   /*Example use of the method provided above*/

  client.getBank().withdraw1(bankItemIdByName("Salmon"));

Looks good but make use of naming conventions. It helps make understanding it easier for the person reading it. 

For example your method name is using correct naming conventions. Use mixed casing for parameter values with a prefix such as a or an. variables use mix casing as well and constants should utilize capitalizing each word with a underscore. 

 

for example:

public int getBankItemByName(aItemName){
        int itemID = 0;
        for (Item singleItem : client.getBank().getItems()) {
            if (single_item.getName().equals(aItemName)) {
             itemID =    singleItem.getId();
             return itemID;
            }
        }
        return null;
    }

an int cant return null change that to -1

and use #equalsIgnoreCase(); instead of #equals();

Link to comment
Share on other sites

 

 

 

just something i wrote

 

  • This will be able to return the id of the item name inside your bank
  • With this snippet you will need to check if the bank is open
  • With this snippet you must keep the anotation
  • Wrote more around the core so it will return an int
    public int bankItemIdByName(String Item_Name){
        Item items[] = client.getBank().getItems();
        int item_id = 0;
        for (Item single_item : items) {
            if (single_item.getName().equals(Item_Name)) {
             item_id =    single_item.getId();
             return item_id;
            }
        }
        return item_id;
    }
/*
 * This will return the id of the item by name
 * This was written by "TheScrub"
 * John of
 * Adelaide South Australia
 */                      




   /*Example use of the method provided above*/

  client.getBank().withdraw1(bankItemIdByName("Salmon"));

Looks good but make use of naming conventions. It helps make understanding it easier for the person reading it. 

For example your method name is using correct naming conventions. Use mixed casing for parameter values with a prefix such as a or an. variables use mix casing as well and constants should utilize capitalizing each word with a underscore. 

 

for example:

public int getBankItemByName(aItemName){
        int itemID = 0;
        for (Item singleItem : client.getBank().getItems()) {
            if (single_item.getName().equals(aItemName)) {
             itemID =    singleItem.getId();
             return itemID;
            }
        }
        return null;
    }

an int cant return null change that to -1

and use #equalsIgnoreCase(); instead of #equals();

 

Opps my bad. Thanks for catching that :P

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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