0

So i have an assignment that requires me to program and create freight Id and update the status for every new order.

Freight ID: This should be a unique number auto generated using the following simple algorithm.
• Use the numbers '1939' as the first freight Id. Increment it by 1 for the next freight.

Freight status: can be one of the codes: ‘D’,’P’, or ‘W’. “D”: Delivered to the destination “P”: Processing “W”: Waiting at the ware house to be delivered.
When a new freight order is created, its initial status should be recorded as ‘W’.

I have tried some ways but i just cant seem to understand how I should auto generate and increment a freight ID as well as create a freight status.

public void freightID() 
{
    int [] freightID = {1939,1939,1939,1939,1939};
    for (int i = 0; i<ID_SIZE; i++)
    {
        int answer = ++freightID[0];
        System.out.println(freightID[i]*1);
   }

}

I know this is completely wrong but i just wanted to show what i tried.

  • How is your question related to the greenfoot tag? Also note: a lot of context is missing. It is really hard to help with homework when that context is missing. I think you would be better off discussing this with your peers, or tutors, or instructors. – GhostCat Sep 10 '19 at 10:52
  • Its related because im using greenfoot for this assignment. There is alot of detail which i didnt want to post since most of it is already solved. I wouldve also asked my tutor but they dont really help since they are very indirect with their responses. In terms of context, Id like to know what can I provide to make it easier to understand? – lahari kalaimalai Sep 10 '19 at 11:03
  • Well, like: how will a user interact with your program? Your question is somehow like "how do I draw a picture?" . There are zillions of ways of doing that. Maybe you should read this here: https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question – GhostCat Sep 10 '19 at 11:06

1 Answers1

0

So as far as I understand your assignment you have to create a class "Order" which has the attribute "freight ID" and "status". The first order will start with the ID 1939 and every new Order needs to increment this number. Creating such Order the status is W. After the creation of the order you want to have the possibility to change the status. If thats correct i have the solution for you:

public class Order {

    public Order() {
        this.freightStatus = freightStatus.W;
        this.freightID = startID;
        startID++;
    }

    private static int startID = 1939;
    private int freightID;
    private FreightStatus freightStatus;

    enum FreightStatus {
        D, P, W
    }

    public void setFreightStatus(FreightStatus freightstatus) {
        this.freightStatus = freightstatus;
    }

    public FreightStatus getFreightStatus() {
        return this.freightStatus;
    }

    public int getFreightID() {
        return this.freightID;
    }

    public static void main(String args[]) {
        Order orders[] = new Order[5];
        for (int counter = 0; counter < orders.length; counter++) {
            orders[counter] = new Order();
        }

        for (Order order : orders) {
            System.out.println(order.getFreightID() + " " + order.freightStatus);
        }

        for (int counter = 0; counter < orders.length; counter++) {
            orders[counter].setFreightStatus(FreightStatus.D);
        }

        for (Order order : orders) {
            System.out.println(order.getFreightID() + " " + order.freightStatus);
        }
    }
}

I hope thats it what you asked for, if not, please clarify your question.

ChristianM
  • 129
  • 6
  • I guess i cant really test it out because im using greenfoot but the logic is correct its just that i have different keywords. Thankyou though – lahari kalaimalai Sep 11 '19 at 21:57