Skip to content

Commit

Permalink
Editing Buttons
Browse files Browse the repository at this point in the history
Tracking buttons more effectively, per project grader requirement. Edited checkboxes as well.
  • Loading branch information
elyshas committed May 23, 2018
1 parent c3ab108 commit 6a0b927
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@

public class MainActivity extends AppCompatActivity {

//***Calculates final score***
//***Calculate final score***
int totalScore;

//***+1 for correct answers***
private static final int CorrectAnswer = 1;
private static final int correctAnswer = 1;

//***RadioButton Groups***
private boolean question1AlreadyAnsweredCorrectly = false;
private boolean question3AlreadyAnsweredCorrectly = false;
private boolean question5AlreadyAnsweredCorrectly = false;
private boolean question7AlreadyAnsweredCorrectly = false;

//***Saving score for rotation***
static final String GAME_SCORE = "gameScore";
Expand All @@ -35,7 +41,6 @@ protected void onCreate(Bundle savedInstanceState) {

}

// Calling on the label and adding the int value for user answers (which was created at the top).

//*** Saving instance for when rotating between portrait and landscape***
@Override
Expand All @@ -52,42 +57,53 @@ public void onRadioButton1Clicked(View view) {
// Check which boxes are checked and add points when appropriate
switch (view.getId()) {
case R.id.q1a1:
if (button1Checked)
// Puffer fish and gnomes
totalScore += CorrectAnswer;
if (button1Checked && !question1AlreadyAnsweredCorrectly) {
// CORRECT - Puffer fish and gnomes
totalScore += correctAnswer;
question1AlreadyAnsweredCorrectly = true;
}
break;
case R.id.q1a2:
if (button1Checked)
if (button1Checked && question1AlreadyAnsweredCorrectly) {
// Squirrels and gnomes
break;
if (totalScore > 0) {
totalScore -= correctAnswer;
}
question1AlreadyAnsweredCorrectly = false;
}
break;
}
}

//*** Question 2 - GIR favorite food - checkboxes***
public void onCheckboxes1Checked(View view) {
// Is the Q2 checkboxes checked?
boolean checkboxes1Checked = ((CheckBox) view).isChecked();
// Check which boxes are checked and add points when appropriate
// Check which button is checked and add/subtract points when appropriate
switch (view.getId()) {
case R.id.q2a1:
if (checkboxes1Checked)
if (checkboxes1Checked) {
// pizza
totalScore += CorrectAnswer;
totalScore += correctAnswer;
}
break;
case R.id.q2a2:
if (checkboxes1Checked)
if (checkboxes1Checked) {
// waffles
totalScore += CorrectAnswer;
totalScore += correctAnswer;
}
break;
case R.id.q2a3:
if (checkboxes1Checked)
// peanuts
totalScore -= CorrectAnswer;
if (checkboxes1Checked) {
// INCORRECT - peanuts
totalScore -= correctAnswer;
}
break;
case R.id.q2a4:
if (checkboxes1Checked)
if (checkboxes1Checked) {
// tacos
totalScore += CorrectAnswer;
totalScore += correctAnswer;
}
break;
}
}
Expand All @@ -96,21 +112,32 @@ public void onCheckboxes1Checked(View view) {
public void onRadioButton2Clicked(View view) {
// Is the Q3 button now checked?
boolean button2Checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
// Check which button is checked and add/subtract points when appropriate
switch (view.getId()) {
case R.id.q3a1:
if (button2Checked)
if (button2Checked && question3AlreadyAnsweredCorrectly)
// Larry
if (totalScore > 0) {
totalScore -= correctAnswer;
}
question3AlreadyAnsweredCorrectly = false;
break;
case R.id.q3a2:
if (button2Checked)
// Keef
totalScore += CorrectAnswer;
if (button2Checked && !question3AlreadyAnsweredCorrectly) {
// CORRECT - Keef
totalScore += correctAnswer;
question3AlreadyAnsweredCorrectly = true;
}
break;
case R.id.q3a3:
if (button2Checked)
if (button2Checked && question3AlreadyAnsweredCorrectly) {
// Garry
break;
if (totalScore > 0) {
totalScore -= correctAnswer;
}
question3AlreadyAnsweredCorrectly = false;
}
break;
}
}

Expand All @@ -121,19 +148,22 @@ public void onCheckboxes2Checked(View view) {
// Check which boxes are checked and add points when appropriate
switch (view.getId()) {
case R.id.q4a1:
if (checkboxes2Checked)
if (checkboxes2Checked) {
// Video Games
totalScore += CorrectAnswer;
totalScore += correctAnswer;
}
break;
case R.id.q4a2:
if (checkboxes2Checked)
// Building robots
totalScore -= CorrectAnswer;
break;
if (checkboxes2Checked) {
// INCORRECT - Building robots
totalScore -= correctAnswer;
}
break;
case R.id.q4a3:
if (checkboxes2Checked)
if (checkboxes2Checked) {
// Insulting Dib
totalScore += CorrectAnswer;
totalScore += correctAnswer;
}
break;
}
}
Expand All @@ -142,21 +172,33 @@ public void onCheckboxes2Checked(View view) {
public void onRadioButton3Clicked(View view) {
// Is the Q1 button now checked?
boolean button3Checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
// Check which button is checked and add/subtract points when appropriate
switch (view.getId()) {
case R.id.q5a1:
if (button3Checked)
if (button3Checked && question5AlreadyAnsweredCorrectly) {
// Walton Chunky
break;
if (totalScore > 0) {
totalScore -= correctAnswer;
}
question3AlreadyAnsweredCorrectly = false;
}
break;
case R.id.q5a2:
if (button3Checked)
// Pustulio
totalScore += CorrectAnswer;
if (button3Checked && !question5AlreadyAnsweredCorrectly) {
// CORRECT - Pustulio
totalScore += correctAnswer;
question5AlreadyAnsweredCorrectly = true;
}
break;
case R.id.q5a3:
if (button3Checked)
// Zitboy
break;
if (button3Checked && question5AlreadyAnsweredCorrectly) {
// Walton Chunky
if (totalScore > 0) {
totalScore -= correctAnswer;
}
question3AlreadyAnsweredCorrectly = false;
}
break;
}
}

Expand All @@ -167,19 +209,22 @@ public void onCheckboxes3Checked(View view) {
// Check which boxes are checked and add points when appropriate
switch (view.getId()) {
case R.id.q6a1:
if (checkboxes3Checked)
// Squirrel Antics
totalScore -= CorrectAnswer;
break;
if (checkboxes3Checked) {
// INCORRECT - Squirrel Antics
totalScore -= correctAnswer;
}
break;
case R.id.q6a2:
if (checkboxes3Checked)
if (checkboxes3Checked) {
// The Doom Song
totalScore += CorrectAnswer;
totalScore += correctAnswer;
}
break;
case R.id.q6a3:
if (checkboxes3Checked)
if (checkboxes3Checked) {
// Merry Jingly
totalScore += CorrectAnswer;
totalScore += correctAnswer;
}
break;
}
}
Expand All @@ -188,26 +233,38 @@ public void onCheckboxes3Checked(View view) {
public void onRadioButton4Clicked(View view) {
// Is the Q7 button now checked?
boolean button4Checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
// Check which button is checked and add/subtract points when appropriate
switch (view.getId()) {
case R.id.q7a1:
if (button4Checked)
// Burger Slave
break;
if (button4Checked && question7AlreadyAnsweredCorrectly) {
// Walton Chunky
if (totalScore > 0) {
totalScore -= correctAnswer;
}
question7AlreadyAnsweredCorrectly = false;
}
break;
case R.id.q7a2:
if (button4Checked)
// McBunsALot
break;
if (button4Checked && question7AlreadyAnsweredCorrectly) {
// Walton Chunky
if (totalScore > 0) {
totalScore -= correctAnswer;
}
question7AlreadyAnsweredCorrectly = false;
}
break;
case R.id.q7a3:
if (button4Checked)
// McMeaties
totalScore += CorrectAnswer;
if (button4Checked && !question7AlreadyAnsweredCorrectly) {
// CORRECT - Pustulio
totalScore += correctAnswer;
question7AlreadyAnsweredCorrectly = true;
}
break;
}
}

// //*** Question 8 - Irken Rulers - EditText question***
// public void answer8Completed (View view) {

// // Is the Q8 answered?
//
// // Check answer
Expand Down Expand Up @@ -282,6 +339,8 @@ public void displayScore(View view) {
checkBox9.setChecked(false);
CheckBox checkBox10 = (CheckBox) findViewById(R.id.q6a3);
checkBox10.setChecked(false);
//Reset QUESTION 8 EditText
// answer8.setText("");

//Resetting EditText
userName.setText("");
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

<!--FIRST QUESTION'S ANSWER OPTIONS-->
<RadioGroup
android:id="@+id/radioGroupQuestion1"
style="@style/RadioGroup"
android:layout_marginLeft="@dimen/Q1_Margins_Land"
android:layout_marginRight="@dimen/Q1_Margins_Land">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
tools:context="com.example.android.invaderzimfandetector.MainActivity">

<LinearLayout
android:id="@+id/TopApp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--App Name and Intro Text-->
<string name="app_name">Invader Zim Fan Detector</string>
<string name="Intro">Take my quiz or feel my wrath!</string>
<string name="EditTextHint">Your First Name</string>
<string name="EditTextHint">Dirty Human Name</string>

<!--Question 1-->
<string name="Question1">1. What items guard Zim\'s front yard?</string>
Expand Down

0 comments on commit 6a0b927

Please sign in to comment.