Mainactivity>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package com.example.lab_test;
import static java.security.AccessController.getContext;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button stdbtn1, stdbtn2, stdbtn3, stdbtn4;
String name1="Adnan",name2="Mahmud", name3="Rafsan", name4="Adit", id1="212-15-4155", id2="212-15-7489", id3="212-15-7896",
id4="212-15-9635";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
stdbtn1 = findViewById(R.id.stdbtn1); stdbtn2 = findViewById(R.id.stdbtn2); stdbtn3 = findViewById(R.id.stdbtn3); stdbtn4 =
findViewById(R.id.stdbtn4);
public void viewStudent(View view) {
stdbtn1.setText(name1);
stdbtn2.setText(name2);
stdbtn3.setText(name3);
stdbtn4.setText(name4);
}
public void stdbmi1(View view) {
Intent intent = new Intent(this, intend.class);
intent.putExtra("Name", name1);
intent.putExtra("id", id1);
startActivity(intent);
public void stdbmi2(View view) {
Intent intent = new Intent(this, intend.class);
intent.putExtra("Name", name2);
intent.putExtra("id", id2);
startActivity(intent);
}
public void stdbmi3(View view) {
Intent intent = new Intent(this, intend.class);
intent.putExtra("Name", name3);
intent.putExtra("id", id3);
startActivity(intent);
}
public void stdbmi4(View view) {
Intent intent = new Intent(this, intend.class);
intent.putExtra("Name", name4);
intent.putExtra("id", id4);
startActivity(intent);
}
}
Intend>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public class intend extends AppCompatActivity {
EditText weight, height;
String name, id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intend);
weight= findViewById(R.id.weight);
height= findViewById(R.id.height);
Intent intent =getIntent();
name= intent.getStringExtra("Name");
id= intent.getStringExtra("id");
TextView textView = findViewById(R.id.name);
textView.setText(name);
public void submit(View view) {
double w = Double.parseDouble(weight.getText().toString());
double h = Double.parseDouble(height.getText().toString());
double r = w / (h * h);
String stringValue = String.valueOf(r);
Toast.makeText(getApplicationContext(), "BMI: " + stringValue, Toast.LENGTH_SHORT).show();
}
public void viewStudent(View view) {
Intent intent = new Intent(this, viewStudent.class);
intent.putExtra("Name", name);
intent.putExtra("id", id);
startActivity(intent);
}
}
Viewstudent>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public class viewStudent extends AppCompatActivity {
TextView viewname, viewid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_student);
Intent intent =getIntent();
String name= intent.getStringExtra("Name");
String sid= intent.getStringExtra("id");
viewname=findViewById(R.id.name);
viewid=findViewById(R.id.stdid);
viewname.setText(name);
viewid.setText(sid);
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/questionTextviewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Question Text"
android:textSize="20dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp"
android:layout_marginBottom="30dp"
/>
<RadioGroup
android:id="@+id/myRadioGroupObjId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:orientation="vertical"
>
<RadioButton
android:id="@+id/option1RadioBtnId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="option 1"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/option2RadioBtnId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="option 2"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/option3RadioBtnId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="option 3"
android:textSize="20dp"/>
<RadioButton
android:id="@+id/option4RadioBtnId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="option 4"
android:textSize="20dp"/>
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/backBtnId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="back"
android:textSize="25sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="30sp" />
<Button
android:id="@+id/nextBtnId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="next"
android:textSize="25sp" />
</LinearLayout>
<TextView
android:id="@+id/scoreTextviewId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Score"
android:textSize="20dp"
android:layout_margin="50dp"
android:layout_marginBottom="30dp"
/>
</LinearLayout>
Java code>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package com.example.quiz;
public class MainActivity extends AppCompatActivity {
RadioGroup myRadioGroupObj;
Button nextBtnObj, backBtnObj;
RadioButton option1RadioObj, option2RadioObj, option3RadioObj, option4RadioObj;
TextView questionTextObj, scoreTextviewObj ;
String[] questionArray = {
"Capital of Bangladesh?",
"Capital of India?",
"Currency of BD?",
"Currency of India?"
};
String[][] options = {
{"Rajshahi", "Dhaka", "Chittagong", "Rangpur"},
{"Dillhi", "Mumbai", "Hydarabad", "Pune"},
{"Euro", "USD", "BDT", "Rupee"},
{"USD", "EURO", "BDT", "Rupee"}
};
String[] answers = {"Dhaka", "Delhi", "BDT", "Rupee"};
int score = 0;
int questionIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connection();
loadQuiz();
nextBtnObj.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
nextFunction();
}
});
backBtnObj.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
backFunction();
}
});
}
private void loadQuiz() {
questionTextObj.setText(questionArray[questionIndex]);
option1RadioObj.setText(options[questionIndex][0]);
option2RadioObj.setText(options[questionIndex][1]);
option3RadioObj.setText(options[questionIndex][2]);
option4RadioObj.setText(options[questionIndex][3]);
}
private void connection() {
myRadioGroupObj = findViewById(R.id.myRadioGroupObjId);
nextBtnObj = findViewById(R.id.nextBtnId);
backBtnObj = findViewById(R.id.backBtnId);
questionTextObj = findViewById(R.id.questionTextviewId);
scoreTextviewObj = findViewById(R.id.scoreTextviewId);
option1RadioObj = findViewById(R.id.option1RadioBtnId);
option2RadioObj = findViewById(R.id.option2RadioBtnId);
option3RadioObj = findViewById(R.id.option3RadioBtnId);
option4RadioObj = findViewById(R.id.option4RadioBtnId);
}
private void backFunction() {
myRadioGroupObj.clearCheck();
if (questionIndex > 0) {
questionIndex--;
loadQuiz();
} else {
Toast.makeText(this, "There is no way", Toast.LENGTH_SHORT).show();
}
}
private void nextFunction() {
if(questionIndex==questionArray.length-2){
nextBtnObj.setText("Submit");
}
myRadioGroupObj.clearCheck();
if (questionIndex < questionArray.length - 1) {
questionIndex++;
loadQuiz();
} else {
checkAnswer(); // Check the answer for the last question
Toast.makeText(this, "Quiz completed", Toast.LENGTH_SHORT).show();
nextBtnObj.setEnabled(false);
}
}
private void checkAnswer() {
int selectedRadioButtonId = myRadioGroupObj.getCheckedRadioButtonId();
if (selectedRadioButtonId != -1) {
RadioButton selectedRadioButton = findViewById(selectedRadioButtonId);
String selectedAnswer = selectedRadioButton.getText().toString();
if (selectedAnswer.equals(answers[questionIndex])) {
score++;
}
updateScore();
}
}
private void updateScore() {
scoreTextviewObj.setText("Score: " + score);
}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
last lab work
main activity::::::::::::::::::::
package com.example.labtask;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
Spinner mySppinerObj;
String option;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySppinerObj = findViewById(R.id.sppinerID);
ArrayAdapter<CharSequence> myAdapter = ArrayAdapter.createFromResource
(this, R.array.sppinerValues, android.R.layout.simple_spinner_item);
myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mySppinerObj.setAdapter(myAdapter);
mySppinerObj.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
option = parent.getItemAtPosition(position).toString();
if (option.equals("USD to BDT")) {
replace(new bmiFragment());
} else if (option.equals("BMI"))
{
replace(new convertionFragment());
}
private void replace (Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.framentID, fragment);
fragmentTransaction.commit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
bmi fragment>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package com.example.labtask;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class bmiFragment extends Fragment {
private EditText weightObj, heightObj;
private TextView bmiob;
private Button bmibtn;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_bmi, container, false);
weightObj = view.findViewById(R.id.edit_text_weight);
heightObj = view.findViewById(R.id.edit_text_height);
bmiob = view.findViewById(R.id.text_view_result);
bmibtn = view.findViewById(R.id.button_calculate);
bmibtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String weightStr = weightObj.getText().toString();
String heightStr = heightObj.getText().toString();
if (weightStr.isEmpty() || heightStr.isEmpty()) {
Toast.makeText(getContext(), "Please enter both weight and height.", Toast.LENGTH_SHORT).show();
return;
}
try {
double weight = Double.parseDouble(weightStr);
double heightCm = Double.parseDouble(heightStr);
// Convert height from centimeters to meters
double heightMeters = heightCm / 100.0;
// Calculate BMI
double bmi = weight / (heightMeters * heightMeters);
// Set the result in the TextView
bmiob.setText(String.format("Your Body Mass Index is: %.2f", bmi));
} catch (NumberFormatException e) {
// Handle invalid input
Toast.makeText(getContext(), "Please enter valid numeric values for weight and height.", Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
}
convertion>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..
package com.example.labtask;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class convertionFragment extends Fragment {
EditText usdObj;
Button convertbtn;
TextView resultob;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_convertion, container, false);
usdObj = view.findViewById(R.id.usdid);
resultob = view.findViewById(R.id.text_view_result);
convertbtn = view.findViewById(R.id.button_calculate);
convertbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String usd = usdObj.getText().toString();
if (usd.isEmpty()) {
Toast.makeText(getContext(), "Please enter USD.", Toast.LENGTH_SHORT).show();
return;
}
try {
double usdd = Double.parseDouble(usd);
// Convert height from centimeters to meters
double bdt = usdd * 117.03;
// Set the result in the TextView
resultob.setText(String.format("%.2f BDT", bdt));
} catch (NumberFormatException e) {
// Handle invalid input
Toast.makeText(getContext(), "Please enter valid numeric values for USD.", Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
}
XML:::::::::::::::::::::::::::::::::::::::::::::::::activity main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Calculator"
android:textSize="30dp"
android:layout_marginTop="30dp"
android:textAlignment="center"
/>
<Spinner
android:id="@+id/sppinerID"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="40dp" />
<FrameLayout
android:id="@+id/framentID"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Fragment bmi:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".bmiFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="BMI"
android:textAlignment="center"
android:textSize="50dp"
android:textStyle="bold"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="50dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Waght"
android:textSize="30dp"
/>
<EditText
android:id="@+id/edit_text_weight"
android:layout_width="match_parent"
android:layout_height="60dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="50dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hight"
android:textSize="30dp"
/>
<EditText
android:id="@+id/edit_text_height"
android:layout_width="match_parent"
android:layout_height="60dp"
/>
</LinearLayout>
<Button
android:id="@+id/button_calculate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Calculate"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:id="@+id/text_view_result"
android:text="BMI = "
android:textSize="30dp"
android:textAlignment="center"
/>
</LinearLayout>
</FrameLayout>
Convertion:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".convertionFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="USD to BDT"
android:textAlignment="center"
android:textSize="50dp"
android:textStyle="bold"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="50dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USD"
android:textSize="30dp"
/>
<EditText
android:id="@+id/usdid"
android:layout_width="match_parent"
android:layout_height="60dp"
/>
</LinearLayout>
<Button
android:layout_marginTop="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Convart"
android:id="@+id/button_calculate"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:id="@+id/text_view_result"
android:text="BDT = "
android:textSize="30dp"
android:textAlignment="center"
/>
</LinearLayout>
</FrameLayout>
String:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;;
<resources>
<string name="app_name">labtask</string>
<string-array name="sppinerValues">
<item>Select Items</item>
<item>USD to BDT</item>
<item>BMI</item>
</string-array>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>