Created
January 21, 2018 20:48
-
-
Save letozaf/352aabd78c9d1f8ed263bf1469866561 to your computer and use it in GitHub Desktop.
NetworkQuizApp
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="@drawable/networking"> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_marginLeft="16dp" | |
android:orientation="vertical" | |
tools:context="com.example.android.networkingquiz.MainActivity"> | |
<EditText | |
android:id="@+id/name" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/name" | |
android:inputType="textCapWords" | |
android:paddingTop="16dp" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:paddingTop="16dp" | |
android:text="@string/question_1" | |
android:textAllCaps="false" | |
android:textSize="20sp" | |
android:textStyle="bold" /> | |
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:paddingBottom="16dp"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:text="@string/question_1_content" /> | |
<RadioButton | |
android:id="@+id/radio_32" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/one" /> | |
<RadioButton | |
android:id="@+id/radio_128B" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/two" /> | |
<RadioButton | |
android:id="@+id/radio_64" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/three" /> | |
<RadioButton | |
android:id="@+id/radio_128b" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/four" /> | |
</RadioGroup> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:paddingTop="16dp" | |
android:text="@string/question_2" | |
android:textAllCaps="false" | |
android:textSize="20sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:text="@string/question_2_content" /> | |
<CheckBox | |
android:id="@+id/checkbox_Q2_hwComp" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/hwComp" /> | |
<CheckBox | |
android:id="@+id/checkbox_Q2_intercomm" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/interconn" /> | |
<CheckBox | |
android:id="@+id/checkbox_Q2_share" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/share" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:paddingTop="32dp" | |
android:text="@string/question_3" | |
android:textAllCaps="false" | |
android:textSize="20sp" | |
android:textStyle="bold" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:text="@string/question_3_content" /> | |
<EditText | |
android:id="@+id/answer_Q3" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:hint="@string/answerQ3" | |
android:inputType="textCapCharacters" | |
android:paddingBottom="16dp" | |
android:paddingTop="16dp" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:paddingTop="16dp" | |
android:text="@string/question_4" | |
android:textAllCaps="false" | |
android:textSize="20sp" | |
android:textStyle="bold" /> | |
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:paddingBottom="16dp"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:paddingBottom="16dp" | |
android:text="@string/question_4_content" /> | |
<RadioButton | |
android:id="@+id/radio_TCP" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/Q4_one" /> | |
<RadioButton | |
android:id="@+id/radio_ARP" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/Q4_two" /> | |
<RadioButton | |
android:id="@+id/radio_ICMP" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/Q4_three" /> | |
<RadioButton | |
android:id="@+id/radio_BootP" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/Q4_four" /> | |
</RadioGroup> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="16dp" | |
android:onClick="submitQuiz" | |
android:text="@string/submit" | |
android:textAllCaps="false" /> | |
</LinearLayout> | |
</ScrollView> |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<color name="colorPrimary">#1565c0</color> | |
<color name="colorPrimaryDark">#003c8f</color> | |
<color name="colorAccent">#5e92f3</color> | |
</resources> |
This file contains 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 com.example.android.networkingquiz; | |
import android.content.Context; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.text.Editable; | |
import android.view.View; | |
import android.widget.CheckBox; | |
import android.widget.EditText; | |
import android.widget.RadioButton; | |
import android.widget.Toast; | |
import org.w3c.dom.Text; | |
import java.util.Objects; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
/** | |
* This method is called when the submitQuiz button is clicked. | |
*/ | |
public void submitQuiz(View view) { | |
int total_Right_Questions = 0; | |
EditText nameText = findViewById(R.id.name); | |
Editable nameField = nameText.getText(); | |
/** | |
* This part is for handling the first question radio button | |
*/ | |
RadioButton radio_32 = (RadioButton) findViewById(R.id.radio_32); | |
boolean radio_32_checked = radio_32.isChecked(); | |
RadioButton radio_128B = (RadioButton) findViewById(R.id.radio_128B); | |
boolean radio_128B_checked = radio_128B.isChecked(); | |
RadioButton radio_64 = (RadioButton) findViewById(R.id.radio_64); | |
boolean radio_64_checked = radio_64.isChecked(); | |
RadioButton radio_128b = (RadioButton) findViewById(R.id.radio_128b); | |
boolean radio_128b_checked = radio_128b.isChecked(); | |
if (radio_32_checked == false) { | |
if (radio_128B_checked == false) { | |
if (radio_64_checked == false) { | |
if (radio_128b_checked == true) { | |
total_Right_Questions += 1; | |
} | |
} | |
} | |
} | |
/** | |
* This part is for handling the second question check boxes | |
*/ | |
CheckBox checkbox_Q2_hwComp = (CheckBox) findViewById(R.id.checkbox_Q2_hwComp); | |
boolean checkbox_Q2_hwComp_checked = checkbox_Q2_hwComp.isChecked(); | |
CheckBox checkbox_Q2_intercomm = (CheckBox) findViewById(R.id.checkbox_Q2_intercomm); | |
boolean checkbox_Q2_intercomm_checked = checkbox_Q2_intercomm.isChecked(); | |
CheckBox checkbox_Q2_share = (CheckBox) findViewById(R.id.checkbox_Q2_share); | |
boolean checkbox_Q2_share_checked = checkbox_Q2_share.isChecked(); | |
if (checkbox_Q2_hwComp_checked == true) { | |
if (checkbox_Q2_intercomm_checked == true) { | |
if (checkbox_Q2_share_checked == true) { | |
total_Right_Questions += 1; | |
} | |
} | |
} | |
/** | |
* This part is for handling the third question edit text field | |
*/ | |
EditText Q3Text = (EditText) findViewById(R.id.answer_Q3); | |
String Q3FieldString = Q3Text.getText().toString(); | |
String rightAnswer = "UDP"; | |
if (Objects.equals(Q3FieldString, rightAnswer)) { | |
total_Right_Questions += 1; | |
} | |
/** | |
* This part is for handling the fourth question edit text field | |
*/ | |
RadioButton Q4_TCP = (RadioButton) findViewById(R.id.radio_TCP); | |
boolean Q4_TCP_checked = Q4_TCP.isChecked(); | |
RadioButton Q4_ARP = (RadioButton) findViewById(R.id.radio_ARP); | |
boolean Q4_ARP_checked = Q4_ARP.isChecked(); | |
RadioButton Q4_ICMP = (RadioButton) findViewById(R.id.radio_ICMP); | |
boolean Q4_ICMP_checked = Q4_ICMP.isChecked(); | |
RadioButton Q4_BootP = (RadioButton) findViewById(R.id.radio_BootP); | |
boolean Q4_BootP_checked = Q4_BootP.isChecked(); | |
if (Q4_TCP_checked == false) { | |
if (Q4_ARP_checked == false) { | |
if (Q4_ICMP_checked == true) { | |
if (Q4_BootP_checked == false) { | |
total_Right_Questions += 1; | |
} | |
} | |
} | |
} | |
/** | |
* This part for summerazing the result of the quiz | |
*/ | |
Context context = getApplicationContext(); | |
int duration = Toast.LENGTH_LONG; | |
CharSequence text = nameField + " You answered " + total_Right_Questions + "/4 questions right"; | |
Toast toast = Toast.makeText(context, text, duration); | |
toast.show(); | |
} | |
} |
This file contains 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
<resources> | |
<string name="app_name">Networking Quiz</string> | |
<!-- Name of person taking quiz [CHAR LIMIT=20]--> | |
<string name="name">Enter your name here:</string> | |
<!-- Question n. 1 label [CHAR LIMIT=20]--> | |
<string name="question_1">Question n. 1:</string> | |
<!-- Question n. 1 content [CHAR LIMIT=100]--> | |
<string name="question_1_content">How long is an IPv6 address?</string> | |
<!-- Question n. 1 first radio button [CHAR LIMIT=100]--> | |
<string name="one">32 bits</string> | |
<!-- Question n. 1 second radio button [CHAR LIMIT=100]--> | |
<string name="two">128 bytes</string> | |
<!-- Question n. 1 third radio button [CHAR LIMIT=100]--> | |
<string name="three">64 bits</string> | |
<!-- Question n. 1 fourth radio button [CHAR LIMIT=100]--> | |
<string name="four">128 bits</string> | |
<!-- Submit button text [CHAR LIMIT=20]--> | |
<string name="submit">Submit</string> | |
<!-- Question n. 2 label [CHAR LIMIT=20]--> | |
<string name="question_2">Question n. 2:</string> | |
<!-- Question n. 2 content [CHAR LIMIT=100]--> | |
<string name="question_2_content">Computer Network is ...</string> | |
<!-- Question n. 2 first check box [CHAR LIMIT=100]--> | |
<string name="hwComp">Collection of hardware components and computers</string> | |
<!-- Question n. 2 second check box [CHAR LIMIT=100]--> | |
<string name="interconn">Interconnected by communication channels</string> | |
<!-- Question n. 2 third check box [CHAR LIMIT=100]--> | |
<string name="share">Sharing of resources and information</string> | |
<!-- Question n. 3 label [CHAR LIMIT=20]--> | |
<string name="question_3">Question n. 3:</string> | |
<!-- Question n. 3 content [CHAR LIMIT=100]--> | |
<string name="question_3_content">Which protocol does DHCP use at the Transport layer ?</string> | |
<!-- Question n. 3 hint to edit text field [CHAR LIMIT=100]--> | |
<string name="answerQ3">type the answer here.</string> | |
<!-- Question n. 4 label [CHAR LIMIT=20]--> | |
<string name="question_4">Question n. 4:</string> | |
<!-- Question n. 4 content [CHAR LIMIT=100]--> | |
<string name="question_4_content">Which protocol is used to send a destination network unknown message back to originating hosts ?</string> | |
<!-- Question n. 4 first radio button [CHAR LIMIT=100]--> | |
<string name="Q4_one">TCP</string> | |
<!-- Question n. 4 second radio button [CHAR LIMIT=100]--> | |
<string name="Q4_two">ARP</string> | |
<!-- Question n. 4 third radio button [CHAR LIMIT=100]--> | |
<string name="Q4_three">ICMP</string> | |
<!-- Question n. 4 fourth radio button [CHAR LIMIT=100]--> | |
<string name="Q4_four">BootP</string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment