Question

In: Computer Science

How can I configure the button in this tip calculator to calculate the total using the...

How can I configure the button in this tip calculator to calculate the total using the entires for the bill and tip percentage? I'm using Visual Studio 2019 Xamarin.Forms

Main.Page.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Accomplish_2.MainPage"
BackgroundColor="Gray"
Padding="5">

<StackLayout>
<!-- Place new controls here -->
<Label Text="Tip Calculator"
HorizontalOptions="Center"
VerticalOptions="Center"
FontSize="Title"
FontAttributes="Bold"/>

<BoxView BackgroundColor="LightPink"
HeightRequest="3"></BoxView>
  
<Entry Placeholder="Bill Total"
Keyboard="Numeric"
x:Name="billTotal"></Entry>
  
<Entry Placeholder="Tip Percentage"
Keyboard="Numeric"
x:Name="tipPercent"></Entry>

<Button Text="Calculate"
Clicked="Button_Clicked"></Button>
  
</StackLayout>

</ContentPage>

Everything above should be good to go, I just can't figure out how to get some actual calculations done with the other page of my code.

Main.Page.xaml.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Accomplish_2
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}

private void Button_Clicked(object sender, EventArgs e)
{
???????? _______________________________________________?????????
}
}
}

Solutions

Expert Solution

Explanation & steps

Based on code given, to calculate total using the entries for the bill and tip percentage using Visual Studio 2019 Xamarin.Forms. There are various ways to achieve this. The simplest way is to directly using x:name="billTotal" as billTotal.Text to read the text from input. This is direct way without any object oriented concept. The direct solution is provided below.

Only add [ var totalAmount= Double.Parse(billTotal.Text) + Double.Parse(tipPercent.Text);]

  • ***Important thing to note is to convert the text entries into double data type, so we can use Double.Parse(billTotal.Text) |Double.Parse(tipPercent.Text)

private void Button_Clicked(object sender, EventArgs e)
{
var totalAmount= Double.Parse(billTotal.Text) + Double.Parse(tipPercent.Text);
}

Further direction, if there is enterprise level mobile application development.Recently as industry enterprise best practice we can use model view binder or MVVM model view view model application architecture. This is bit complex but there is lot of sample cose in Github for Xamarin.forms. One can visit Channel9.msdn microsoft to go through free videos to learn and implement.

MVVM Architecture- Binding Context & Data Binding

  • View;.xaml XAML user interface
  • Model is Form data, called ;
  • ViewModel : interaction between the View and the Model.

Data binding is binding between view and view model. The BindingContext in presentation (view) is an object instance of the ViewModel.


Related Solutions

Javascript Calculator Algorithm to calculate a tip percentage given the bill amount and total bill including...
Javascript Calculator Algorithm to calculate a tip percentage given the bill amount and total bill including tip. Asker suer for bill without tip: Ask the user for total bill with tip: Ask the user how many people splitting bill: Submit button to calculate the tip percentage
JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I...
JS Bin / Tax Calculator / using HTML | CSS | JavaScript ------------------------------------------------------------------------------------------- How can I edit the JavaScript below so that when the calculate button is clicked the total price only shows two decimal places by using the toFixed() method? ----------------------------------------------------------------------------------------------------------- JavaScript: // Variables var tax = "tax"; // Tax percentage var taxRate = document.getElementById('tax'); // Selecting tax element // On the time of loading the DOM we are setting the tax rate window.addEventListener('DOMContentLoaded', (event) => { taxRate.value =...
How would I complete this using a scientific calculator?
You invest $100 in a risky asset with an expected rate of return of 0.12 and a standard deviation of 0.15 and a T-bill with a rate of return of 0.05.What percentages of your money must be invested in the risky asset and the risk-free asset, respectively, to form a portfolio with an expected return of 0.09?How would I complete this using a scientific calculator?
Using the BAII Plus calculator I am having a difficult time using this calculator to solve...
Using the BAII Plus calculator I am having a difficult time using this calculator to solve this MIRR 0 =-325,000 1=50,000 2= 75,000 3=-60,000 4=225,000 5=300,000 Required rate of return =15% We discount all negative CFs(at 15%) time 0 We compound all positive cash flows (at 15%) to 5 years This is now the TV or Terminal Value Please help me understand how to calculate these numbers?
How can i calculate Cost of goods sold and ending inventory using FIFO, LIFO and the...
How can i calculate Cost of goods sold and ending inventory using FIFO, LIFO and the periodic system given the information below? On December 1, 2017, Ivanhoe Company had the account balances shown below. Debits Credits Cash $5,180 Accumulated Depreciation—Equipment $1,460 Accounts Receivable 4,230 Accounts Payable 2,710 Inventory (2,900 x $0.60) 1,740 Common Stock 10,200 Equipment 21,400 Retained Earnings 18,180 $32,550 $32,550 The following transactions occurred during December. Dec. 3 Purchased 3,900 units of inventory on account at a cost...
How to calculate Traffic LOS '' Level of service '' without using FFS. I can use...
How to calculate Traffic LOS '' Level of service '' without using FFS. I can use collected volume, and how can I do that ? and what are the information's needed ?
Can you explain how to calculate with TI-84 calculator if possible? Thanks will rate! 1) This...
Can you explain how to calculate with TI-84 calculator if possible? Thanks will rate! 1) This exercise uses the normal probability density function and requires the use of either technology or a table of values of the standard normal distribution. The cash operating expenses of the regional phone companies during the first half of 1994 were distributed about a mean of $29.77 per access line per month, with a standard deviation of $2.65. Company A's operating expenses were $28.00 per...
how can i calculate a "required levered return"?
how can i calculate a "required levered return"?
How can I calculate the net income trends ?
How can I calculate the net income trends ?
How do I solve this system of equations without using a calculator or fancy matrix math?...
How do I solve this system of equations without using a calculator or fancy matrix math? v1 = 1.8 v2 = ? v3 = ? (1) v1 = 1.8 (2) 7150v2+1350v3  = 12780 (3) 7150v22 + 1350v32 = 23166
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT