Allow the user to enter the number of people in the party. Calculate and display the amount owed by each person if the bill were to be split evenly among the party members.
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mdc.tippcalcula"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
-------------------------------
<?xml version="1.0" encoding="utf-8"?> <GridLayout 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:columnCount="2" android:useDefaultMargins="true" tools:context=".MainActivity"> <EditText android:id="@+id/amountEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:hint="" android:digits="0123456789" android:inputType="number" android:layout_column="0" android:layout_columnSpan="2" android:maxLength="6"/> <TextView android:id="@+id/amountTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_row="0" android:layout_column="0" android:layout_columnSpan="2" android:layout_gravity="fill_horizontal" android:background="@color/amount_background" android:elevation="@dimen/elevation" android:hint="@string/enter_amount" android:padding="@dimen/textview_padding" /> <TextView android:id="@+id/percentTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|end" android:text="@string/tip_percentage" /> <SeekBar android:id="@+id/percentSeekBar" android:layout_width="wrap_content" android:layout_height="@dimen/seekbar_height" android:layout_gravity="fill_horizontal" android:max="30" android:progress="15"/> <TextView android:id="@+id/TipLabelTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/tip" /> <TextView android:id="@+id/tipTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_horizontal" android:background="@color/result_background" android:elevation="@dimen/elevation" android:gravity="center" android:padding="@dimen/textview_padding" /> <TextView android:id="@+id/totalLabelTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/total" /> <TextView android:id="@+id/totalTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_horizontal" android:background="@color/result_background" android:elevation="@dimen/elevation" android:gravity="center" android:padding="@dimen/textview_padding" /> <EditText android:id="@+id/numberOfPeopleEditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_horizontal" android:background="@color/result_background" android:elevation="@dimen/elevation" android:gravity="center" android:padding="@dimen/textview_padding" android:ems="10" android:hint="Enter Number Of People" android:digits="012345678" android:inputType="number" android:layout_columnSpan="2"/> <TextView android:id="@+id/eachPersonLabelTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="@string/each" /> <TextView android:id="@+id/eachPersonTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_horizontal" android:background="@color/result_background" android:elevation="@dimen/elevation" android:gravity="center" android:padding="@dimen/textview_padding" /> </GridLayout>
----------
package com.mdc.tippcalcula; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import android.text.Editable; import android.text.TextWatcher; import android.widget.EditText; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import java.text.NumberFormat; public class MainActivity extends AppCompatActivity { private static final NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); private static final NumberFormat percentFormat = NumberFormat.getCurrencyInstance(); private double billAmount = 0.0; private double percent = 0.15; private double numPeople = 0; private TextView percentTextView; private TextView tipTextView; private TextView amountTextView; private TextView totalTextView; private TextView eachPersonTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); amountTextView = (TextView) findViewById (R.id.amountTextView); percentTextView = (TextView) findViewById (R.id.percentTextView); tipTextView = (TextView) findViewById(R.id.tipTextView); totalTextView = (TextView) findViewById(R.id.totalTextView); eachPersonTextView = (TextView) findViewById(R.id.eachPersonTextView); tipTextView.setText(currencyFormat.format(0)); totalTextView.setText(currencyFormat.format(0)); eachPersonTextView.setText(currencyFormat.format(0)); EditText amountEditText = (EditText) findViewById(R.id.amountEditText); amountEditText.addTextChangedListener(amountEditTextWatcher); SeekBar percentSeekBar = (SeekBar) findViewById(R.id.percentSeekBar); percentSeekBar.setOnSeekBarChangeListener(seekBarListener); } private void calculate(){ percentTextView.setText(percentFormat.format(percent)); double tip = billAmount * percent; double total = billAmount + tip; tipTextView.setText(currencyFormat.format(tip)); totalTextView.setText((currencyFormat.format(total))); } private final OnSeekBarChangeListener seekBarListener = new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean b) { percent = progress / 100.0; calculate(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }; private final TextWatcher amountEditTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { try { billAmount = Double.parseDouble(charSequence.toString()) / 100.0; amountTextView.setText(currencyFormat.format(billAmount)); } catch (NumberFormatException e){ amountTextView.setText(""); billAmount = 0.0; } } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { } }; }
------
<?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="textview_padding">12dp</dimen> <dimen name="elevation">4dp</dimen> <dimen name="seekbar_height">40dp</dimen> </resources>
---
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#6200EE</color> <color name="colorPrimaryDark">#3700B3</color> <color name="colorAccent">#03DAC5</color> <color name="amount_background">#BBDEFB</color> <color name="result_background">#ffE0B2</color> </resources>
----
<resources> <string name="app_name">Tip Calculator</string> <string name="enter_amount"> Enter Amount</string> <string name="tip_percentage">15%</string> <string name="tip">Tip</string> <string name="total">Total</string> <string name="number">No. Of People</string> <string name="each">Each Person</string> </resources>
In: Computer Science
Java Programming Question:
A dog shelter would like a simple system to keep track of all the dogs that pass through the facility. The system must record for each dog:
dogId (int) - must be unique
name (string)
age (double) - cannot be less than 0 or more than 25
breed (string)
sex (char) – m for male, f for female
foundHome (bool) - true means the dogs has been places in a home false otherwise.
You must create an object oriented java solution with a text based menu as summarized on the next page. The system must check that valid data is entered. For example, the menu has four items so only 1 to 5 must be allowed as input from the menu.
Summary of Operations
System Menu:
Overview:
Add Dog:
When a dog is added to the system, you must check that the dogId is not already used in the system. All new dogs have no home as yet (foundHome = false).
View all Dogs:
This menu option shows all dogs in the system. This includes dogs that have a home and those that do not.
View all available dogs:
Shows all dogs in the system, that have no homes as yet.
View dog:
Asks the user for a dogId and then displays the dog information if found and “There is no dog with that id..” if it is not found.
Update dog home status:
Asks the user for a dogId. If a dog with that id is found, the “foundHome” status is changed to true and the dog information is to be displayed. If the dog is not found the message “There is no dog with that id..” should be displayed.
In: Computer Science
In: Computer Science
Python:
Write a program that keeps track of a game score and declares the winner when the game is over. A game is over when either one player scores 10 or more points with at least 2 more points than the opponent. A game is also over when one player scores 7 points and the opponent scores none. The program should begin by asking the names of the two players. Then, it should keep asking who won the point till the game is over (you will need to prompt user to determine who won the point. In the end it should display the winner and the final score.
In: Computer Science
Suppose THREE packets, each of length, L = 20 bits arrive at a router at the same time. Assume that there are no packets being transmitted or queued at the router. Let the router's transmission rate, R = 5 bit/seconds.
1.What is the queuing delay for each of these 3 packets?
2.What is the average queuing delay for the 3 packets?
3.Suppose the speed of propagation is s m/s, the distance between A and B is d meters, and the transmission rate of the link between A and B is R bps.Consider sending two packets of size L1 bits and L2 bits from A to B.
What is the total delay of sending these two packets from A to B in terms of L1, L2, R, d and s? Ignore the processing delay.
In: Computer Science
Complete the PA7_incomplete.py program (posted below) for an infinite interactive loop to process a dictionary. The program starts by asking an input file name where the dictionary entries are stored. This file will be assumed be present and to contain two items in each line as key and value pairs separated by a comma, like the example.txt file (posted below). The file could be possibly empty. The program reads the contents of this file into a dictionary, closes the file and presents user with the following menu choices in an infinite loop: Add an entry Show value for a key Delete an entry Save the file Print the current dictionary Quit Complete rest of the program to process the dictionary interactively with the user. The following appropriate actions should be taken for each one of them and then the menu should be shown again unless the user quits. Add an entry: Ask the user for the key and value, and make an entry, if the key already exists then prompt the user whether to overwrite its value. Show value for a key: Ask the user for the key and show the corresponding value, point out if the key does not exist.
def main():
d = {} # dictionary
# Read the file's contents in the dictionary d
filename = input("Give the file name: ")
file = open(filename,"r")
for line in file:
# read key and value
key, value = line.split(",")
# remove whitespaces before and after
key = key.lstrip()
key = key.rstrip()
value = value.lstrip()
value = value.rstrip()
# insert entry in the dictionary
d[key] = value
file.close()
loop=True # continue looping if true
while (loop):
print("\n\nEnter one of the following menu choices:")
print("1 Add an entry")
print("2 Show value for a key")
print("3 Delete an entry")
print("4 Save the file")
print("5 Print the current dictionary")
print("6 Quit")
choice = input("Choice 1-6: ")
print("\n\n")
if (choice=="1"): # Add an entry
k = input("Give the key: ")
v = input("Give its value: ")
# complete the rest
elif (choice=="2"): # Show value for a key
k = input("Give the key: ")
# complete the rest
elif (choice=="3"): # Delete an entry
k = input("Give the key to delete the entry: ")
# complete the rest
elif (choice=="4"): # Save the file
print("Saving the file")
# complete the rest
elif (choice=="5"): # Print the current dictionary
l = list(d.keys()) # get all the keys
l.sort() # sort them
# complete the rest
elif (choice=="6"): # Quit
loop=False
# complete the rest
else :
print("Incorrect choice")
Delete an entry: Ask the user for the key and delete the entry, point out if the key does not exist Save the file: Save to the same file name in the same comma-separated format (do not worry about the order of entries), make sure to close the file Print the current dictionary: show value entries of the current dictionary on the screen (in alphabetical order of the keys). End the program. If the dictionary has been modified since the last save, then prompt the user whether it should be saved before quitting.
In: Computer Science
C++ mainDisplay.cpp
Write the function displayAt that receives the two STL lists; vList and pList. The function should display the elements in vList that are in positions specified by pList. For example, if pList has the elements (2, 5, 6, 8) then the elements in positions 2, 5, 6, and 8 in vList are displayed. Use only the public STL container operations.
In: Computer Science
Assignment
Extend the Game of Life assignment to load its configuration from a file.
Functional Requirements
CODE I HAVE:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "life.h"
int main(int argc, char *argv[]) {
int board[XSIZE][YSIZE];
int rounds = DEFAULTROUNDS;
initBoard(board);
board[5][5] = ALIVE;
board[5][6] = ALIVE;
board[5][7] = ALIVE;
board[6][6] = ALIVE;
printf("Playing %d rounds.\n\n", rounds);
for (int i = 0; i < 15; i++) {
printf("Round: %d\n", i + 1);
printBoard(board);
playRound(board);
sleep(1);
}
return 0;
}
void initBoard(int vBoard[][YSIZE]) {
/* write this functions */
for (int i = 0; i < XSIZE; i++)
for (int j = 0; j < YSIZE; j++)
//Sets it to dead values on the board
vBoard[i][j] = DEAD;
}
void playRound(int vBoard[][YSIZE]) {
int tmpBoard[XSIZE][YSIZE];
initBoard(tmpBoard);
// perform the algorithm on vBoard, but update tmpBoard
// with the new state
for (int x = 0; x < XSIZE; x++) {
for (int y = 0; y < YSIZE; y++) {
int numNeighbors = neighbors(vBoard, x, y);
// If a cell is alive
if (vBoard[x][y] == ALIVE) {
//If it has less than two living neighbors, it dies.
if (numNeighbors < 2)
//SETS TO DEAD
tmpBoard[x][y] = DEAD;
//Else if it has two or three living neighbors, it lives and continues to the next generation
else if (numNeighbors <= 3)
//SETS TO ALIVE
tmpBoard[x][y] = ALIVE;
//Else if it has more than three living neighbors, it dies becuase of overpopulation
else
//SETS TO DEAD
tmpBoard[x][y] = DEAD;
}
//Else if a cell is dead
else {
// if it has exactly three living neighbors, it becomes alive due to reproduction.
if (numNeighbors == 3)
//Sets to ALIVE
tmpBoard[x][y] = ALIVE;
}
}
}
// copy tmpBoard over vBoard
for (int x = 0; x < XSIZE; x++) {
for (int y = 0; y < YSIZE; y++) {
vBoard[x][y] = tmpBoard[x][y];
}
}
}
int onBoard(int x, int y) {
if (x < 0 || x >= XSIZE)
return 0;
else if (y < 0 || y >= YSIZE)
return 0;
else
return 1;
}
int neighbors(int vBoard[][YSIZE], int x, int y) {
int n = 0;
int xp1 = x + 1;
int xm1 = x - 1;
int yp1 = y + 1;
int ym1 = y - 1;
if (onBoard(xm1, y) && vBoard[xm1][y] == ALIVE)
n++;
if (onBoard(xm1, yp1) && vBoard[xm1][yp1] == ALIVE)
n++;
if (onBoard(x, yp1) && vBoard[x][yp1] == ALIVE)
n++;
if (onBoard(xp1, yp1) && vBoard[xp1][yp1] == ALIVE)
n++;
if (onBoard(xp1, y) && vBoard[xp1][y] == ALIVE)
n++;
if (onBoard(xp1, ym1) && vBoard[xp1][ym1] == ALIVE)
n++;
if (onBoard(x, ym1) && vBoard[x][ym1] == ALIVE)
n++;
if (onBoard(xm1, ym1) && vBoard[xm1][ym1] == ALIVE)
n++;
return n;
}
void printBoard(int vBoard[XSIZE][YSIZE]) {
for (int i = 0; i < XSIZE; i++) {
for (int j = 0; j < YSIZE; j++) {
//prints dead characters as - and alive chracters as O
printf("%c ", vBoard[i][j] ? 'O' : '-');
}
//prints space to keep rounds seperate
printf("\n");
}
}
In: Computer Science
C++
Using your completed LinkedList template class, developed in homework and lab, write a program that implements and properly tests the following functions (these functions are not member functions of the class, you will write these function in mainTest.cpp )
1. Function compare that receives two LinkedList objects and compares the data in the nodes of the two lists to check if they are the same. The lists are equal only if they have the same number of nodes and corresponding nodes contain the same data. The function returns true or false to main.
2. Function mergeLists that receives two LinkedList objects. The function merges the sorted lists into a new list then returns the new list object back to main. Display the returned list.
Linkedlist.h link: https://pastebin.com/L4UUT3V8
In: Computer Science
The following program uses Pthreads to create two threads. They do some work for the process and then exit. The process then outputs a result.
Assume all supporting libraries and other functions have been included.
=> Use the answer text field to describe what work (operations) the threads are doing, and what kind of result (what is it?) is output by the process.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
int res1, res2, a[100], b[100];
void *runner1(void *param);
void *runner2(void *param);
void readData(int []);
int main(int argc, char *argv[])
{
pthread_t tid1, tid2;
pthread_attr_t attr;
readData(a);
readData(b);
pthread_attr_init(&attr);
pthread_create(&tid1, &attr, runner1, argv[1]);
pthread_create(&tid2, &attr, runner2, argv[1]);
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
printf("result = %d\n", res1+res2);
}
void *runner1(void *param)
{
int i, upper = atoi(param);
res1 = 0;
for (i = 0; i < upper; i++)
res1 += a[i];
pthread_exit(0);
}
void *runner2(void *param)
{
int i, upper = atoi(param);
res2 = 0;
for (i = 0; i < upper; i++)
res2 += b[i];
pthread_exit(0);
}
In: Computer Science
Can you compare 2 search engines based on information retrieval models like Probability model or boolean model?
In: Computer Science
In: Computer Science
The following program uses Pthreads to create two threads. They do some work for the process and then exit. The process then outputs a result.
Assume all supporting libraries and other functions have been included.
=> Use the answer text field to describe what work (operations) the threads are doing, and what kind of result (what is it?) is output by the process.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
int res1, res2, a[100], b[100];
void *runner1(void *param);
void *runner2(void *param);
void readData(int []);
int main(int argc, char *argv[])
{
pthread_t tid1, tid2;
pthread_attr_t attr;
readData(a);
readData(b);
pthread_attr_init(&attr);
pthread_create(&tid1, &attr, runner1, argv[1]);
pthread_create(&tid2, &attr, runner2, argv[1]);
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
printf("result = %d\n", res1+res2);
}
void *runner1(void *param)
{
int i, upper = atoi(param);
res1 = 0;
for (i = 0; i < upper; i++)
res1 += a[i];
pthread_exit(0);
}
void *runner2(void *param)
{
int i, upper = atoi(param);
res2 = 0;
for (i = 0; i < upper; i++)
res2 += b[i];
pthread_exit(0);
}
HTML EditorKeyboard Shortcuts
In: Computer Science
Q: Mention all five elements that Web 2.0 site must contain.
Avoid Plagiarism (copying) please.
In: Computer Science
1.If variable Test(i,j) is selected so the first column represents the student number (1,2,..., 32), 2nd column represents the score of the first homework, 3rd column represents the score of the 2nd homework, etc. If there is a total of 5 homework for this class, what is the size of variable Test ? Explain why, Does (i,i) is the same as rows x columns?
(6,32)
(32,6)
2.If the size of b is shown on the workspace menu for MATLAB as 4x4, what type of variable b is? Explain why
2D matrix
4D matrix
3. If you want to multiply 8 by the result of adding 12 to 5, which command would you use in MATLAB? Explain why
[5+12]*8
(8+12)*5
4. If the following commands are executed in MATLAB
a = [1:5;logspace(2,8,5)]
How many rows are in a?
2
3
8
5
In: Computer Science