✅ I need help with building a project named train station system

I feel a bit confused about how to start the project, that's why I need help
113 Replies
Anton
Anton2y ago
$main
MODiX
MODiX2y ago
$mains
Anton
Anton2y ago
$mains
MODiX
MODiX2y ago
The possible signatures for Main are
public static void Main() { }
public static int Main() { }
public static void Main(string[] args) { }
public static int Main(string[] args) { }
public static async Task Main() { }
public static async Task<int> Main() { }
public static async Task Main(string[] args) { }
public static async Task<int> Main(string[] args) { }
public static void Main() { }
public static int Main() { }
public static void Main(string[] args) { }
public static int Main(string[] args) { }
public static async Task Main() { }
public static async Task<int> Main() { }
public static async Task Main(string[] args) { }
public static async Task<int> Main(string[] args) { }
public is not required (can be any accessibility). Top-level statements are compiled into a Main method and will use an appropriate signature depending on whether args is referenced, the await operator is used and/or an explicit return statement is used. https://docs.microsoft.com/en-US/dotnet/csharp/fundamentals/program-structure/main-command-line
Main() and command-line arguments
Learn about Main() and command-line arguments. The 'Main' method is the entry point of an executable program.
Anton
Anton2y ago
you put code in the main method?
The king of kings
what are these methods you wrote above lol seems a bit confusing
Anton
Anton2y ago
these are signatures
The king of kings
I mean you posted something and you shoed me something else 🤷🏻‍♂️
Anton
Anton2y ago
for the main method
The king of kings
Ok but what why do I need all these methods then?
Anton
Anton2y ago
you didn't know how to start you start by putting your code in main
The king of kings
Ah! Ok! Sorry my brain fog is totally missed up. I guess I asked the wrong question what I mean is that the project seems a bit confusing to me not where to start 😄 it's kind of complicated
Anton
Anton2y ago
well it break down then what are the high level steps you need to take ?
The king of kings
that's why many people say we need to break down our project into small steps. You're definitely right. That's why it feels so dame confusing. well! I don't know what would be these steps. I mean from what I see the goal of the project is to create a program/ app that can check how many passengers rides, stays and get off, right? and they have specified a limited numbers based on the recommendations max 40 passengers are allowed to be in the train
Anton
Anton2y ago
well skim the image you sent what are the two big glaring things? that are each even on separate lines
The king of kings
capacity 40 & 10 stations right?
Anton
Anton2y ago
no input and output
The king of kings
Ok
Anton
Anton2y ago
how do you get from input to output? what do you get as a result of input?
The king of kings
by getting user input and then print out the result I get the output
Anton
Anton2y ago
how do you get the results?
The king of kings
well
Anton
Anton2y ago
I'm expecting a high level answer
The king of kings
if I'm intending to perform some condition statements for user input then I could print the output
Anton
Anton2y ago
well kinda. the answer I was expecting is "we have to apply certain transformations / processing to the user input"
The king of kings
Ok that's right
Anton
Anton2y ago
alright so the three big things are input -> processing -> output
The king of kings
yes sir
Anton
Anton2y ago
is any user input valid?
The king of kings
nope
Anton
Anton2y ago
so you also have to validate the user input
The king of kings
by setting guard
Anton
Anton2y ago
input + validation -> processing -> output
The king of kings
throwing exception
Anton
Anton2y ago
this is the structure that you should use for all your programs
The king of kings
really that's very interesting to learn
Anton
Anton2y ago
this is analogous to functions too they take parameters -> apply validation or contracts -> do some logic -> return the result
The king of kings
you're right. This is what I've been doing in all my projects and you just showed me the simple flow
Anton
Anton2y ago
now break down which part of the problem goes into which category
The king of kings
man you are incredibly awesome in transforming confusing stuff into more clear understandable stuff, i really like learning with you that's a really good question this problem goes to the train driver getting passengers record/ number of how many the enter the train, get off and exist currently, right? this should be the primary step of the program getting passengers data
Anton
Anton2y ago
first step is to get tge data form the user and do the validation
The king of kings
that's correct do you know what confused me most every time I build a project, I set and think! Should I use properties, method, list/array or plain condition statements. this is my problem for example, look what I have don so far.
The king of kings
I don't mean to overwhelm you with too much stuff you got busy or something?
Anton
Anton2y ago
the simplest thing is just plain structs do everything in you main method treat objects as just groups of variables whatever you have is not right since you know so little, stay away from OOP and properties and constructors and stuff like that you create an object, you set public fields, you use the data stored in the fields forget instance methods exist every method should be static otherwise you are definitely going to get overwhelmed
The king of kings
Ok! Great. do you think my knowledge is bad at these, I don't think so. I know how these work, but my problem is just not knowing if they are the right option for the specific project. what do you mean here?
Anton
Anton2y ago
don't use instance methods because they will confuse you more at least for the time being it's always the same for simple projects. you define the data (the train struct or class) and then you do operations on the data (calling static methods passing in the data, or just calculating things inline)
The king of kings
Ok! You mean by calling methods and use them through an instantiating an object? When am I going to learn them if I don't practice them then? "you do operations on the data" you mean applying the condition statements, right?
Anton
Anton2y ago
no I mean static methods. do you know what static methods are? I mean the processing part
The king of kings
I've watched some tutorials on it, isn't that I don't need to instantiate an object, but I could call the method directly from the class Train?
Anton
Anton2y ago
yes and you should use them at te beginning. I suggest you don't use instance methods make a static method and pass the train as a parameter you don't completely understand the idea of parameters yet don't jump into OOP unless you have that down at least + procedural programming is so so much easier to understand for a beginner (yeah I misread the message hence I'm rewording some stuff)
The king of kings
I do understand parameter and arguments and OOP and all that, but I don't know the why and this is why I get confused sometimes and I think it requires more experience like by building a various of projects. like for .e.g why should pass parameters in the method?
Pobiega
Pobiega2y ago
how else do you pass a value into a piece of code? methods without arguments would be significantly less useful
The king of kings
Oh! That was very interesting to know, you're right. why the hell we use methods if they don't enable us to print out any value.
Pobiega
Pobiega2y ago
you can stick a Console.WriteLine(); in any method you want, but a lot of the time you dont actually want that
TheRanger
TheRanger2y ago
odd to make a variable of Train Array stations a Train is a Train, why each Train should know the number of Trains ?
The king of kings
You're right. I can print out any value using the static method invocation and Console.WriteLine(); great to see you show up bro recently, I started a new project from my previous course I took although it's written in Swedish.
Pobiega
Pobiega2y ago
Plenty of people here read swedish just fine, if you have detailed instructions in swedish, but as you probably know we prefer all communication over official channels are in english .)
The king of kings
it seems a bit confusing to me where to start and what to do
Pobiega
Pobiega2y ago
seems to me your input is a text file or possibly a series of inputs to STDIN (Console.ReadLine()) but I'd develop based on a text file easier to test
The king of kings
that's right. English is the main language when it comes to programming
Pobiega
Pobiega2y ago
the first row in the file is two numbers separated by a space
The king of kings
what do you mean by that? text file? this project feels complicated to understand what they want
Pobiega
Pobiega2y ago
a little bit, sure they just say "the first input contains two numbers..." they dont really specify in what format that input will be its usually either a file or STDIN, which are both streams - so you can actually code in a way that supports both.. but that might be harder to use for a beginner
The king of kings
input of what?
Pobiega
Pobiega2y ago
it doesnt say.
Pobiega
Pobiega2y ago
Pobiega
Pobiega2y ago
thats all it says
The king of kings
yeah! This is what confused me most my friend. I took this course online and I had a teacher called David, he used not offer any help that's why I failed at the course.
Pobiega
Pobiega2y ago
bad teachers are dime a dozen, I'm afraid
The king of kings
that's right. I was very disappointed to waste 3 months on the course. I mean all I understood is that, they want me to create a program where its features distinct with getting input data and do calculation + comparing for these data and then print out the result/ values of these data so when any new passengers need to ride in the train the the driver would check if there's available seats then the app would display if possible or not possible. am I seem right or wrong do you think?
Pobiega
Pobiega2y ago
something along those lines the first line of input is the trains capacity AND the total number of stations the rest of the lines are each one station with each station having number of people who get OFF the train get ON the train are left behind
The king of kings
the next part of the assignment that confuses me most is the 10 stations, don't really know what purpose of these stations 🤷🏻‍♂️
Pobiega
Pobiega2y ago
your goal is to return a boolean variable: if this "route" is valid or not according to the rules
The king of kings
Ok I understood is that if the train contains 1 - 40 passengers then it's fall, we can't take in any more passengers not possible, they're gonna wait for the next train.
Pobiega
Pobiega2y ago
you could do this in many ways, and the faster/simpler ones are probably not using OOP here but you certainly CAN use OOP if you want
The king of kings
Ok! Wow, that's very satisfying to see. I don't expect to get any code snippet, since I need to practice logical skill, but some tips/ hints or any guidance would be appreciated 🙂
Pobiega
Pobiega2y ago
Step 1, parse the input. Step 2, make a method that rakes the parses input in and returns the bool out
The king of kings
Ok! I should be able to use the snippet that you provided me yesterday. https://discord.com/channels/143867839282020352/143867839282020352/1082372654864015460
MODiX
MODiX2y ago
Pobiega#2671
public static T GetFromConsole<T>(string prompt) where T : IParsable<T>
{
while (true)
{
Console.Write(prompt);
if (T.TryParse(Console.ReadLine(), null, out var value))
{
return value;
}

Console.WriteLine("Invalid format. Try again.");
}
}
public static T GetFromConsole<T>(string prompt) where T : IParsable<T>
{
while (true)
{
Console.Write(prompt);
if (T.TryParse(Console.ReadLine(), null, out var value))
{
return value;
}

Console.WriteLine("Invalid format. Try again.");
}
}
Quoted by
<@!973964186956726313> from #chat (click here)
React with ❌ to remove this embed.
Pobiega
Pobiega2y ago
Depends? You dont need that snippet if you go with the file route and even then, your core algorithm (aka the actual problem solving) should probably just take parsed input in I'd probably start out with something like this
public static class Program
{
public static void Main()
{
var input = GetInputFromFile("trains.txt");
var result = SolveProblem(input);
Console.WriteLine(result);
}

private static bool SolveProblem(TrainProblemInput input)
{
throw new NotImplementedException();
}

private static TrainProblemInput GetInputFromFile(string path)
{
throw new NotImplementedException();
}
}

