140 likes | 223 Views
Assignment 2. Salim Malakouti. Problem Definition?. Restaurant Owner Sells only potatoes Keep the profit Maximized. Minimize potatoes wasted + Minimize effort. Goal. In other words you are trying to keep the potatoes sorted with minimum effort possible. What is the problem?.
E N D
Assignment 2 Salim Malakouti
Problem Definition? • Restaurant Owner • Sells only potatoes • Keep the profit Maximized Minimize potatoes wasted + Minimize effort
Goal • In other words you are trying to keep the potatoes sorted with minimum effort possible
What is the problem? • You are using a Stack(box) to keep the potatoes • You can use a separate temporary box(Stack) • You are keeping everything in the truck in a stack • You can’t take anything back to the truck. • You need your employee to carry boxes between these boxes or the truck.
Code? • Use: take n from top of the main stack • Skip: Here you move on to the next day. So you should throw out any boxes that are expired + a message for each. • Report • A report for the latest delivery • A report for overall deliveries • Report include: • Number of boxes • Total cost • Cost of moving around • Quit
Display • Display the content of the current box • Different methods • Alter toString method
Receive *** • You receive a stack of boxes from file with the following format: <company>:<date>:<cost> • Example: receive 6 Spud Heaven:3:4.5 Potato Pot:4:5.0 Tuber Town:3:4.0 Perry's Potatoes:9:5.5 Potato Pot:10:5.0 SpudsRUs:3:4.0 • Hard Part: Giving an algorithm for itusingpops and pushes.
Good Question? • Can we sort them in the file? NO • If you want to sort them you have to use the stacks that you have.
A simple example? 1 3 4 3 5 4 1 8 5 10 9 8 9 10
Important • You won’t have any interactive interface? • So how inputs are given? • Through input files.
Sample Input File • display • report • use • 5 • receive • 5 • Fiveth:5:5.0 • Fourth:4:5.0 • Threeth:3:5.0 • Twoth:2:5.0 • Oneth:1:5.0 • display • report • quit • report • display • use • 8 • skip • receive • 4 • Bogus:0:100.0 • Weasel:0:150.0 • Squat:0:125.0 • Nada:0:100.0 • report • receive • 5 • Oneth:1:5.0 • Twoth:2:5.0 • Threeth:3:5.0 • Fourth:4:5.0 • Fiveth:5:5.0
How to read the file? • You need to parse it? Ideas?
Split function • String test = “1,2,3,4,5”; • String[] numbers = test.split(“,”); • System.out.print(numbers.length); OUT: 4 [“1”,”2”,”3”,”4”]