Concept explainers
Rewrite the following if-else statements as statements that use the conditional operator.
a) if (x > y)
z = 1;
else
z = 20;
b) if {temp > 45)
population = base * 10;
else
population = base * 2;
c) if (hours > 40)
wages *= 1.5;
else
wages *= 1;
d) if (result >= 0}
System.out.println(“The result is positive.”);
else
System.out.println(“The result is negative.”);
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Additional Engineering Textbook Solutions
Experiencing MIS
Starting out with Visual C# (4th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with C++: Early Objects (9th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Java How To Program (Early Objects)
- Question 10 programming in racket Write a procedure (timezone) that takes no arguments and returns a ; *string* indicating your time zone. ; Remember the difference between a procedure call and the evaluation of a variable! ; Ex: (timezone) => "EST"arrow_forward3. Convert the following switch statement into if-else statements then into if-then statements: String dayString1, dayString2, dayString3; int day = KB.nextInt (); switch (day) { case 1: dayStringl case 2: dayString2 "Saturday"; "Sunday"; break; case 3: dayString3 = "Monday"; break; case 4: dayStringl = "Tuesday"; case 5: daystring2 = "Wednesday"; break; default: dayString3 = "Invalid day"; break; } 4. Write a program that displays the following pattern: A A A A BB AA A ССС AA AA DDDD AAAΑ EEEEE ΑAAAΑΑ FFFFFFarrow_forwardLogical table: Write the truth value of the following logical statementsX=17; Y=35Question;!(Y!=X | | (X<Y)(Y==X) && (X<=Y)arrow_forward
- Interest on a credit card’s unpaid balance is calculated using the average daily balance. Suppose that netBalanceis the balance shown in the bill, paymentis the payment made, d1is the number of days in the billing cycle, and d2is the number of days payment is made before the billing cycle. Then the average daily balance is: averageDailyBalance = (netBalance * d1 –payment * d2) / d1 if the interest rate per month is say, 0.0152, then the interest on the unpaid balanceis: interest = averageDailyBalance * 0.0152 Design a program that accepts as input netBalance, payment, d1, d2, and interest rate per month. The program outputs the interest charged. Format your output to two decimal places. C++arrow_forwardPROGRAM DESCRIPTION John dela Cruz is interested in knowing how much his interest earning would be after some time. Assuming there are no deposits other than the original investment, the balance in a savings account after one year may be calculated as: amount = principal * (1 + rate/m)" interest = amount - principal Principal is the balance in the savings account, rate is the interest rate (0 to 100), m is the number of times the interest is compounded during a year (m is either 1,2,3 or 4 if the interest is compounded quarterly) and nis the number of year., Write a program that asks for the borrower's lastname, borrower's first name, borrower's middle name, civil status (Single, Married, Widow), principal, the interest rate and the number of times the interest is compounded. Follow the format of the report provided in the example. OUTPUT Example 1 Enter the borrower's lastname : Enter the borrower's firstname : Enter the borrower's middle name: Enter civil status : Married Enter the…arrow_forwardWrite a multiple assignment statement that can be used instead of the followinggroup of assignment statements:east = 1;west = 1;north = 1;south = 1;arrow_forward
- Code_Method to check if x is power of 2*/ static boolean isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x!=0 && ((x&(x-1)) == 0); }arrow_forwardQ7-Write a program that simulates a simple calculator. It reads two integers and a character. If the character is a +, the sum is printed; if it is a -, the difference is printed; if it is a *, the product is printed; if it is a /, the quotient is printed; and if it is a %, the remainder is printed. (Use a switch statement.)arrow_forwardProblem 2: Employee Payment The Stark Industry needs a program to calculate how much to pay their hourly employees. They have the following rules: An employee gets paid (hours worked) × (base pay), for each hour up to 40 hours. For every hour over 40, they get overtime = (base pay) × 1.5. If the number of hours is greater than 60, print an error message. Example: If an employee works for 45 hours, and his base pay is $8 , the he will get= (40 * 8)+ [5* (8 * 1.5)] = $380 Create a new class called StarkIndustry. Write a method that takes the base pay and hours worked as parameters, and prints the total pay or an error. Write a main method that calls this method for each of these employees: Employee No Base pay Hours Worked Employee 1 $7.20 35 Employee 2 $8.20 47 Employee 2 $10.50 73 You will have to submit StarkIndustry.java file.arrow_forward
- 22. What is the value of x after the following statements are executed? int x = 5; switch(x) { case 5: x += 2; case 6: x++; break; default: x *= 2; break; }arrow_forwardPlease answer item number 3. (pyhthon programming)arrow_forwardThe following statement should determine if x is not greater than 20. What is wrong with it?arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning