Concept explainers
Given that the int variable temp contains a temperature that is not negative, write a Java statement that uses the conditional operator to set the String variable label to either “degree” or “degree”. We want to use label to produce grammatically correct output, such as 0 degrees, 1 degree, 2 degrees, and so on. If you have not studied the conditional operator, use an if-else statement instead.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out with Python (3rd Edition)
C Programming Language
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting out with Visual C# (4th Edition)
- Write a JAVA program that asks the user to input the instructor Salary (double) and Academic Rank (String) as “Assistant" ,"Associate" ,or “Lecturer" (ignore case). Assume all inputs are valid and there is no need for validation. Your program should display the Tax amount and Net Salary as follows: Тах Атоиnt % Salary x Tаx Rate Net Salary= Salary – Tax Amount Tax Rate can found from the following table Academic Rank Tax Rate Assistant Associate 9% 12% Lecturer 7% Sample Input / Output Input instructor Salary: 955.7 Input Academic Rank: Assistant The amount of Tax is BD 86.013 The Net Salary is BD 869.687 Note: Your answer should follow the given sample input / output.arrow_forward1.Write a Java program of Rock-Paper-Scissors. Two players will input the first equivalent letter. For example: S for Scissor, R for Rock and P for Paper. Then Display the winner with a message such as: "Player 1 Wins" or "Rock breaks Scissors" or "It's a Tie", ETC. Use if-else statements. 2. Given the flowchart below, what does this Flowchart do? Conver the Flowchart into a Java Program using if-else statements. 3. Write a java program that accepts an ordinary number and outputs its equivalent roman numerals. Below is some samples of ordinary number and roman numerals. Ordinary numbers Roman numerals1 I5 V10 X50 L 100 C500 D1000 M If you input ordinary number 2968…arrow_forwardAn internet service provider has three different subscription packages for its customers: Package A: for RM9.95 per month 10 hours of access are provided. Additional hours are RM2.00 per hour. Package B: for RM13.95 per month 20 hours of access are provided. Additional hours are RM 1.00 per hour Package C: for RM 19.95 per month unlimited access is provided. Write a JAVA program using if/else or switch selection to calculates a customer’s monthly bill. It should ask the user to enter the letter of the package the customer has purchased (A, B, or C) and the number of hours that were used. It should then display the total charges.arrow_forward
- Create a program and inside your program, type the code as given below. Then rewrite the nested ifs with logical operators. 1. int num = 5; // nested if if ( num > 0 ) { if ( num 5) { if (y > 3) { System.out.println ("x is greater and y is greater"); else if(x = 78) { System.out.println("It will snow!"); else { System.out.println ("What am I? The weatherman?"); Output will look like this (the first line being the given code; the repeated line being the rewritten code): num is between 0 and 10 num is between 0 and 10 x is less and y is less x is less and y is less It will snow! It will snow!arrow_forwardWrite a Java program to help a convenience store clerk decide whether or not to sell beer to a customer. Beer can only be sold to somebody who is 21 years old or more and has enough money (beer costs $5.00). If the customer is too young, tell them how many years they must wait before returning. If they have too little money, tell them how much more is needed. program will require the use of nested "if/else" statements. Examine the sample outputs carefully in order to structure your code in a logical manner. Work out your logic in pseudo code first. Test carefully to ensure that your logic works exactly as it should. This ** BONUS** 5 bonus points if you use printf successfully to print out the dollar amount needed when the customer does not have enough money. Notes: Carefully read and adhere to coding standards – pay particular attention to the use of braces and indentation Use CONSTANTS for the beer price and minimum age Choose meaningful identifiers for all variables and constants…arrow_forward2. Write a java program that ask user to enter the grade depending on the below grading system :a. Under 50-F c. 50 to 60 - D d. 60 to 70 - C e. 70 to 80 -Bf. more than 80 - A after that print the equivalent gradearrow_forward
- An instructor wants to give feedback to students in an assignment according to the number of correctly solved programs. Example of feedback :Nb of correct programs Feedback 0 incomplete assignment1 partially correct assignment2 Satisfactory attempt 3 Good attempt4 Excellent attemptThe following figure shows an example of execution.Write the Java program that reads the number of correctly solved programs and displays the adequate feedback.Note: Choose your own feedback message and do not copy from the previous table. Use any of the conditional statements like if-else/ if-else-if/switch case.arrow_forwardWrite a program that prints the insurance fee to pay for a pet according to the following rules: (Note: must use a switch statement to determine pet fee) A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been neutered costs $40.A cat that has not been neutered costs $60.A bird or reptile costs nothing.Any other animal generates an error message. The program should prompt the user for the appropriate information: a character code for the pet type, and a yes/no response for the neutered status. Use a code letter to determine the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird, R or r represents a reptile, and anything else represents some other kind of animal). Use a code letter to determine the neutered status(i.e. Y or y represents yes, N or n represents no). The user should be allowed to enter the input in either upper or lower case. It prints out the type of animal (full name of animal)…arrow_forwardThe objective of this program is to demonstrate your proficiency with the if-elif-else construct. Your program will consist of a simple guessing game. Using the random module, generate an integer between 1 and 10. This will be the secret. You will then ask the user for a guess between 1 and 10. . If the guess is greater than the secret respond, "Too high". • If the guess is less than the secret respond, "Too low". . If both numbers are equal respond, "Success!". Remember to test your program to ensure that all of the comparisons work. Please note that a loop is not required. The images below shows the program being run multiple times to display the three different possible output messages. Your display should look like this. User input is highlighted in green. Please enter your guess: 10 Too high! Please enter your guess: 5 Too low! Please enter your guess: 1 Success!arrow_forward
- Write a program that reads the temperature and unit from the user and prints a message indicating if it’s hot, cool or cold. The user may enter the temperature either in Fahrenheit or in Celsius. Below are the intervals. Your program should use nested if-else statements. If the input is invalid, print an error message and terminate the program.arrow_forwardWrite an if statement in Java that prints "Pass" if the grade is greater than or equal to 70 and prints "Fail" if the grade is below 70. If the grade is below 70 print "You have to do Exam2."arrow_forwardWrite a Regular expression that check whether a string contains an Vowel or not? You have also include the driver code in Java Language. Your driver code should take string from the user.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education