record TrainStation(int On, int Off, int LeftBehind);
record TrainProblemInput(int TrainCapacity, TrainStation[] Stations);
public static class Program
{
public static void Main()
{
var input = GetInputFromFile("trains.txt");
var result = SolveProblem(input);
Console.WriteLine(result);
}

private static bool SolveProblem(TrainProblemInput input)
{
throw new NotImplementedException();
}

private static TrainProblemInput GetInputFromFile(string path)
{
throw new NotImplementedException();
}
}

record TrainStation(int On, int Off, int LeftBehind);
record TrainProblemInput(int TrainCapacity, TrainStation[] Stations);
@Faraj
The king of kings
Ok! I'm not really sure what you mean by file route?
Pobiega
Pobiega2y ago
as in, store the input as a file you've only sent screenshots of the instructions, so I can't tell for sure, but it seems reasonable to have a file with stuff like
The king of kings
I'm not sure what this code is doing! I see that you're throwing exceptions.
Pobiega
Pobiega2y ago
36 10
10 10 0
10 5 0
...
36 10
10 10 0
10 5 0
...
yeah, thats a special exception that just means.. "this method isnt done yet" meaning you should replace it with the code that does what the method should do
The king of kings
this is just a simple console application not using any framework just you know didn't really understand what you mentioned here what are those numbers for? 🙂
Pobiega
Pobiega2y ago
Did you read the instructions? 😛 yes, the above code is indeed for a console app..
The king of kings
Ok! But it seems a bit advanced code to me.
Pobiega
Pobiega2y ago
its really not. its not OOP in any way, its just using methods and your own types (the records at the bottom)
The king of kings
like you're using bool in the methods which I've never used and you're using record which I haven't seen before
Pobiega
Pobiega2y ago
bool is the datatype for the values true and false it can only ever be one of those two. thats it. its the simplest data type there is 🙂
The king of kings
I know but you're using it in declaring method
Pobiega
Pobiega2y ago
sure? but its just a data type a method that returns a bool isnt different from a method that returns a string, or an int
The king of kings
are you using some overriding methods?
Pobiega
Pobiega2y ago
its just the return type. nope. not at all
The king of kings
Ok
Pobiega
Pobiega2y ago
its just two static methods (not counting Main), in a static class. thats it. records are like classes, but immutable (cant be changed) by default and have this nifty syntax that is really short 🙂 its just a good way to make types for data
The king of kings
Ok so the goal of this code is to?
Pobiega
Pobiega2y ago
its just a boilerplate, a starting point the goal is that you would replace the "throw new..." lines with actual code that does what the methods say they do and then when you run the program, it would solve the train problem I'm sure you've heard "break down the problem" a million times by now
The king of kings
Ok! That seems clear to me now.
Pobiega
Pobiega2y ago
this is that. ive broken down the problem once, into two parts
The king of kings
of course many times
Pobiega
Pobiega2y ago
part 1: reading and parsing the input part 2: solving the actual problem this is a very common first step, as you want to separate the reading and understanding of your inputs from the actual logic
The king of kings
Ok
Pobiega
Pobiega2y ago
now, as you solve these two parts, you'll likely want/need to create new methods to help solve the individual parts. thats fine, you are just further breaking down the problems
The king of kings
Ok! You know what my friend, I really would like to call you just a 15 minutes so I can understand a bit more clearly, that way I don't need to spend many days on building only one simple project, is it ok?
Pobiega
Pobiega2y ago
sure, lets go to #dev-vc-1
The king of kings
awesome man, thanks a lot.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
The king of kings
👍
Want results from more Discord servers?
Add your server