Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4.11, Problem 4.26CP
Assume x is an int variable, and rand references a Random object. What does the following statement do?
x = rand.nextInt(9) + 1;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
var type = "swimming";
6.
6.
5.
"wednesday";
var day
var duration = 50;
var laps
var location = "YMCA";
%3D
20;
6.
How many of the variables in the code store strings?
var adventurersName = ["George", " Tim", " Sarah", " Mike", " Edward"];var adventurersKilled = 3;var survivors;var leader = "Captain Thomas King";var numberOfAdventurers = adventurersName.length;
survivors = numberOfAdventurers - adventurersKilled;
console.log("Welcome to The God Among Us\n");console.log("A group of adventurers began their search for the mystical god said to live among us. In charge of the squad was " + leader + " who was famous for his past exploits. Along the way, the group of comrades were attacked by the god's loyal followers. The adventurers fought with bravado and strength under the tutelage of "+ leader + " the followers were defeated but they still suffered great losses. After a headcount of the remaining squad, "+ adventurersKilled +" were found to be dead which left only " + survivors + " remaining survivors.\n");
console.log("Current Statistics :\n");console.log("Total Adventurers = " + numberOfAdventurers);console.log("Total Killed = " +…
(Difficulty Level 3)In the game Flick Fleet, players undertake space combat by flicking a six sided die at other ships.
There is an object called SpaceShip, where ships have a type corresponding to: Destroyer, Cruiser, Bomber, or Fighter. This object has a method called:
get_ship_type(): Returns a string that corresponds to the type of ship (e.g. "Destroyer", "Cruiser", "Bomber" or "Fighter")
Each ship has different regions that have a corresponding number between 1 and 5.
Fighter - Hull (1), Engines (2)
Bomber - Hull (1), Engines (2), Shield Generator (3)
Cruiser - Hull (1), Engines (2), Shield Generator (3), Defense Grid (4)
Destroyer - Hull (1), Engines (2), Shield Generator (3), Defense Grid (4), Engineering (5)
Write a function called laser_attack that takes in as its parameters a ship of type Ship, and an integer value between 1 and 6.
This function should return true if the number passed in the second parameter corresponds to a region possessed by the ship…
Chapter 4 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 4.1 - What will the following program segments display?...Ch. 4.2 - How many times will Hello World be printed in the...Ch. 4.2 - How many times will I love Java programming! be...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.3 - Write an input validation loop that asks the user...Ch. 4.5 - Name the three expressions that appear inside the...Ch. 4.5 - You want to write a for loop that displays I love...Ch. 4.5 - What will the following program segments display?...Ch. 4.5 - Write a for loop that displays your name 10 times.
Ch. 4.5 - Write a for loop that displays all of the odd...Ch. 4.5 - Write a for loop that displays every fifth number,...Ch. 4.6 - Write a for loop that repeats seven times, asking...Ch. 4.6 - In the following program segment, which variable...Ch. 4.6 - Prob. 4.15CPCh. 4.10 - What is the difference between an input file and...Ch. 4.10 - What import statement will you need in a program...Ch. 4.10 - What class do you use to write data to a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - What classes do you use to read data from a file?Ch. 4.10 - Write code that does the following: opens a file...Ch. 4.10 - You are opening an existing file for output. How...Ch. 4.10 - What clause must you write in the header of a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is an int variable, and rand references a...Ch. 4.11 - Assume x is a double variable, and rand references...Ch. 4 - What will the println statement in the following...Ch. 4 - Prob. 2MCCh. 4 - Prob. 3MCCh. 4 - What is each repetition of a loop known as? a....Ch. 4 - This is a variable that controls the number of...Ch. 4 - The while loop is this type of loop. a. pretest b....Ch. 4 - The do-while loop is this type of loop. a. pretest...Ch. 4 - The for loop is this type of loop. a. pretest b....Ch. 4 - This type of loop has no way of ending and repeats...Ch. 4 - This type of loop always executes at least once....Ch. 4 - This expression is executed by the for loop only...Ch. 4 - Prob. 12MCCh. 4 - This is a special value that signals when there...Ch. 4 - To open a file for writing, you use the following...Ch. 4 - To open a file for reading, you use the following...Ch. 4 - Prob. 16MCCh. 4 - This class allows you to use the print and println...Ch. 4 - This class allows you to read a line from a file....Ch. 4 - True or False: The while loop is a pretest loop.Ch. 4 - True or False: The do-while loop is a pretest...Ch. 4 - True or False: The for loop is a posttest loop.Ch. 4 - True or False: It is not necessary to initialize...Ch. 4 - True or False: One limitation of the for loop is...Ch. 4 - True or False: A variable may be defined in the...Ch. 4 - True or False: In a nested loop, the inner loop...Ch. 4 - True or False: To calculate the total number of...Ch. 4 - // This code contains ERRORS! // It adds two...Ch. 4 - Prob. 2FTECh. 4 - // This code contains ERRORS! int choice, num1,...Ch. 4 - Prob. 4FTECh. 4 - Write a while loop that lets the user enter a...Ch. 4 - Write a do-whi1e loop that asks the user to enter...Ch. 4 - Write a for loop that displays the following set...Ch. 4 - Write a loop that asks the user to enter a number....Ch. 4 - Write a for loop that calculates the total of the...Ch. 4 - Write a nested loop that displays 10 rows of #...Ch. 4 - Convert the while loop in the following code to a...Ch. 4 - Convert the do-while loop in the following code to...Ch. 4 - Convert the following while loop to a for loop:...Ch. 4 - Convert the following for loop to a while loop:...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write an input validation loop that asks the user...Ch. 4 - Write nested loops to draw this pattern:Ch. 4 - Write nested loops to draw this pattern: ## # # #...Ch. 4 - Complete the following program so it displays a...Ch. 4 - Complete the following program so it performs the...Ch. 4 - Prob. 17AWCh. 4 - Prob. 18AWCh. 4 - Modify the code you wrote in Question 18 so it...Ch. 4 - Write code that opens a file named NumberList.txt...Ch. 4 - Prob. 1SACh. 4 - Why should you indent the statements in the body...Ch. 4 - Describe the difference between pretest loops and...Ch. 4 - Why are the statements in the body of a loop...Ch. 4 - Describe the difference between the while loop and...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use in situations where you...Ch. 4 - Which loop should you use when you know the number...Ch. 4 - Why is it critical that accumulator variables are...Ch. 4 - What is an infinite loop? Write the code for an...Ch. 4 - Describe a programming problem that would require...Ch. 4 - What does it mean to let the user control a loop?Ch. 4 - What is the advantage of using a sentinel?Ch. 4 - Prob. 14SACh. 4 - Describe a programming problem requiring the use...Ch. 4 - How does a file buffer increase a programs...Ch. 4 - Why should a program close a file when its...Ch. 4 - What is a files read position? Where is the read...Ch. 4 - When writing data to a file, what is the...Ch. 4 - What does the Scanner classs hasNext method return...Ch. 4 - What is a potential error that can occur when a...Ch. 4 - Prob. 22SACh. 4 - How do you open a file so that new data will be...Ch. 4 - Sum of Numbers Write a program that asks the user...Ch. 4 - Distance Traveled The distance a vehicle travels...Ch. 4 - Distance File Modify the program you wrote for...Ch. 4 - Pennies for Pay Write a program that calculates...Ch. 4 - Prob. 5PCCh. 4 - File Letter Counter Write a program that asks the...Ch. 4 - Hotel Occupancy A hotels occupancy rate is...Ch. 4 - Average Rainfall Write a program that uses nested...Ch. 4 - Population Write a program that will predict the...Ch. 4 - Largest and Smallest Write a program with a loop...Ch. 4 - Celsius to Fahrenheit Table Write a program that...Ch. 4 - Bar Chart Write a program that asks the user to...Ch. 4 - File Head Display Write a program that asks the...Ch. 4 - Line Numbers Write a program that asks the user...Ch. 4 - Uppercase File Converter Write a program that asks...Ch. 4 - Budget Analysis Write a program that asks the user...Ch. 4 - Random Number Guessing Game Write a program that...Ch. 4 - Random Number Guessing Game Enhancement Enhance...Ch. 4 - ESP Game Write a program that tests your ESP...Ch. 4 - Square Display Write a program that asks the user...Ch. 4 - Dice Game Write a program that plays a simple dice...Ch. 4 - Prob. 22PCCh. 4 - Personal Web Page Generator Write a program that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Convert each of the following binary representations to its equivalent base ten form: a. 101010 b. 100001 c. 10...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
The two mathematical models for language description are: Recognition Generation These two mathematical models ...
Concepts of Programming Languages (11th Edition)
To what extent will our decisions regarding technology in general, and computer technology in particular, affec...
Computer Science: An Overview (12th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
(Displaying a Square of Any Character) Modify the function created in Exercise 5.19 to form the square out of w...
C How to Program (8th Edition)
Create another ticket machine for tickets of a different price; remember that you have to supply this value whe...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
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
- int a[ 10] = {1,5,3,8,4,2,6,9,7}; int *p; p = &a[2]; p[0] = 10; p[1] = 15; What are the values of a? Select one: O a. {10,15,3,8,4,2,6,9,7} O b. {1,15,10,8,4,2,6,9,7} O c. {1,5,10,15,4,2,6,9,7} O d. {1,10,15,8,4,2,6,9,7}arrow_forwardMake a declaration that sets the object's monthlyPay reference variable.array that can hold decimal numbersarrow_forwardA struct to store a single playing card is as follows: struct card { char suit; char kind; }; The valid suits are 'S', 'H', 'D' and 'C', while the valid kinds are 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', and 'K'. A poker hand can be stored as an array of five struct cards. A flush is a hand that contains five cards, all of the same suit. Write a function that returns 1, if the poker hand passed to it has five cards of the same suit, and 0 otherwise. int isFlush(struct card hand[]); int isFlush(struct card hand[]) {arrow_forward
- void Date: addDays (int n); void Date: subtractDays(in n); The addDays method will add n number of days to the current date that's stored in Object's data. For example, object hold 4/21/2022 as the date and if user of this object calls addDays (10) method, it will add 10 days to 4/21/2022 giving a new date of 5/1/2022. There can be more complicated scenarios if you add a lot of days (for example hundreds of days) due to possible rollover of year and months. You can limit number of days to be added to 100. Just like addDays, subtractDays method will subtract number of days from the current date. Provide implementation of both functions in the class. Also modify your main function as follows:arrow_forwardint grades[100]; int i; for (i=0;i <= 100;i++) { grades[i) = 100; } The above C++ code is the proper way to initialize the grades array, TRUE or FLASE True Falsearrow_forwardUse java See the image for requirementsarrow_forward
- 5. Given the following code AFIFOQueue aQue = new AFIFOQueue (10); AStack astack - new AStack (10); for (int i = 1; i <1e; i++) { aQue. Enqueue (i); } for (int i = 1; i <=5; i++) { astack. Push( aQue.Dequeue ()); } while(!astack . Empty ()) aQue. Enqueue (astack.Pop()); a. After the above code is executed, what is the content of the queue? (Fill in the content of aQue below) Indicate where the front and rear are located. b. What is the content of astack?arrow_forward1 def ticket price(age: int) -> float: ""Return the ticket price for a person with age in years. Seniors 65 and over pay 4.75, kids 12 and under pay 4.25, and everyone else pays 7.50. Precondition: age > e 7 >>> ticket_price(7) 4.25 10 >> ticket_price(21) 11 7.5 12 >>> ticket_price(101) 13 4.75 14 History Submit LOarrow_forwardDesign an application that declares an array of 10 StockTransactionobjects. Prompt the user for data for each object, and then display all the values. Design an application that declares an array of 10 StockTransactionobjects. Prompt the user for data for each object, and then pass the array to a method that determines and displays the two stocks with the highest and lowest price per share.arrow_forward
- 3. Magic Square: Create a class MagicSquare that prompts the user for a positive odd integer size, generates a normal magic square of order size, and prints it with numbers right-justified and aligned in evenly-spaced columns. You may assume the numbers in the square are 3 digits or less (i.e. size ≤31). However, each space-separated column should have a width equal to the largest integer in the magic square. (See example transcripts below.) To generate the magic square, use the following algorithm: Assign 1 to our initial current position: the bottom row, middle column. Place each successive value (up to size * size) in the first of the following positions that is unoccupied: (1) one space down and to the right, or (2) one space up. Positions wrap around the sides, top and bottom, as shown in the following example transcripts (user input underlined): Please enter a positive odd integer: 3 492 357 8 16 Please enter a positive odd integer: 5 11 18 25 2 9 10 12 19 21 3 4 6 13 20 22 23 5…arrow_forwardWhat the following code does? int * foo = new int [5]; if (!foo) { ..}arrow_forwardJAVA ONLYPlease create a code that checks if 'user' favourite game is in the top 3 games. if the game is in the top 3 then it should say: "common favourite game" if else then "uncommon favourite game"code: TOP_3_GAMES = {'', 'CALL OF DUTY', 'LEAGUE OF LEGENDS', 'VALORANT'}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,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY