0

I'm fairly new to Java and having a hard time understanding how to access the methodss and setting variables to a specific value that are in my Bean class. I am creating new instances of the Bean class and wanting to set the variables to a specific value. I also want to store these all in a List. Here is the code I have: public class ReportBean { //instance variables

private String inventoryFulfillmentSpecialist;
private String inventoryFulfillmentManager;
private String poNumber;
private String poReferenceNumber;
private String shipToLoc;
private String poStatus;
private String importStatus;
private String orderType;
private String item;
private String mismatchFields;
private String tValue;
private String hValue;

/**
 * Getter method for variable 'inventoryFulfillmentSpecialist'.
 * @return String
 */
public String getInventoryFulfillmentManager() {
    return inventoryFulfillmentManager;
}
/**
 * Getter method for variable 'inventoryFulfillmentSpecialist'.
 * @return String
 */
public String getInventoryFulfillmentSpecialist() {
    return inventoryFulfillmentSpecialist;
}
/**
 * Getter method for variable 'poNumber'.
 * @return String
 */
public String getPoNumber() {
    return poNumber;
}
/**
 * Getter method for variable 'poReferenceNumber'.
 * @return String
 */
public String getPoReferenceNumber() {
    return poReferenceNumber;
}
/**
 * Getter method for variable 'shipToLoc'.
 * @return String
 */
public String getShipToLoc() {
    return shipToLoc;
}
/**
 * Getter method for variable 'poStatus'.
 * @return String
 */
public String getPoStatus() {
    return poStatus;
}
/**
 * Getter method for variable 'importStatus'.
 * @return String
 */
public String getImportStatus() {
    return importStatus;
}
/**
 * Getter method for variable 'orderType'.
 * @return String
 */
public String getOrderType() {
    return orderType;
}
/**
 * Getter method for variable 'item'.
 * @return String
 */
public String getItem() {
    return item;
}
/**
 * Getter method for variable 'tssVsPoMisMatchFields'.
 * @return String
 */
public String getTssVsPODirectMisMatchFields() {
    return tssVsPODirectMisMatchFields;
}
/**
 * Getter method for variable 'tradeStoneValue'.
 * @return String
 */
public String getTradeStoneValue() {
    return tradeStoneValue;
}
/**
 * Getter method for variable 'hostValue'.
 * @return String
 */
public String getHostValue() {
    return hostValue;
}
/**
 * Setter method for variable 'inventoryFullfilmentManager'.
 * @param inventoryFulfillmentManager String
 */
public void setInventoryFulfillmentManager(String inventoryFulfillmentManager) {
    this.inventoryFulfillmentManager = inventoryFulfillmentManager;
}
/**
 * Setter method for variable 'inventoryFulfillmentSpecialist'.
 * @param inventoryFulfillmentSpecialist String
 */
public void setInventoryFulfillmentSpecialist(
        String inventoryFulfillmentSpecialist) {
    this.inventoryFulfillmentSpecialist = inventoryFulfillmentSpecialist;
}
/**
 * Setter method for variable 'poNumber'.
 * @param poNumber String
 */
public void setPoNumber(String poNumber) {
    this.poNumber = poNumber;
}
/**
 * Setter method for variable 'poReferenceNumber'.
 * @param poReferenceNumber String
 */
public void setPoReferenceNumber(String poReferenceNumber) {
    this.poReferenceNumber = poReferenceNumber;
}
/**
 * Setter method for variable 'shipToLoc'.
 * @param shipToLoc String
 */
public void setShipToLoc(String shipToLoc) {
    this.shipToLoc = shipToLoc;
}
/**
 * Setter method for variable 'poStatus'.
 * @param poStatus String
 */
public void setPoStatus(String poStatus) {
    this.poStatus = poStatus;
}
/**
 * Setter method for variable 'importStatus'.
 * @param importStatus String
 */
public void setImportStatus(String importStatus) {
    this.importStatus = importStatus;
}
/**
 * Setter method for variable 'orderType'.
 * @param orderType String
 */
public void setOrderType(String orderType) {
    this.orderType = orderType;
}
/**
 * Setter method for variable 'item'.
 * @param item String
 */
public void setItem(String item) {
    this.item = item;
}
/**
 * Setter method for variable 'tssVsPODirectMisMatchFields'.
 * @param tssVsPODirectMisMatchFields String
 */
public void setTssVsPODirectMisMatchFields(String tssVsPODirectMisMatchFields) {
    this.tssVsPODirectMisMatchFields = tssVsPODirectMisMatchFields;
}
/**
 * Setter method for variable 'tradeStoneValue'.
 * @param tradeStoneValue String
 */
