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
C# Tip Calculator. I can't figure the code out for this assignment can I get some...
C# Tip Calculator. I can't figure the code out for this assignment can I get some help For this assignment, you'll create a simple tip calculator. Expected program flow: Ask the user for the bill total. Ask the user for the tip percent. Print the final output in the following format when the user enters 10 and 15 for the first two prompts: Total for bill $10.00 with a 15% tip is $11.50 Note that the money values should be...
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?
How can I solve this using the HP 10bii financial calculator? A well-known financial writer argues...
How can I solve this using the HP 10bii financial calculator? A well-known financial writer argues that he can earn an extremely high return buying wine by the case. Specifically, he assumes that he will consume one $14 bottle of fine Bordeaux per week for the next 12 weeks. He can either pay $14 per week or buy a case of 12 bottles today. If he buys the case, he receives a discount of 8 percent. Assume he buys the...
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...
Can someone explain me how to calculate this on a TI-83 PLUS financial calculator... What is...
Can someone explain me how to calculate this on a TI-83 PLUS financial calculator... What is the duration of a five-year, $1,000 Treasury bond with a 10 percent semiannual coupon selling at par? Selling with a yield to maturity of 12 percent? 14 percent? What can you conclude about the relationship between duration and yield to maturity? Plot the relationship. Why does this relationship exist?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT