✅ I'm having issues with "MostrarEstatisticasPorLocal/Sensor/Tipo" in Menu.cs
it was suposed to give me the information that is on the "Leitura" list, but for some reason, it just starts the first switch case without returning anything out of it. there's more issues I got but in a conversation I might be able to recall them. Thanks
https://github.com/JoValadares/Issue/tree/main/TrabalhoFinal_23-24
GitHub
Issue/TrabalhoFinal_23-24 at main · JoValadares/Issue
Contribute to JoValadares/Issue development by creating an account on GitHub.
107 Replies
it reaches line 31
u type in an option
or are u saying its not asking for an option and just returns nothing
it asks for an option, I tell him the option, and it just goes back to "Exibir" the menu method
which option u tell it
what do you mean?
what is the option ur trying to reach
when I do the first option, it works, still working on it, but it works for the time being, but the 2nd option has 3 more options below it, those are the ones not returning anything
sorry I switched them, it's the 2nd option that has 3 more below
ok so you're doing 2, then u want o select an option and it just goes back to the main menu?
yea, without showing the data that I asked for, which in the would be the average, minimum and maximum number of the data input
so its reaching this line https://github.com/JoValadares/Issue/blob/main/TrabalhoFinal_23-24/TrabalhoFinal_23-24/SistemaMonitorizacaoAmbiental.cs#L92
but the foreach prints nothing for example
yes
it's most likely that
you're creating a local variable leituras and updating it locally
so once it goes out of the scope its gone
you're not using the property leituras
which is subsequently used by your other methods
on DadosAmbientais.cs
so it makes sense that when u do DadosAmbientais.leituras its empty
so how would I fix that?
by using the property to store the data
but I have been using the property have I not?
look at the code above
specifically inside AdicionarLeitura
and explain to me what it does
I don't know how to explain it very well as english is not my language, but wouldn't that be like creating a new list and adding information into it?
or is it because of the static?
do you see the problem?
it's local?
what else?
it being local is 1 of the problems
I can't see what's the other
you're not using your property at all
the static is also bad and should not be needed its an instance you're initializing.
what do you mean I'm not using my property?
do you understand what a local variable is?
I am genuinely confused, I'm on my first year of C# so hence why I'm not really understanding of this
I would guess it's something only the same class can mess with
no
its something that exists within a block
i.e.:
so how would I call it if not inside a method "block"
so we have
now imagine this
what would this print
I think it would yea
would what?
José
u think Print() would print Jose?
it does not
yea I think so
because we never give the property Name the value Jose
we are giving it to a local variable we added inside Add
this would have used the property
leowest
REPL Result: Success
Quoted by
<@1102729783969861782> from #bot-spam (click here)
Compile: 511.528ms | Execution: 35.913ms | React with ❌ to remove this embed.
leowest
REPL Result: Success
Console Output
Quoted by
<@1102729783969861782> from #bot-spam (click here)
Compile: 503.540ms | Execution: 34.926ms | React with ❌ to remove this embed.
you see the difference on both code
one print jose, the other does not
I do see it
that is the impact of scopes and acessibility in c#
so I gotta remove "leituras = new..." from here?
u have to remove the first 2 lines
the first line declares the local variable u dont want that
and the 2nd line initializes it to empty
why would u want to make it empty every time u add new items to it
and last but not least u need to remove static from the property
https://learn.microsoft.com/en-us/shows/csharp-fundamentals-for-absolute-beginners/understanding-scope-and-accessibility-modifiers
this is very important to understand
I removed all static from all the methods in DadosAmbientais, but still it all goes rogue when I take away the static from Adicionar
I dont know what goes rogue is, if u have an error say the error
yes those errors are in a separate file
did u have some requiriment where u need
SistemaMonitorizacaoAmbiental to inherit from DadosAmbientais
because right now ur doing anything but that
yea but from what my professor told me, there's no need to be connected, since DadosAmbientais.cs is just a helping tool to connect SistemaMonitorizacaoAmbiental.cs and Leitura.cs
do u have written what he asked?
this would be there connection
ok
so remove this : DadosAmbientais
and again remove anything static in SistemaMonitorizacaoAmbiental.cs
static is used in very specific scenarios
anything?
not in the way you're using for instances
every static in that file
are you talking about methods or everything?
cuz in this image texts says "anything underlined must be static"
in the file SistemaMonitorizacaoAmbiental.cs remove the word "static" anywhere u see it
sure those u can leave
that's the only one I have in my SistemaMonitorizacaoAmbiental
ok good because the previous file was excessively using it
yea I can see that now
but now there is no connection
there is connection
I used the static and the : DadosAmbientais because VS2022 told me to, since I was so confused with everything being wrong
that is why I told u to watch the video above
how so, still got alot of erros, even more than before
so u have a better understanding of scope and acessibility
while I explain the rest
I was watching it but came back in hopes of understand better
will continue now
so in your SistemaMonitorizacaoAmbiental class the connection here would be
private DadosAmbientais dadosAmbientais;
That is how you access the instance of DadosAmbientais from it
so why do u have the errors?
because you're not using it
You're acessing the static class directly
not the instance u have declared
holy shit
that such a simple thing
and it somehow makes so much sense
I created a bridge and I was trying to barge through the back door
more like u created a blackhole and were trying to patch all over it to remove the holes
:catlaugh:
that's why access modifier, scopes etc are important to understand
so u know ur acessing the right thing
working the right context
etc
I would also make totalSensores private not public
same way u did to Sensor
also, I did do a little bit of cheating while doing this, could you briefly explain what "Distinct()"; does? or send a video about it?
leowest
REPL Result: Success
Result: DistinctIterator<string>
Quoted by
<@1102729783969861782> from #bot-spam (click here)
Compile: 309.039ms | Execution: 66.825ms | React with ❌ to remove this embed.
can I get one more push on this? why is it when I try to create both types of "Sensor" so "SensorTemperatura" and "SensorHumidade", it only creates Humidade, or at least only displays humidade
example, here I created three type 1 sensores, which should be "Temperatura", but instead they're shown as "Humidade"
mmmm
string tipo = tipoSensor == 0 ? "Temperatura" : "Humidade";
https://github.com/JoValadares/Issue/blob/main/TrabalhoFinal_23-24/TrabalhoFinal_23-24/Menu.cs#L110C16-L110C76
this one should be easy for u to spot
I don't see it
what are the options
the options of it being wrong in my opinion?
tipo is not being reached by the method
what are the option numbers
1-Temperatura 2- Humidade
ok and how would u compare if tipo was temperatura?
1 == Temperatura
and what are u not doing in your code
saying which of the option is which?
look closer
and think of what we just talked about
its not a tricky question
attibuiting a number to its specific option is the one answer that comes to head
it was "tipoSensor ==1" before but there was a bug going on cuz of it
and when I changed it it worked
well you input 1 or 2
that means u will never create a sensor of type temperature
because 0 will never be 1
oh I get it
but that would conflict with what's already in the method
conflict with what
that is literally saying ask the user for the type until he types a valid number
in this case valid number being 1 or 2
but wouldn't making the 0 a 1 here solve the issue?
cuz my program doesn't have all of that
yes it will
my point is ur not handling invalid scenarios
and for those it will always create a humidity sensor
that is how that ternary works
if its not 1 go to right hand
limiting the user to pick only 1 or 2 is one way, the other would be using a switch with 3 cases the 3rd case being an error and returning and not creating the sensor
or if,elseif,else which u prefer
would that be inside the for?
it would replace the 2 lines u have before tipo yes
but here what would I put on "tipo"
tipoSensor instead?
I didnt change those 2 lines
replace the 2 lines u have before tipo yesbefore tipo
oh I was replacing these two lines
I still have alot of issues but I'l ltry to solve them by myself for now, thanks for all the help tho, sorry for bothering aswell
not a bother
but the parts that were not working are working now correct?
yea, the ones I did make an issue
ok 🙂 well feel to ask more or $close up to u
If you have no further questions, please use /close to mark the forum thread as answered
if I really can't seem to grasp the error I will, thanks again!