QUESTION 1
1.1 – Extract from Assignment QuestionProduce an interface as shown below. Choose an appropriate image as the main image on the interface. Make some space between the image and the toolbar. The sentence, "Welcome to Zoo Taiping" has the following attributes:
• font size: 20dp
• font color: #4286f4
• font style: bold
The animal's list should be made using a ListView element. When the name of the animal is clicked, a toast that displays the name of the animal will be displayed for a few seconds.
Main UI XML (activity_main.xml)<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="109dp"
android:layout_y="70dp"
android:src="@drawable/zootaipinglogo"
tools:layout_editor_absoluteX="86dp"
tools:layout_editor_absoluteY="69dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="7dp"
android:layout_y="204dp"
android:text="Welcome to Zoo Taiping"
android:textAlignment="center"
android:textColor="#4286f4"
android:textSize="20dp"
android:textStyle="bold"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="228dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="7dp"
android:layout_y="230dp"
android:text="Choose your favourite animal:"
android:textAlignment="center"
android:textColor="#b2b2b2"
android:textSize="18dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="255dp" />
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="449dp"
android:layout_x="1dp"
android:layout_y="262dp"
tools:layout_editor_absoluteX="-16dp"
tools:layout_editor_absoluteY="305dp" />
</AbsoluteLayout>
1.3 – Main JAVA class(es)
JAVA File (mainActivity.java) |
package com.example.cbod4103_question1; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { ListView listView; TextView textView; String[] listItem; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView=(ListView)findViewById(R.id.listView); //textView=(TextView)findViewById(R.id.textView); listItem = getResources().getStringArray(R.array.animallist); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, listItem); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // TODO Auto-generated method stub String value=adapter.getItem(position); Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show(); }}); }} |
1.4 – Additional Included File(s)
String for ListView XML (AnimalList.xml) |
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">ListView</string> <string-array name="animallist"> <item>Giraffe</item> <item>Elephant</item> <item>Tiger</item> </string-array> </resources> |
1.5 – Testing the Application
Build and run the application as per screenshots below.
1.6 – Additional Requirement from Assignment
a. Create a snapshot video by showing the programming created in the Android Studio
b. he video also must show the all the screen, components, and list view.
c. Your answer must also state the links to get the video.
QUESTION 2
2.1 – Extract from Assignment Question
The score for the English Placement Test (EPT) is calculated based on the marks obtained from the speaking, listening, and writing tests. The maximum mark for all the tests is 100%. However, to calculate the grade for the EPT, each test has been given a certain percentage as shown in Table 1. After that, the final marks will be calculated, and the final grade is given as shown in Table 2.
Write an Android app that requests a name and marks for each of the student as shown in Figure 1. When the details have been entered, the app will calculate the final marks and grade and show them on the next screen as shown in Figure 2. Create a snapshot video for running the results of the each of the animations. Your answer must also state the links to get the video.
2.2 – Main & Result UI Element
Main Page (activity_main.xml) |
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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" tools:context=".MainActivity"> <ImageView android:id="@+id/image_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/testres01" android:layout_alignParentTop="true" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/image_view" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Name" android:textAlignment="center" android:textColor="#a5a5a5" android:textSize="24dp" android:textStyle="bold" /> <EditText android:id="@+id/name_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center" android:textColor="#a5a5a5" android:hint="Enter name here" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Writing" android:textAlignment="center" android:textColor="#a5a5a5" android:textSize="24dp" android:textStyle="bold" /> <EditText android:id="@+id/writing_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center" android:textColor="#a5a5a5" android:inputType="number" android:hint="Enter Writing marks" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Speaking" android:textAlignment="center" android:textColor="#a5a5a5" android:textSize="24dp" android:textStyle="bold" /> <EditText android:id="@+id/speaking_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center" android:textColor="#a5a5a5" android:inputType="number" android:hint="Enter Speaking marks" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Listening" android:textAlignment="center" android:textColor="#a5a5a5" android:textSize="24dp" android:textStyle="bold" /> <EditText android:id="@+id/listening_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="center" android:textColor="#a5a5a5" android:inputType="number" android:hint="Enter Listening marks" /> <Button android:id="@+id/calculate_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:backgroundTint="#c9caca" android:textColor="@color/black" android:text="Calculate" /> </LinearLayout> </RelativeLayout> |
Result Page (activity_result.xml) |
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="left"> <ImageView android:id="@+id/image_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/testres02" android:layout_alignParentTop="true" /> <TextView android:id="@+id/name_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textStyle="bold" android:textColor="#a5a5a5" android:layout_marginTop="16dp" android:layout_marginLeft="20pt" /> <TextView android:id="@+id/writing_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textStyle="bold" android:textColor="#a5a5a5" android:layout_marginTop="16dp" android:layout_marginLeft="20pt" /> <TextView android:id="@+id/speaking_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textStyle="bold" android:textColor="#a5a5a5" android:layout_marginTop="16dp" android:layout_marginLeft="20pt" /> <TextView android:id="@+id/listening_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textStyle="bold" android:textColor="#a5a5a5" android:layout_marginTop="16dp" android:layout_marginLeft="20pt" /> <View android:layout_width="match_parent" android:layout_height="2dp" android:layout_marginTop="16dp" android:background="@android:color/darker_gray"/> <TextView android:id="@+id/total_marks_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:layout_marginTop="16dp" android:textColor="#4153b6" android:textStyle="bold" android:layout_marginLeft="20pt" /> <TextView android:id="@+id/grade_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="28sp" android:layout_marginTop="16dp" android:textStyle="bold" android:layout_marginLeft="20pt" /> <Button android:id="@+id/back_button" android:layout_marginTop="16dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:backgroundTint="#c9caca" android:textColor="@color/black" android:text="Back" /> </LinearLayout> |
2.3 – Main & Result JAVA class(es)
Main Activity (MainActivity.java) |
package com.example.cbod4103_question2; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import com.example.cbod4103_question2.R; import com.example.cbod4103_question2.ResultsActivity; public class MainActivity extends AppCompatActivity { private EditText mNameEditText, mWritingEditText, mSpeakingEditText, mListeningEditText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mNameEditText = findViewById(R.id.name_edit_text); mWritingEditText = findViewById(R.id.writing_edit_text); mSpeakingEditText = findViewById(R.id.speaking_edit_text); mListeningEditText = findViewById(R.id.listening_edit_text); Button mCalculateButton = findViewById(R.id.calculate_button); mCalculateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String name = mNameEditText.getText().toString(); String tempWrite = mWritingEditText.getText().toString(); String tempSpeaking = mSpeakingEditText.getText().toString(); String tempListenening = mListeningEditText.getText().toString(); double writingMarks = Double.parseDouble(mWritingEditText.getText().toString()); double speakingMarks = Double.parseDouble(mSpeakingEditText.getText().toString()); double listeningMarks = Double.parseDouble(mListeningEditText.getText().toString()); if (name.isEmpty() || tempWrite.isEmpty() || tempSpeaking.isEmpty() || tempListenening.isEmpty()) { Toast.makeText(MainActivity.this, "Please fill in all fields", Toast.LENGTH_SHORT).show(); } else { // Check if any marks entered are greater than 100 if (writingMarks > 100 || speakingMarks > 100 || listeningMarks > 100) { Toast.makeText(MainActivity.this, "Marks cannot be greater than 100", Toast.LENGTH_SHORT).show(); return; } } double totalMarks = calculateTotalMarks(writingMarks, speakingMarks, listeningMarks); String grade = calculateGrade(totalMarks); Intent intent = new Intent(MainActivity.this, ResultsActivity.class); intent.putExtra("name", name); intent.putExtra("tempWrite", tempWrite); intent.putExtra("tempSpeaking", tempSpeaking); intent.putExtra("tempListenening", tempListenening); intent.putExtra("total_marks", totalMarks); intent.putExtra("grade", grade); startActivity(intent); } }); } private double calculateTotalMarks(double writingMarks, double speakingMarks, double listeningMarks) { // Maximum score for all tests is 100% // Therefore apply weightage of 0.5, 0.3 and 0.2 forr the exam categories double total = (writingMarks * 0.5) + (speakingMarks * 0.3) + (listeningMarks * 0.2); return total; } private String calculateGrade(double totalMarks) { if (totalMarks >= 80) { return "A"; } else if (totalMarks >= 60 && totalMarks <= 79) { return "B"; } else if (totalMarks >= 40 && totalMarks <= 59) { return "C"; } else { return "F"; } } } |
Result Activity (ResultActivity.java) |
package com.example.cbod4103_question2; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class ResultsActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_results); Button backButton = findViewById(R.id.back_button); backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); // close the current activity and go back to the previous one } }); Intent intent = getIntent(); String name = intent.getStringExtra("name"); String tempWrite = intent.getStringExtra("tempWrite"); String tempSpeaking = intent.getStringExtra("tempSpeaking"); String tempListenening = intent.getStringExtra("tempListenening"); double totalMarks = intent.getDoubleExtra("total_marks", 0); String grade = intent.getStringExtra("grade"); TextView nameTextView = findViewById(R.id.name_text_view); nameTextView.setText("Name: " + name); TextView writingTextView = findViewById(R.id.writing_text_view); writingTextView.setText("Writing: " + tempWrite); TextView speakingTextView = findViewById(R.id.speaking_text_view); speakingTextView.setText("Speaking: " + tempSpeaking); TextView listeningTextView = findViewById(R.id.listening_text_view); listeningTextView.setText("Listening: " + tempListenening); TextView totalMarksTextView = findViewById(R.id.total_marks_text_view); totalMarksTextView.setText("Final Marks: " + totalMarks); TextView gradeTextView = findViewById(R.id.grade_text_view); gradeTextView.setText("Grade: " + grade); if (grade.equals ("A")) { gradeTextView.setTextColor(Color.parseColor("#0d7802")); } else if (grade.equals ("B")) { gradeTextView.setTextColor(Color.parseColor("#ff9601")); } else if (grade.equals ("C")) { gradeTextView.setTextColor(Color.parseColor("#ff4301")); } else { gradeTextView.setTextColor(Color.parseColor("#ff0000")); }} } |
2.4 – Additional Included File(s)
String XML (strings.xml) |
<resources> <string name="app_name">English Placement Test</string> </resources> |
2.5 – Testing the Application
Build and run the application as per screenshots below.
2.6 – Additional Requirement from Assignment
a. Create a snapshot video by showing the programming created in the Android Studio
b. The video also must show the all the screen, components, and list view.
c. Your answer must also state the links to get the video.
List of References:
1. Budi Kurniawan. (2015). Android Application Development. First Edition. Open Brainy Sofftware Corp.
2. W3Schools (Ed.). (n.d.). Java Tutorial. Java tutorial. Retrieved March 10, 2023, from https://www.w3schools.com/java/