I am currently writing code for a program that will controll more than one TV in another class "Class fernsehen".I am creating 4 objects and then in the first case (case 0: will end up as 1 eventually if i can get it to work).where i get user input for the object to refer to in the switch case method.I am having no luck so far and maybe someone has a tipp for me.
here is the code so far
i am only trying it for the moment in case 1: until i get it worked out so you only need to look until there really to see my problem.
Is this possible to do in Java? if so how?
I think i spot the problem.
The variable input never gets set.
It is null since this moment and never gets assigned a value, even when you go through case 0 with tvChoise 1 or 2.
You are shadowing the variable with a local one there and assigning the actual object to the local variable.
On a sidenote: it might be better to declare input of the type fernseher right away since i assume you won't be using it for anything less specific than a fernseher.
On a second sidenote: It's more common to have classnames start with a capital letter. (for example Fernseher instead of fernseher)
Thank you very much and that was a stupid mistake for sure lol. I know i should use a capital letter for the class but sometimes i type quicker than i think;) I need to start paying more attention to
that sort of thing as i actually can get some things working now;) I also need to start commenting on my code!! I never do that but i know it is a good practice...