Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 2.1, Problem 8SC
Explanation of Solution
Volume.java
//Class volume
public class Volume
//Main method
{
public static void main(String[] args)
{
//variable declaration
double cansPerPack = 6;
//constant declaration
final double CAN_VOLUME = 0.355; // Liters in a 12-ounce can
//calculate total volume
double totalVolume = cansPerPack * CAN_VOLUME;
//display the resultant
System.out.print("A six-pack of 12-ounce cans contains ");
System.out.print(totalVolume);
System.out.println(" liters.");
//constant declaration
final double BOTTLE_VOLUME = 2; // Two-liter bottle
//calculate total volume
totalVolume = totalVolume + BOTTLE_VOLUME;
//display the resultant
System.out.print("A six-pack and a two-liter bottle contain ");
System...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
4. Step through each line of the JavaScript program below. (This is the program from Figure 17.1.) Write down the value of each variable as you walk through it. Use an order of a 16 oz. latte with 2 shot.
var price;
var taxRate = 0.088;
if (drink == "espresso")
price = 1.40;
if (drink == "latte" || drink == "cappuccino") {
if (ounce == 8)
price = 1.95;
if (ounce == 12)
price = 2.35;
if (ounce == 16)
price = 2.75;
}
if (drink == "Americano")
price = 1.20 + .30 * (ounce/8);
price = price + (shots - 1) * .50;
price = price + price * taxRate
Can you please help write this with java level
The Nim game. Write a program for a two-player version of the game Nim: a human player will play against the computer. The game is simple: players take turns removing from 1 to 4 sticks from a pile of 13 sticks; the player who picks up the last stick wins the game.
Here’s some pseudocode for the Nim game.
Start by initializing some variables that will allow you to keep track of the state of the game:
One variable should record how many sticks there are left in the pile; initially, this variable must be initialized to 13.
There are two players in the game, who take turns. To remember who’s turn is next, use a variable with two states (= values). Say the variable is 1 if the human player is next, and it is 2, if the computer’s turn is next. Pick randomly the player who should start the game.
Then, start the main loop of the game: the game should continue for as long as there still are sticks (at least one) to pick. In each repetition of the game loop, one player will play their turn:…
Chapter 2 Solutions
Big Java Late Objects
Ch. 2.1 - Declare a variable suitable for holding the number...Ch. 2.1 - What is wrong with the following variable...Ch. 2.1 - Declare and initialize two variables, unitPrice...Ch. 2.1 - Prob. 4SCCh. 2.1 - Some drinks are sold in four-packs instead of...Ch. 2.1 - Prob. 6SCCh. 2.1 - Prob. 7SCCh. 2.1 - Prob. 8SCCh. 2.1 - How would you explain assignment using the parking...Ch. 2.2 - A bank account earns interest once per year. In...
Ch. 2.2 - In Java, how do you compute the side length of a...Ch. 2.2 - The volume of a sphere is given by V=43r3 If the...Ch. 2.2 - Prob. 13SCCh. 2.2 - Prob. 14SCCh. 2.3 - Write statements to prompt for and read the users...Ch. 2.3 - What is wrong with the following statement...Ch. 2.3 - Prob. 17SCCh. 2.3 - What is problematic about the following statement...Ch. 2.3 - What is the output of the following statement...Ch. 2.3 - Using the printf method, print the values of the...Ch. 2.4 - Prob. 21SCCh. 2.4 - Suppose the architect specifies a pattern with...Ch. 2.4 - A robot needs to tile a floor with alternating...Ch. 2.4 - For a particular car, repair and maintenance costs...Ch. 2.4 - The shape of a bottle is approximated by two...Ch. 2.5 - What is the length of the string "Java Program"?Ch. 2.5 - Consider this string variable. String str = "Java...Ch. 2.5 - Use string concatenation to turn the string...Ch. 2.5 - Prob. 29SCCh. 2.5 - Prob. 30SCCh. 2 - Write declarations for storing the following...Ch. 2 - What is the value of mystery after this sequence...Ch. 2 - What is wrong with the following sequence of...Ch. 2 - Write the following mathematical expressions in...Ch. 2 - Write the following Java expressions in...Ch. 2 - What are the values of the following expressions?...Ch. 2 - What are the values of the following expressions,...Ch. 2 - What are the values of the following expressions?...Ch. 2 - Assuming that a and b are variables of type int,...Ch. 2 - Suppose direction is an integer angle between 0...Ch. 2 - Find at least five compile-time errors in the...Ch. 2 - Find three run-time errors in the following...Ch. 2 - Consider the following code segment. double...Ch. 2 - Explain the differences between 2, 2.0, 2, 2, and...Ch. 2 - Explain what each of the following program...Ch. 2 - Write pseudocode for a program that reads a word...Ch. 2 - Write pseudocode for a program that reads a name...Ch. 2 - Write pseudocode for a program that computes the...Ch. 2 - Modify the pseudocode for the program in How To...Ch. 2 - Prob. 20RECh. 2 - You are cutting off a piece of pie like this,...Ch. 2 - The following pseudocode describes how to obtain...Ch. 2 - Suppose you are given a string str and two...Ch. 2 - Prob. 24RECh. 2 - For each of the following computations in Java,...Ch. 2 - Prob. 26RECh. 2 - This chapter contains a number of recommendations...Ch. 2 - Write a program that displays the dimensions of a...Ch. 2 - Write a program that computes and displays the...Ch. 2 - Write a program that reads a number and displays...Ch. 2 - Write a program that prompts the user for two...Ch. 2 - Enhance the output of Exercise E2.4 so that the...Ch. 2 - Write a program that prompts the user for a...Ch. 2 - Write a program that prompts the user for a radius...Ch. 2 - Write a program that asks the user for the lengths...Ch. 2 - Improve the program discussed in How To 2.1 to...Ch. 2 - Write a program that helps a person decide whether...Ch. 2 - Write a program that asks the user to input The...Ch. 2 - File names and extensions. Write a program that...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Write a program that reads a number between 1,000...Ch. 2 - Printing a grid. Write a program that prints the...Ch. 2 - Write a program that reads in an integer and...Ch. 2 - Write a program that reads two times in military...Ch. 2 - Writing large letters. A large letter H can be...Ch. 2 - Write a program that transforms numbers 1, 2, 3, ,...Ch. 2 - Write a program that prints a Christmas tree:...Ch. 2 - Easter Sunday is the first Sunday after the first...Ch. 2 - In this project, you will perform calculations...Ch. 2 - The following pseudocode describes how a bookstore...Ch. 2 - The following pseudocode describes how to turn a...Ch. 2 - The following pseudocode describes how to extract...Ch. 2 - Giving change. Implement a program that directs a...Ch. 2 - An online bank wants you to create a program that...Ch. 2 - A video club wants to reward its best members with...Ch. 2 - Consider the following circuit. Write a program...Ch. 2 - The dew point temperature Td can be calculated...Ch. 2 - The pipe clip temperature sensors shown here are...Ch. 2 - Prob. 12PPCh. 2 - Consider the following tuning circuit connected to...Ch. 2 - According to the Coulomb force law, the electric...
Knowledge Booster
Similar questions
- Q1: The local Driver's License Office has asked you to write a program that grades the writ- ten portion of the driver's license exam. The exam has 20 multiple choice questions. Here are the correct answers: 1. A 2. D 3. B 4. B 5. C 6. B 7. A 8. B 9. C 10. D 11. A 12. C 13. D 14. B 15. D 16. C 17. C 18. A 19. D 20. B Your program should store the correct answers shown above in an array. It should ask the user to enter the student's answers for each of the 20 questions, and the answers should be stored in another array. After the student's answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. Input Validation: Only accept the letters A, B, C, or…arrow_forward"Type" doesn't specify a variable. Variables have data types. How can this idea explain any variable?arrow_forwardProblem: An online grocery store sells items on a web page. A user adds items to a basket and he clicks on the submit button when he completes. The store sells food and electronic items. The electronic items require VAT payment of 15 percentage of their prices. There are packed and lose food. The lose food is measured in weights. User specifies the weight amount or the quantity in his selection of items depending on its type. The price is computed as the product of the price per item or the price per weight and the weight or quantity are given by the user. Write an application that reads a user basket list and produces the bill receipt. Check the given samples of input/output in the figures below. The bill receipt contains the list of item details in decreasing order according to the price computed for each item. Use the selection sort' to sort the items in the list and do not use java given sort method. Selection sort is an algorithm used to arrange elements in a list. It selects the…arrow_forward
- SHOW THE CODES IN ANY JAVA APPLICATION LIKE JCRATOR AND ECLIPSE. OUTPUT SHOULD BE LIKE IN THE TABLEarrow_forwardStep through each line of the following JavaScript program. Write down the value of each variable as you walk through it. Use an order of a 16 oz. latte with two shots.arrow_forwardWrite an application that determines the value of the coins in a jarand prints the total in dollars and cents. Read integer values thatrepresent the number of quarters, dimes, nickels, and penniesarrow_forward
- You are asked to write a Java program making a discount promotion chart for a souvenir store in Niagaraon-the-Lake, Ontario. Your discount chart should have three columns. The first column lists the items’ original price tag in CAD, and the second & third column provide the discounted prices after tax respectively in CAD and USD. All original price tags of the store are ended in .49 or .99. Your program should receive the maximum and minimum price tags, discount percentage (should be applied to original price tag), and CAD to USD exchange rate via keyboard entry. Develop you program based on the below sample results. Note that your program should check if the entries are valid values. In case of an invalid entry the program should ask the user to enter a value again as shown in the sample result. for rounding to 0.5 the round method of Math class in java.lang package might be helpful. As you may remember you do not need to import java.lang. you are only allowed to import the…arrow_forwardPreviously in this chapter you saw the card_dealer.py program that simulates cards being dealtfrom a deck. Enhance the program so it simulates a simplified version of the game of Blackjackbetween two virtual players. The cards have the following values:Numeric cards are assigned the value they have printed on them. For example, the value ofthe 2 of spades is 2, and the value of the 5 of diamonds is 5.Jacks, queens, and kings are valued at 10.Aces are valued at 1 or 11, depending on the player’s choice.The program should deal cards to each player until one player’s hand is worth more than 21points. When that happens, the other player is the winner. (It is possible that both players’ handswill simultaneously exceed 21 points, in which case neither player wins.) The program shouldrepeat until all the cards have been dealt from the deck.If a player is dealt an ace, the program should decide the value of the card according to thefollowing rule: The ace will be worth 11 points, unless that…arrow_forwardYou are a Chemistry major who has to create a program for first time chemistry lab users. The Erlenmeyer flask contains a nitric acid solution. When the student presses a button, 0.5 mL of NaOH solution can be added to a buret, which is set up over the Erlenmeyer flask. An indicator is added to the solution being titrated. The indicator is a substance that changes to blue when the reaction is complete (endpoint). You determine the amount of mixture that will cause this reaction to occur. Create a titration simulator that will allow a student to add up to 18 mL of titrant. Notify the student when the mixture turns blue. In Python please :)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,