I am just a side programmer, working on little tiny projects for some extra coin. Nothing to big.
But I got this code with an if and else if statement that I am trying to run on the GUI on Android Studio, I want the code to display within the actual android app. I don't know where to put the code in or how to call it in the .java file, so that it can run in the android app on the Studio program. I was hoping maybe someone with more experience with Android Studio can help me figure out what my next steps are. I do apologize if I am vague with my problem, I am not quite great at explaining the issue.
public class Main {
public static void main(String[] args) {
String lit;
Scanner scan = new Scanner(System.in);
System.out.println("Set the thermostat to call for heating, does the pilot stay lit? y/n");
lit = scan.nextLine();
if (lit.equals("y")) {
System.out.println("Great. So it works.");
} else if (lit.equals("n")) {
System.out.println("Check the thermocouple.");
}
}
}


Android apps work in a different way to 'normal' java programs, the concept of System.in doesn't really exist. The main function isn't something that you call manually. User input comes from having widgets on the screen like an EditText to read the data.
I'd start here to get a grasp on a basic app and then you should be able to see how you could modify your sample above to an app.
I see you need to make an actual GUI app with this.
I would suggest you to see some tutorials on android studio first.
To build this app, first put in 2 Textview, and 2 buttons in the activity_main.
In the properties panel on the left, change the text of these objects so that your question is in one textView, the other is blank and the buttons are labelled Yes or No (or y and n, your choice).
Change the id of the 2 buttons so that one's id is yes and the other's is no. Set the id of the blank textView as result.
Now, in the main activity, put this in BEFORE @Override:
Button yes = (Button) findViewById(R.id.yes);
Button no = (Button) findViewById(R.id.no);
TextView result = (TextView) findViewById(R.id.result);
And put this AFTER setContentView (on the next line):
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
result.setText("Whatever your message is for yes");
}
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
result.setText("Whatever your message is for no");
}
I hope this is what you wanted. Once again, I would advise you to watch some tutorials.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With