I am trying to get round a rather annoying issue in my homework.
Basically the task is to create a fake ordering UI where the user puts in some variables about the type of box they need to order and then presses a button. Behind the scenes the app should be validating which pipe fits the users needs and then instantiate a new box object and execute the methods inside the new object.
I am basically struggling to find a way that isn’t stupid which allows for the UI to validate a choice before creating a new object, a method is given to us to begin with and is referred to a ‘brute force method’ which has a massive if statement inside the button click which does the checking there, now I am 100% sure there is an easier way to do it although the only thing I can come up with is holding constants or statics in a class and checking each class before creating one.
Scenario:
The idea is that each box the company sells has certain features (thickness, laminated, colour and other things) while others boxes don’t, I need to be able to figure out when the order button is clicked what box the order fits once I know the box type that the order fits I should create a new object of that box and run the cost() method, if it doesn’t fit any box the company sells then I should prompt the user. The program must use abstraction.
The class isn’t at a high level at the moment so I can’t use enums and lookup tables which is causing me problems.
Thanks for any help in advance.
Sounds to me like they just want you to show several classes (one for each type of box) which all inherit or implement a common interface with methods like ‘getWidth’, ‘getHeight’ etc. You can then write a simple loop to iterate over a collection of box type instances, evaluating their suitability before returning the list of compatible box types.