public void setTradeStoneValue(String tradeStoneValue) {
    this.tradeStoneValue = tradeStoneValue;
}
/**
 * Setter method for variable 'hostValue'.
 * @param hostValue String
 */
public void setHostValue(String hostValue) {
    this.hostValue = hostValue;
}

List<ReportBean> reportData = new ArrayList<ReportBean>();
ReportBean bean1 = new ReportBean();
ReportBean bean2 = new ReportBean();
ReportBean bean3 = new ReportBean();
bean1.setInventoryFulfillmentManager("Jackie Luffman");
bean1.setInventoryFulfillmentSpecialist("Phillip Smith");
bean1.setPoNumber("348794798");
bean1.setPoReferenceNumber("140629700");    

public String toString()
{
    StringBuilder sb = new StringBuilder();
    sb.append("ReportBean: ");
    sb.append("inventoryFulfillmentManager = " + getInventoryFulfillmentManager() + " ");
    sb.append("inventoryFulfillmentSpecialist = " + getInventoryFulfillmentSpecialist() + " ");
    sb.append("poNumber = " + getPoNumber() + " ");
    sb.append("poReferenceNumber = " + getPoReferenceNumber() + " ");
    sb.append("shipToLoc = " + getShipToLoc() + " ");
    sb.append("poStatus = " + getPoStatus() + " ");
    sb.append("importStatus = " + getImportStatus() + " ");
    sb.append("orderType = + " + getOrderType() + " ");
    sb.append("item = " + getItem() + " ");
    sb.append("tssVsPODirectMisMatchFields = " + getTssVsPODirectMisMatchFields() + " ");
    sb.append("tradeStoneValue = " + getTradeStoneValue() + " ");
    sb.append("hostValue = " + getHostValue() + " ");

    return sb.toString();
}

}

I get errors and when I try to say bean1.setxxxx I get the red squiggly line and it's says "syntax error on token(s), misplaced construct(s)". If anyone could help it would be much appreciated, thanks.

5
  • 2
    Post your ReportBean class as well. What you've got so far isn't enough information. The actual error would be useful as well. Commented Jul 2, 2014 at 16:32
  • 2
    I suspect that you don't quite understand what "static" means. Commented Jul 2, 2014 at 16:35
  • What do you mean with static? Create new instance of the object setting all fields at once? If you want to access the methods check if the method is visible where you want to access. Usually getters and setters should be public. Commented Jul 2, 2014 at 16:38
  • I guess I was confusing myself, I basically just want to access the methods and set the values. I included the getters and setters in the class as well as the error. Commented Jul 2, 2014 at 17:13
  • @daniel souza I'm a little new to the world of programming, I now get the concept though. I need to include the code I'm looking for in the main class, not the bean class itself, and just make instances of the bean class in main and set the values of those fields there. Commented Jul 3, 2014 at 11:16

2 Answers 2

1
bean1.setInventoryFulfillmentManager("Jackie Luffman");
bean1.setInventoryFulfillmentSpecialist("Phillip Smith");
bean1.setPoNumber("348794798");
bean1.setPoReferenceNumber("140629700"); 

This part of the code is just floating inside your class. This is a structured programming thing. In Java, all the code must be inside a method or function.

you must use a static main method to encapsulate this:

public static void main(String[] args) {
    //yourcode here
}
Sign up to request clarification or add additional context in comments.

Comments

0
import java.util.ArrayList;

class ReportBean {
    private String InventoryFulfillmentManager;
    private String InventoryFulfillmentSpecialist;
    private String PoNumber;
    private String PoReferenceNumber;

    // Default constructor
    public ReportBean() {}

    public void setInventoryFulfillmentManager(String value) {
        this.InventoryFulfillmentManager = value;
    }

    public void setInventoryFulfillmentSpecialist(String value) {
        this.InventoryFulfillmentSpecialist = value;
    }

    public void setPoNumber(String value) {
        this.PoNumber = value;
    }

    public void setPoReferenceNumber(String value) {
        this.PoReferenceNumber = value;
    }
}

public class Main {
    public static void main(String[] args) {
        ArrayList<ReportBean> list = new ArrayList<>();
        for(int i = 0; i < 3; i++) {
            list.add(new ReportBean());
            list.get(i).setInventoryFulfillmentManager("Jackie Huffman");
            list.get(i).setInventoryFulfillmentSpecialist("Phillip Smith");
            list.get(i).setPoNumber("348794798");
            list.get(i).setPoReferenceNumber("140629700");
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.