Imagine a cinema offering 50% discounts for groups or 3 or 4 people. Assuming the existence of an integer, nPeople that holds some value; declare an integer variable named discount that is assigned the value,50, if nPeople is 3 or 4.0, otherwiseFollowing is a buggy code. Click on "Check" and study the error. Then read the problem statement again carefully, and identify the issue based on the error message.For example:Test Resultint nPeople = 2;2 people. Discount of 0%int nPeople = 3;3 people. Discount of 50%int nPeople = 4;4 people. Discount of 50%int nPeople = 5;5 people. Discount of 0%int nPeople = 12;12 people. Discount of 0%
Question
Imagine a cinema offering 50% discounts for groups or 3 or 4 people. Assuming the existence of an integer, nPeople that holds some value; declare an integer variable named discount that is assigned the value,50, if nPeople is 3 or 4.0, otherwiseFollowing is a buggy code. Click on "Check" and study the error. Then read the problem statement again carefully, and identify the issue based on the error message.For example:Test Resultint nPeople = 2;2 people. Discount of 0%int nPeople = 3;3 people. Discount of 50%int nPeople = 4;4 people. Discount of 50%int nPeople = 5;5 people. Discount of 0%int nPeople = 12;12 people. Discount of 0%
Solution
Sure, here is the corrected code in Java:
int nPeople = 3; // you can change this value to test different scenarios
int discount;
if (nPeople == 3 || nPeople == 4) {
discount = 50;
} else {
discount = 0;
}
System.out.println(nPeople + " people. Discount of " + discount + "%");
This code first declares an integer variable nPeople and assigns it a value. Then it declares another integer variable discount. It then checks if nPeople is either 3 or 4. If it is, it assigns the value 50 to discount. If it's not, it assigns the value 0 to discount. Finally, it prints out the number of people and the discount percentage.
Similar Questions
The following code fragment is intended to keep reading in an integer from the user until the number entered is between 1 and 10 (inclusive). What kind of error does this code contain, and where?a.Logic error, on line 7b.Syntax error, on line 7c.Syntax error, on line 6d.Runtime error, on line 6e.Runtime error, on line 7f.Logic error, on line 6Clear my choice
Assuming the existence of two integers, doctor and donna, that hold some value; declare a variable named ood that holds the sum of doctor and donna.Following is buggy code. Click on "Check" and study the error. Then read the problem statement again carefully, and identify the issue based on the error message.This example also indicates how you don't need to worry about all the error messages, and how, many times, fixing the first few takes care of the rest.For example:Test Resultint doctor = 17, donna = 29;for doctor = 17 and donna = 29, ood = 46int doctor = 50, donna = -50;for doctor = 50 and donna = -50, ood = 0int doctor = Integer.MAX_VALUE, donna = 1; //THIS IS PRETTY COOL - BECAUSE IT CAUSES INTEGER OVERFLOWfor doctor = 2147483647 and donna = 1, ood = -2147483648
Q 2: You are developing a program that performs a division operation on two numbers provided by the user. However, there is a situation where a runtime error can occur due to a division by zero. To help junior developers learn about error handling in expressions and conditions, you want to create a program deliberately containing this error and guide them in diagnosing and fixing it.
Assuming the existence of two integers, begin and end, that hold some value; declare a variable named sumRange that holds the sum of all integers in the range [begin, end]. For example, if begin = 3 and end = 5, sumRange should be 3+4+5 = 12if begin = 8 and end = 8, sumRange should be 8if begin = 10 and end is ANY VALUE LESS THAN 10, sumRange should be 0Following is buggy code. Click on "Check" and study the error. Then read the problem statement again carefully, and identify the issue based on the error message.For example:Test Resultint begin = 10, end = 12;for begin = 10 and end = 12, sumRange = 33int begin = 50, end = 10;for begin = 50 and end = 10, sumRange = 0int begin = 120, end = 120;for begin = 120 and end = 120, sumRange = 120
A company manufacturing computer chips finds that 5% of all chips manufactured are defective. Management is concerned that employee inattention is partially responsible for the high defect rate. In an effort to decrease the percentage of defective chips, management decides to offer incentives to employees who have lower defect rates on their shifts. The incentive program is instituted for one month. If successful, the company will continue with the incentive program.a. Write the company's null and alternative hypotheses. Make sure to include the correct parameter, sign and number.Ho: H1: b. In this context describe a Type I error and the impact such an error would have on the company.Management thinks the incentive program was effective, when in fact it did not lower the defective rate from 5%.Management thinks the incentive program did not work, when in fact it did lower the defective rate from 5%.c. In this context describe a Type II error and the impact such an error would have on the company.Management thinks the incentive program was effective, when in fact it did not lower the defective rate from 5%.Management thinks the incentive program did not work, when in fact it did lower the defective rate from 5%.d. Based on the data they collected during the trial program, management found that a 95% confidence interval for the percentage of defective chips was (4%, 6%). What conclusion should management reach about the new incentive program? Explain.Since 5% is not in the interval, we have enough evidence that the defect rate has been decreased.Since 5% is in the interval, we do not have evidence that the defect rate has been decreased.e. Describe to management an advantage of decreasing the significance level.Lowers the probability of a Type I errorLowers the probability of a Type II errorf. Describe to management a disadvantage of decreasing the significance level.Raises the probability of a Type I errorRaises the probability of a Type II errorg. Management decided to extend the incentive program so that the decision can be made on three months of data instead. Will the power increase, decrease, or remain the same with a larger sample size, assuming they use the same level of significance?The power willIncreaseDecreaseStay the same
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.