Building a console app for a uni assignment and struggling
Having serious trouble coding this console app in c# and would appreciate help, I have a UML diagram to use
37 Replies
$details
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, what you expect the result to be, what .NET version you are using and what platform/environment (if any) are relevant to your question. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Sorry, new here ^^" I need to create a console app that functions as a food delivery app (Just eat, Uber Eats etc...) Needs to be able to read from a selection of files formatted in a particular way, split those files into various different strings to use as names, ingredients,prices and recipes for fooditems. Also need to be able to add fooditems into an order etc
alright, which part are you getting stuck on?
Mainly the file reading, not sure how to split the file as its in quite an annoying format, also cant seem to get the current directory of the file so instead have to hardcode the directory which sucks
do you have an example of the format and the code you're trying to use to find the files?
Name:Slow Food Emporium
Toppings:[<cheese,80>,<tomato sauce,40>,<bbq sauce,40>,<peppers,40>,<pineapple,40>,<ham,100>]
Garnishes:[<cheese,80>,<bacon,100>,<fried onions,40>]
Pizza:<Name:Hawaiian,Toppings:[tomato sauce,cheese,pineapple,ham],Price:550>
Pizza:<Name:Margherita,Toppings:[tomato sauce,cheese],Price:500>
Burger:<Name:Classic Hamburger,Garnishes:[],Price:350>
Burger:<Name:Bacon Burger,Garnishes:[cheese,bacon,fried onions],Price:450>
the numbers after the ingredients are the prices of individual ingredients, since youll be able to add extra toppings on items
i will say this format sucks
:SCshocked:
yeah :((((
were you given any specific tools/guidance on how to parse the file?
not really no, we did basic file reading in one lecture but we were thrown way in the deep end for this one
im stunned that unis are such an important part of education and then they pull this :SCgetoutofmyhead:
so you have a couple of lines that look like they aren't menu items themselves, just lists of options
then you have actual menu items that can have optional add-ons from those lists?
yes!
so i know that if i read the file and create an array of strings, entry 0 1 and 2 will always be name, ingredients, and garnishes
are you expecting to be given "bad" files to see if your code rejects it or not?
because if not you can probably take some shortcuts
we get to make all the files ourself so nah no need to catch myself out
i imagine theyll use one of their own just to make sure we use the same format tho
you can make the files yourself but the format you sent is required?
yes!
my point is what if they give you a file where the order of the first 3 lines are different, or there are invalid characters that don't match the format, etc
i don't really understand why they'd use such a complex format if you could get away with ignoring most of it
JSON would suite this far more
i think.
honestly i imagine a big try catch loop would suffice since its only 1st year
any standard serialization format would, but if the exercise is to parse this specific thing then that's not really an option
ah ok
personally i'd start looking at how much of the actual file structure you can ignore
if you know the first 3 lines are always name, toppings, garnishes, then strip out all the contents except what you actually care about which are the actual name and the lists of toppings and garnishes
then you know those lists have items that are always a name and a price, so get rid of the angle brackets and split it into a plain array where every 2 elements make an item
i have a suggestion but idk if its bad or not :SCgetoutofmyhead:
its just super confusing because up until now, projects and labs have been super basic
ill take anything!!
i'm suggesting doing some pre-processing to turn
Toppings:[<cheese,80>,<tomato sauce,40>,<bbq sauce,40>,<peppers,40>,<pineapple,40>,<ham,100>]
into something like
cheese,80,tomato sauce,40,bbq sauce,40,peppers,40,pineapple,40,ham,100
simplify the problem basically
all the other garbage doesn't give your program any useful informationyou know these 3 the rest is kinda dynamic
so if those are not provided in this specific order i think it would be an option to hardcode the 3 Keys and treat the rest with the standard serializer youll write so you can avoid line issues if that was what you wanted to go with
sorry had to go get laundry ;-;
ill play around with some stuff and see what happens, thank you for the advice guys!
just break it into pieces, im assuming you still have time for this so just experiment with it
personally i think this is a great approach for it
i do! got a week to finish
relatable af frfr
x333 this is my main downfall rn, work and moving house has made it impossible to get this done
just so so tired...
Nah you'll get there
:SCyay:
tyyyyyy i hope so, if i fail this i fail the module :)))
nah, don't cut corners with the parser
they're always straightforward to write, just tedious
just bite the bullet and write the most straightforward code you can
just try to solve it head on, you'll be surprised how easy it actually is if you just do the thing the most obvious way