Android Studio Problem: a) Develop the BMI app and achieve the following feature
ID: 3889767 • Letter: A
Question
Android Studio Problem:
a) Develop the BMI app and achieve the following features:
1) The user is able to switch between (kg, cm) and (lbs, feet, inch) units;
2) If the user does not type in anything, remind the user to type in the numbers.
3) Depending on the BMI, show different warning messages to the user. For example, if BMI > 30, show “Your BMI is XX; obesity!”
4) Use “method overloading” when calculate the BMI. One method take two inputs (kg and cm) to calculate; the second method has the same method name and take three input (lbs, feet, and inch) to calculate the BMI.
Java code
src/MainActivity.java
(Paste your java code here)
XML code
res/layout/activity_main.xml
(Paste your xml code here)
b) Create a new class call PatientAccount. Create two variables: String name and double balance. Create getter and setter for these two fields. Create two different constructors for the two variables. One constructor to set default values for the variables. The other constructor takes two inputs from the user. Create two addition methods in the class: withdraw (double money) and deposit (double money): ‘withdraw’ will reduce the balance by ‘money’ and ‘deposit’ will increase the ‘deposit’ by ‘money’. If the balance is less than 0 when doing ‘withdraw’, print out the following message using System.out.println(): "cannot withdraw, balance too low".
class PatiantAccount {
private String name;
private double balance;
//Put your code here
}
Explanation / Answer
public class PatientAccount {
private String name;
private double balance;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public PatientAccount(String name, double balance) {
this.name = name;
this.balance = balance;
}
public PatientAccount() {
name = null;
balance = 0.0;
}
public void withdraw(double money)
{
if(balance<0)
{
System.out.println("cannot withdraw, balance too low ");
}
else
balance=balance-money;
}
public void deposit(double money)
{
balance=balance+money;
}
}