Last active
August 2, 2026 06:29
-
-
Save fpopic/dd1abe193cecf82ffb96 to your computer and use it in GitHub Desktop.
loto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package hr.fer.ruazosa.hw3; | |
| import android.app.Activity; | |
| import android.os.Bundle; | |
| import android.text.Editable; | |
| import android.text.TextWatcher; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.EditText; | |
| import android.widget.TextView; | |
| public class LottoTicketCreatorActivity extends Activity { | |
| private EditText inputMinor; | |
| private EditText inputMajor; | |
| private String errMsg; | |
| private TextView result; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_lotto_ticket_creator); | |
| errMsg = getResources().getString(R.string.calculator_input_error); | |
| result = (TextView) findViewById(R.id.creator_result); | |
| inputMinor = (EditText) findViewById(R.id.calculator_minor); | |
| inputMinor.addTextChangedListener(new TextWatcher() { | |
| @Override | |
| public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
| String minor = inputMinor.getText().toString(); | |
| if (minor.equals("") || minor.equals("0") || minor.contains(".")) { | |
| inputMinor.setError(errMsg); | |
| } | |
| } | |
| @Override | |
| public void onTextChanged(CharSequence s, int start, int before, int count) { | |
| String minor = inputMinor.getText().toString(); | |
| if (minor.equals("") || minor.equals("0") || minor.contains(".")) { | |
| inputMinor.setError(errMsg); | |
| } | |
| } | |
| @Override | |
| public void afterTextChanged(Editable s) { | |
| String minor = inputMinor.getText().toString(); | |
| if (minor.equals("") || minor.equals("0") || minor.contains(".")) { | |
| inputMinor.setError(errMsg); | |
| } | |
| } | |
| }); | |
| inputMajor = (EditText) findViewById(R.id.calculator_major); | |
| inputMajor.addTextChangedListener(new TextWatcher() { | |
| @Override | |
| public void beforeTextChanged(CharSequence s, int start, int count, int after) { | |
| String major = inputMajor.getText().toString(); | |
| if (major.equals("") || major.equals("0") || major.contains(".")) { | |
| inputMajor.setError(errMsg); | |
| } | |
| } | |
| @Override | |
| public void onTextChanged(CharSequence s, int start, int before, int count) { | |
| String major = inputMajor.getText().toString(); | |
| if (major.equals("") || major.equals("0") || major.contains(".")) { | |
| inputMajor.setError(errMsg); | |
| } | |
| } | |
| @Override | |
| public void afterTextChanged(Editable s) { | |
| String major = inputMajor.getText().toString(); | |
| if (major.equals("") || major.equals("0") || major.contains(".")) { | |
| inputMajor.setError(errMsg); | |
| } | |
| } | |
| }); | |
| inputMajor.setError(errMsg); | |
| inputMinor.setError(errMsg); | |
| Button submit = (Button) findViewById(R.id.creator_generate); | |
| submit.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| String major = inputMajor.getText().toString(); | |
| String minor = inputMinor.getText().toString(); | |
| if (major.equals("") || major.equals("0") || major.contains(".")) { | |
| inputMajor.setError(errMsg); | |
| result.setText(R.string.calculator_result_error); | |
| } | |
| if (minor.equals("") || minor.equals("0") || minor.contains(".")) { | |
| inputMinor.setError(errMsg); | |
| result.setText(R.string.calculator_result_error); | |
| } | |
| if (minor.equals("6") && major.equals("45")) { | |
| result.setText("1, 2, 3, 4, 5, 6"); | |
| } | |
| else if (minor.equals("7") && major.equals("39")) { | |
| result.setText("6, 5, 4, 3, 2, 1"); | |
| } | |
| else if (Integer.parseInt(minor) >= Integer.parseInt(major)) { | |
| result.setError(getResources().getString(R.string.calculator_result_error_minor_gt_major)); | |
| try { | |
| if (Integer.parseInt(minor) < 0 || Integer.parseInt(major) < 0) { | |
| result.setText(R.string.calculator_result_error); | |
| } | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment