0

whats the problem? (line 33) , sololearn cant run the program... (run it on another platform). the problem is to tell that if th

import java.util.Scanner; class door{ static boolean open = false; public static void openDoor(){ open = true; } public static void closeDoor(){ open = false; } } public class Main { public static void main(String[] args) { door d = new door(); Scanner s = new Scanner (System.in); String x = s.nextLine(); x = x.substring (0 , 1).toUpperCase() + x.substring (1); if (x.equals ("Open")){ d.openDoor(); System.out.println ("Door is open"); }else if (x.equals ("Open") && d.open){ System.out.println ("The door is already open..."); }else if (x.equals ("Close") && d.open = false){ System.out.println ("The door is already closed..."); } else{ System.out.println ("ERROR"); } String r = s.nextLine(); r = r.substring (0 , 1).toUpperCase() + r.substring (1); if (r.equals ("Close")){ d.closeDoor(); System.out.println ("Door is closed"); }else if (r.equals ("Open") && d.open){ System.out.println ("The door is already open"); } else{ System.out.println ("ERROR"); } } }

1st Jun 2020, 1:10 PM
Yahel
Yahel - avatar
8 Respuestas
+ 1
Rithea Sreng wow, thanks! (How didnt I think of that :) ).
1st Jun 2020, 6:32 PM
Yahel
Yahel - avatar
0
Please always link your code so that we can run it. Open your code and on top right you can see the share option. Click it, copy and paste the link here. Also your question is incomplete. Use the description section to explain your problem but you have written it in the title which allows less number of characters.
1st Jun 2020, 1:22 PM
Avinesh
Avinesh - avatar
0
https://code.sololearn.com/cQ0tULjXZYU5 run the program and see the problem... how can i fix it? thanks
1st Jun 2020, 1:25 PM
Yahel
Yahel - avatar
0
d.open == false
1st Jun 2020, 1:58 PM
Taste
Taste - avatar
0
https://code.sololearn.com/cQ0tULjXZYU5 so why now if i write the first time "Close" and also the second time "Close", wh after the second time its saying "Door is closed"?
1st Jun 2020, 2:22 PM
Yahel
Yahel - avatar
0
yahel what are you expecting the output to be? Do you mind writing a couple of combination of inputs and corresponding outputs.
1st Jun 2020, 2:49 PM
Avinesh
Avinesh - avatar
0
Avinash , in the first Scanner i write "close" and then its saying "The door is already closed..." (as it should). at the second Scanner i write "close" again and its not saying "The door is already closed..." again (as it shoul be). Contrary to that, the system says "Door is closed". All the other combinations work fine.. (except "close" + "close")
1st Jun 2020, 2:55 PM
Yahel
Yahel - avatar
0
Rithea Sreng I'm not experienced enough to understand that code, I will try to take it apart and learn everything... thanks. But if you know how to solve the problem that I got in my way, it would be helpful.
1st Jun 2020, 6:22 PM
Yahel
Yahel - avatar