Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3, Problem 12E
Consider the previous question, but include + or – letter grades. A+ is 4.25, A– is 3.75, B+ is 3.25. B– is 2.75, and so on.
- a. Why can’t we use one switch statement with no other conditionals to convert these additional letter grades?
- b. Write a fragment of code that will do the conversion using a multibranch if-also statement.
- c. Write a fragment of code that will do the conversion using nested switch statements.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Correct answer will be upvoted else downvoted. Computer science.
You are given a positive integer x. Check whether the number x is representable as the amount of the solid shapes of two positive integers.
Officially, you really want to check in case there are two integers an and b (1≤a,b) to such an extent that a3+b3=x.
For instance, in the event that x=35, the numbers a=2 and b=3 are reasonable (23+33=8+27=35). In the event that x=4, no pair of numbers an and b is reasonable.
Input
The primary line contains one integer t (1≤t≤100) — the number of experiments. Then, at that point, t experiments follow.
Each experiment contains one integer x (1≤x≤1012).
Kindly note, that the input for some experiments will not squeeze into 32-cycle integer type, so you should use something like 64-bit integer type in your programming language.
Output
For each experiment, output on a different line:
"Indeed" in case x is representable as the amount of the 3D shapes of two…
Below is a Boolean expression. Write a block of conditional statements (if/elif/else)
that will cause the phrase "It works!" to be printed if and only if the Boolean
expression evaluates to True. Your code should not use any logical operators
(and/or/not), only conditionals and prints (and pass if necessary). You may assume
that first, second, third, and fourth are variables which have already been defined as
either True or False.
(first or not second) and not (third or fourth)
4. Write a program which to find the grace marks for a student using switch. The
user should enter the class obtained by the student and the number of subjects he
has failed in.
- If the student gets first class and the number of subjects he failed in is greater
than 3, then he does not get any grace. If the number of subjects he failed in is
less than or equal to 3 then the grace is of 5 marks per subject.
- If the student gets second class and the number of subjects he failed in is greater
than 2, then he does not get any grace. If the number of subjects he failed in is
less than or equal to 2 then the grace is of 4 marks per subject.
- If the student gets third class and the number of subjects he failed in is greater
than 1, then he does not get any grace. If the number of subjects he failed in is
equal to 1 then the grace is of 5 marks per subject.
[Marks - 10]
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 3.1 - Suppose goals is a variable of type int. Write an...Ch. 3.1 - Suppose goals and errors are variables of type...Ch. 3.1 - Suppose salary and deductions are variables of...Ch. 3.1 - Suppose speed and visibility are variables of type...Ch. 3.1 - Suppose salary and bonus are variables of type...Ch. 3.1 - Assume that nextWord is a string variable that has...Ch. 3.1 - Prob. 7STQCh. 3.1 - What output is produced by the following code? int...Ch. 3.1 - Suppose you change the code in the previous...Ch. 3.1 - What output is produced by the following code? int...
Ch. 3.2 - Suppose number is a variable of type int that has...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the code in the previous...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the first line of the code in...Ch. 3.3 - Prob. 20STQCh. 3.4 - Suppose you change the order of the drawing...Ch. 3.4 - Prob. 22STQCh. 3.4 - Write code for a JOptionPane dialog that will ask...Ch. 3 - Write a fragment of code that will test whether an...Ch. 3 - Write a fragment of code that will change the...Ch. 3 - Suppose you are writing a program that asks the...Ch. 3 - Prob. 4ECh. 3 - Consider the following fragment of code: What is...Ch. 3 - We would like to assess a service charge for...Ch. 3 - What is the value of each of the following boolean...Ch. 3 - The following code fragment will not compile. Why?...Ch. 3 - Prob. 9ECh. 3 - Consider the boolean expression (2 5) (x 100))....Ch. 3 - Write a switch statement to convert a letter grade...Ch. 3 - Consider the previous question, but include + or ...Ch. 3 - Imagine a program that displays a menu of five...Ch. 3 - Repeat the previous exercise, but define an...Ch. 3 - Repeat Exercise 13, but use a multibranch if-else...Ch. 3 - Given that the int variable temp contains a...Ch. 3 - Write Java statements that create a yes-or-no...Ch. 3 - A number x is divisible by y if the remainder...Ch. 3 - Write a program to read in three nonnegative...Ch. 3 - Write a program that reads three strings from the...Ch. 3 - Write a program that reads a one-line sentence as...Ch. 3 - Write a program that allows the user to convert a...Ch. 3 - Write a program that inputs an integer. If the...Ch. 3 - Prob. 7PCh. 3 - Repeat Programming Project 5 of Chapter 2, but...Ch. 3 - Repeat any of the previous Practice Programs using...Ch. 3 - Suppose that we are working for an online service...Ch. 3 - Write a program that reads a string from the...Ch. 3 - Repeat the calorie-counting program described in...Ch. 3 - Repeat Programming Project 5 but in addition ask...Ch. 3 - Repeat Programming Project 11 in Chapter 2, but if...Ch. 3 - Write a program to play the rock-paper-scissor...Ch. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 8 in Chapter 1, but add...Ch. 3 - Write a program that inputs two strings that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Give the definition for the member function getElement for the class template Pair discussed in the section Syn...
Problem Solving with C++ (10th Edition)
(Sum a Sequence of Integers) Write a program that sums a sequence of integers. Assume that the first integer re...
C How to Program (8th Edition)
The ____________ is always transparent.
Web Development and Design Foundations with HTML5 (8th Edition)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- What is the value of x after the following if-else statement is executed? Rewrite it using a switch statement.arrow_forwardImplement the following questions using Python. Make use of conditional and print statements.Make sure to clearly define your variables and don’t forget to indent your code. The logician Raymond Smulyan describes an island containing two types of people:knights who always tell the truth and knaves who always lie. You visit the island and are approached bytwo natives who speak to you as follows:• A says: B is a knight.• B says: A and I are of opposite type.What are A and B?arrow_forwardPlease don't use answer already posted on other websites. individual MIPS code will leave you feedback!! Thank you! Write a complete MIPS program that prompts the user for a test score and prints out the letter score following the java if-else chain below.arrow_forward
- Write a program that will simulate a simple calculator. There will be four options: add two numbers, subtract two numbers, square root and raise to the power. During the subtraction option, you should not get any negative numbers when subtracting. For example, if we subtract 4 -7 you should get 3 not negative 3. Tip: use the absolute value function. You will use a switch case statement to create the selection mechanism. You will use three predefined functions we have used from chapter 4. The program will loop as long as the user types in Y or y for yes. You must include comments, failure to do so will vastly affect your grade. Once you are done, submit in a .cpp file. You do not need to show me the running program. I will check to see that it runs as l am grading your lab. Select a an option (1-4) from the following 1. Addition of two number 2. subtraction of two positive numbers 3. Square root of a number 4. Raise to the power 1 You chose to add two number Enter the first number 2…arrow_forwardA lecturer intends to separate his students into 2 groups based on their INDEX Numbers, those withodd numbers in group A and EVEN numbers in B. Use if-else statement to implement this.arrow_forwardWrite a program that asks the user for the number of credits earned so far. If the number of credits is 126 or more, set variable status to 1 and print a message indicating the student can graduate. Otherwise, set status to 0 and print a message indicating the student can't graduate yet. Compute the variable status using the shortcut conditional operator we saw in the lecture (don't use if- statement). Then, use the variable status to decide what to print based on the conditional operator like we did in the lecture (don't use if- statement). Enter credits earned so far: 130 Status = 1 Student is ready to graduate. Enter credits earned so far: 100 Status = 0 Student is not ready to graduate. - 3 -arrow_forward
- Rock Paper Scissors Lizard Spock (RPSLS) is an extended version of the classical game of chance Rock Paper Scissors. This game is created by Sam Kass and Karen Bryla. In this game, the players pick one of the following variables: rock, paper, scissors, lizard, spock. The outcome of the game is determined by the rules below specifying which variable defeats the other. If both players choose the same variable, the game ends in a draw. Rules: • scissors cut paper • paper covers rock • rock captures lizard • lizard poisons spock • spock smashes scissors • scissors captures lizard • lizard eats paper • paper disproves spock • spock vaporizes rock • rock crushes scissors In this project, you will write a program that takes two strings representing the choices of the players as inputs and prints the outcome of the RPSLS game. There are three possible outcomes of this game: a tie, a win for player 1 and, a win for player 2. You are supposed to determine the outcome depending on the players'…arrow_forward1. Determine if the expression: (!( a>=b) || !( a==c )) is True or False. Given the value of a is 2, b is 10 and c is -5. 2. Determine if the expression: ! (!(a>b) && ( a==c) || ( a>=b ) ) is True or False. Given the value of a is 2, b is 10 and c is -5. 3. Determine if the expression: !( b>c ) || ( c<5 ) is True or False. Given the value of b is 10 and c is -5.arrow_forwardQuestion 1: As you are a student of university now, you need to ensure your assignments are plagiarism-free. To do this, you decide to design a simple plagiarism checker. Your checker will take 2 strings as input. Then it will compare the 2 strings and check how many words they have in common. Then, print the percentage in common, by calculating: (No. of words in common / (No of words in string 1+ No of words in string 2)) * 100. If the calculated plagiarism is greater than or equal to 30%, print "Plagiarism detected." Otherwise, print "Good job!". Note: you need to compare "words" not individual characters. You can consider that all characters in both inputs will be in only lowercase or uppercase. ========= ======== Sample Input 1: my dog's name is bob bob is my dog's name Sample Output 1: Common percentage: 50% Plagiarism detected. Explanation 1: Length of string1= 5, Length of string2= 5, number of common words= 5. Hence, common percentage= (5/(5+5))*100 = 50 %3D Sample Input 2: my…arrow_forward
- Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". End with a newline. Remember to use println instead of print to output a newline.arrow_forwardWrite a program for an coffee shop. The user will need to choose what type of roast and what type of flavor. You should have at least 3 choices, but you may use more. Use 2 switch statements. 1 for setting the roast and and 1 for setting the flavor and then let your user know what you made for them. Rather than having print statements within your switch statements, you'll want to set values to Strings. You declare and initialize a String variable the same way you do a primitive data type. String coffeeRoast = "dark"; or initialize to an empty String like this String coffeeRoast = ""; Depending on what the user enters, you can assign a value to a String and then use your String variables in your print statement in Javaarrow_forwardWrite pseudocode to show the user how to dance to "Cupid Shuffle." The pseudocode will play the role of the dance instructor, printing the words for each step as the song plays. For this assignment, we will see and use all 3 forms of control structure (sequence, selection, and repetition). The example that follows demonstrates what messages should bedisplayed and when, so remember to use those prompts and outputs verbatim.Example Output of PseudocodeDo you like group/line dances? Well, I do, and my favorite is the CupidShuffle. Please put it on and I’ll show you how to do it!Is the introduction over (y/n)? nDo what you want.Is the introduction over (y/n)? nDo what you want.Is the introduction over (y/n)? yAlright, it’s dance time!Is the song over (y/n)? nAlright, keep on going!Step 1: Step rightStep 2: Step rightStep 3: Step rightStep 4: Step rightStep 5: Step leftStep 6: Step leftStep 7: Step leftStep 8: Step leftStep 9: Kick rightStep 10: Kick leftStep 11: Kick rightStep 12: Kick…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY