For this assignment we're going to make another calculator. This
one will be a simple
four function (add, subtract, multiply, and divide) calculator, but
it will have state.
Specifically, the calculator will keep track of the result of the
most recent operation and
use that value as the first operand for the next operation. Take a
look at the sample
output below if this doesn't quite make sense. Your new calculator
class should have
the following fields and methods:
fields:
private double currentValue
methods:
public static int displayMenu()
public static double getOperand(String prompt)
public double getCurrentValue()
public void add(double operand2)
public void subtract(double operand2)
public void multiply(double operand2)
public void divide(double operand2)
public void clear()
The displayMenu option should allow the user to pick from these
options: add, subtract,
multiply, divide, clear, and quit. If the user has entered an
invalid option, it should reprompt them. Once a valid option has
been entered, the method should return it. The
getOperand method displays the prompt to the user, reads in a
double value, and
returns it. The getCurrentValue method just returns the number
stored in the
currentValue field. The add, subtract, multiply, and divide methods
now only need to
take one parameter because the first operand will be the
currentValue field. Also, these
methods do not need to return the result. Instead, they should
store it in the
currentValue field. The clear method should reset the currentValue
to zero. DO NOT
make the currentValue field static. With currentValue as an
instance field, we can
eventually write a program that allows users to have multiple
calculators running, each
computing different things. Note that because currentValue is an
instance field, the
methods that change it, such as add, subtract, multiply, and
divide, must be instance
methods. Methods such as displayMenu and getOperand can remain
static because
they do not need to access the state of the calculator. Once you
have all of the methods
written, write a main method that creates an instance of your
calculator class. Write a
loop that displays the current value (initially it will be zero),
asks the user what operation
they want to perform, computes the result, and repeats until the
user chooses to quit.
Sample output:
The current value is 0.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 1
What is the second number? 6
The current value is 6.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 2
What is the second number? 2
The current value is 4.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 3
What is the second number? 12
The current value is 48.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 4
What is the second number? 0
The current value is NaN
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 5
The current value is 0.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 1
What is the second number? 48
The current value is 48.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 4
What is the second number? 12
The current value is 4.0
Menu
1. Add
2. Subtract
3. Multiply
4. Divide
5. Clear
6. Quit
What would you like to do? 6
Goodbye!
In: Computer Science
consider the following equation,
max r = 4x + y + 6z
2x + y + 2z <= 10
x + 2y + z <= 9
x + 2z <= 6
x, y, z >= 0
The tableau corresponds with a step of the SIMPLEX method applied to the previous problem
|
Basic |
x |
y |
z |
s1 | s2 | s3 | bi |
| s1 |
1 |
1 |
0 |
1 |
0 |
-1 |
4 |
| s2 | 1 / 2 |
2 |
0 |
0 |
1 |
-1 / 2 |
6 |
| z | 1 / 2 |
0 |
1 |
0 |
0 |
1 / 2 |
3 |
what is the value of x, y, z and the objective function. Identify the entering and the leaving variables. Justify your response with the calculations performed (you can extend the previous tableau to perform the required calculations)
In: Advanced Math
D^2 (D + 1)y(t)= (D^2 +2)f(t)
a.) Find the characteristic polynomial, characteristic equation, characteristic roots, and characteristic modes of the system.
b.) Find y_o(t), the zero-input component of response y(t) for t>=0, if the the initial conditions are y_0 (0) = 4, y_0' (0) = 3, and y_0'' (0) = -1
In: Advanced Math
I have two bonds which Bond 1 pays annually and Bond 2 pays semi Annually
Bond 1:YTM=3.25%,Coupon value = 5.50%,maturity in years is 22
Bond 2:YTM=5.50%,Coupon value = 5.50%,maturity in years is 4
Face value is $100
calculate the prices of 2 Bonds
show formula as well
In: Finance
Question 1 (1 point)
The Kellogg Company periodically compares sales across departments. In one particular instance, they would like to determine if sales of snacks are different from sales of frozen foods. If snacks are group 1 and frozen foods are group 2, what are the hypotheses for this test?
Question 1 options:
|
|||
|
|||
|
|||
|
|||
|
Question 2 (1 point)
Do sit down restaurant franchises and fast food franchises differ significantly in stock price? Specifically, is the average stock price for sit-down restaurants different from the average stock price for fast food restaurants? If sit down restaurants are considered group 1 and fast food restaurants are group 2, what are the hypotheses of this scenario?
Question 2 options:
|
|||
|
|||
|
|||
|
|||
|
Question 3 (1 point)
Does the amount of hazardous material absorbed by the bodies of hazardous waste workers depend on gender? You want to test the hypotheses that the amount absorbed by men (group 1) is different from the amount absorbed by women (group 2). A random sample of 195 male workers and 199 female workers showed an average lead absorption in the blood of 12.13 (SD = 1.281) and 11.84 (SD = 0.821), respectively (measured in micrograms/deciliter). Assuming that the population standard deviations are the same, perform a two independent samples t-test on the hypotheses Null Hypothesis: μ1 = μ2, Alternative Hypothesis: μ1 ≠ μ2. What is the test statistic and p-value of this test?
Question 3 options:
|
|||
|
|||
|
|||
|
|||
|
Question 4 (1 point)
The owner of a local golf course wants to examine the difference between the average ages of males and females that play on the golf course. Specifically, he wants to test if the average age of males is greater than the average age of females. If the owner conducts a hypothesis test for two independent samples and calculates a p-value of 0.862, what is the appropriate conclusion? Label males as group 1 and females as group 2.
Question 4 options:
|
|||
|
|||
|
|||
|
|||
|
In: Statistics and Probability
A cell in G1 has 4 chromosomes (2n = 4).
How many chromosomes per cell at the end of the following stages?
How many DNA molecules per cell at the end of the following stages?
1.S phase
2.G2 phase
3.Metaphase
4.Anaphase
5.Cytokinesis
Please explain, thanks.
In: Biology
Find the equation of the tangent line to the curve at the point corresponding to the given value of t
1. x=cost+tsint, y=sint-tcost t=7pi/4
2. x=cost+tsint, y=sint-tcost t=3pi/4?
In: Math
For the following data set, X: 9, 6, 8, 3, 8, 9, 3, 4, 3, 7:
Calculate:
1. Variance
2. Mode
3. Mean
4. Mean Average Deviation (MAD) about the mean
5. Median
In: Statistics and Probability
|
What is the profitability index of a project that costs $8,000 and provides cash flows of $2,100 in years 1 and 2 and $4,100 in years 3 and 4? The discount rate is 10%. (Do not round intermediate calculations. Round your answer to 4 decimal places.) |
In: Finance
Explain how the ANN model works. (use the steps listed below)
Step 1: Determine the Topology and Activation Function
Step 2: Initiation
Step 3: Calculating Error
Step 4: Weight Adjustment
Step 4: Weight Adjustment
In: Operations Management