0% found this document useful (0 votes)
55 views5 pages

Assignment-02

This document contains code for an Android application assignment submitted by a student named Jannatim Maisha to their instructors Mr. Md. Aminur Rahman and Mr. Md. Siam Ansary at Ahsanullah University of Science and Technology. The application contains XML layout code to display multiple choice questions with checkboxes and buttons to submit answers. It also includes string resources and Java code to handle checking answers and displaying the response.

Uploaded by

JANNATIM MAISHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views5 pages

Assignment-02

This document contains code for an Android application assignment submitted by a student named Jannatim Maisha to their instructors Mr. Md. Aminur Rahman and Mr. Md. Siam Ansary at Ahsanullah University of Science and Technology. The application contains XML layout code to display multiple choice questions with checkboxes and buttons to submit answers. It also includes string resources and Java code to handle checking answers and displaying the response.

Uploaded by

JANNATIM MAISHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Ahsanullah University of Science and Technology

Department of Computer Science and Engineering


Spring 2021

Program : Bachelor of Science in Computer Science and Engineering


Course No : CSE 2200
Course Title: Software Development III
Assignment No:02
Date of Submission:24.1.22
Submitted to:
Mr. Md. Aminur Rahman

Assistant Professor, Department of CSE, AUST.


Mr. Md. Siam Ansary
Lecturer, Department of CSE, AUST.
Submitted by
Name:Jannatim Maisha
Student ID:190204055
Solution:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DCBEE1"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/question"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textSize="30sp"
android:textStyle="bold"
android:id="@+id/qstn"

/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linear1"
android:orientation="vertical"
android:layout_below="@id/qstn"
android:layout_margin="10dp"
>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkbox1"
android:layout_marginTop="10dp"
android:text="@string/checkBoxText1"
android:textSize="25sp"
android:textColor="@color/black"
android:buttonTint="#F64782"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkbox2"
android:layout_marginTop="10dp"
android:text="@string/checkBoxText2"
android:textSize="25sp"
android:textColor="@color/black"
android:buttonTint="#F64782"
/>

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkbox3"
android:layout_marginTop="10dp"
android:text="@string/checkBoxText3"
android:textSize="25sp"
android:textColor="@color/black"
android:buttonTint="#F64782"
/>

</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textAlignment="center"
android:textColor="#938484"
android:textSize="35sp"
android:id="@+id/answer"
android:background="#A9DA59"
/>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="@string/buttonText"
android:layout_above="@id/answer"
android:layout_marginBottom="20dp"
android:textSize="30sp"
android:backgroundTint="#DDBF64"
android:textColor="#D33A6E"
android:id="@+id/button"

/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button"
android:layout_marginBottom="20dp"
android:id="@+id/onlyOne"
android:textSize="30sp"
android:textColor="#614C4C"

/>

</RelativeLayout>

strings.xml
<resources>
<string name="app_name">Assignment2</string>
<string name="question">Who is the most honourable person in seven
kingdoms?</string>
<string name="checkBoxText1">Ned Stark</string>
<string name="checkBoxText2">Jon Arryn</string>
<string name="checkBoxText3">Jaehaerys I Targaryen</string>
<string name="buttonText">CLICK</string>
</resources>

MainActivity.kt
package com.example.assignment2

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.CheckBox
import android.widget.TextView

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val chckBox1=findViewById<CheckBox>(R.id.checkbox1)
val chckBox2=findViewById<CheckBox>(R.id.checkbox2)
val chckBox3=findViewById<CheckBox>(R.id.checkbox3)
val txtBox1=findViewById<TextView>(R.id.answer)
val txtBox2=findViewById<TextView>(R.id.onlyOne)
val click=findViewById<Button>(R.id.button)
var count : Int= 0
click.setOnClickListener {

if (chckBox1.isChecked) {

count++

}
if (chckBox2.isChecked) {
//txtBox1.setText("wrong answer")
count++
}
if (chckBox3.isChecked) {
//txtBox1.setText("wrong answer")
count++

} if(count==1&&chckBox1.isChecked){
txtBox2.setText("")
txtBox1.setText("correct answer")
count=0
}
if(count==1&&chckBox2.isChecked)
{
txtBox2.setText("")
txtBox1.setText("wrong answer")
count=0
}
if(count==1&&chckBox3.isChecked)
{
txtBox2.setText("")
txtBox1.setText("wrong answer")
count=0
}

if(count>1){
txtBox2.setText("you can select only one option")
txtBox1.setText("")
count=0
}

if (chckBox1.isChecked && chckBox2.isChecked &&


chckBox3.isChecked)
{
txtBox2.setText("you can select only one option")
txtBox1.setText("")
count=0
}

if(!chckBox1.isChecked&&!chckBox2.isChecked&&!chckBox3.isChecked)
{
txtBox2.setText("you have to select one option")
txtBox1.setText("")
count=0
}

}
}

You might also like