New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
introduction to programming with java a problem solving approach
Introduction To Programming With Java A Problem Solving Approach 3rd International Edition John Dean - Solutions
Write the shortest Java statement that increments count by 1.
Write the shortest Java statement that decrements count by 3.
Write the shortest Java statement that multiplies number by (number - 1) and leaves the product in number.
What does it mean if a variable contains garbage?
In a trace listing, what are line numbers for?
Write a Java statement that assigns the double variable, myDouble, to the int variable, myInteger.
What’s wrong with the following initialization?
If we try to put a quotation mark (") somewhere inside a string literal to be printed, the computer interprets the quotation mark as the end of the string literal. How can we overcome this problem and force the computer to recognize the quotation mark as something we want to print?
When describing the location of a file or directory, computers directory paths. In Windows environments, use the backslash character (\) to separate directories and files within a directory path. If you need to print a directory path within a Java program, how should you write the backslash
The type name for a primitive type is not capitalized, but the type name for a reference type is usually capitalized. (T / F)
List the primitive types this chapter describes, in the following categories:a) Integer numbersb) Floating-point numbersc) Individual text characters and special symbols
What two operators perform string concatenation, and what’s the difference between these operators?
What method can be used to retrieve a character at a specified position within a string?
What two methods can be used to compare strings for equality?
What is whitespace?
Write the statement that you must put before any other code to tell the compiler that you will be using the Scanner class.
Write the statement that creates a connection between your program and the computer’s keyboard.
Write a statement that inputs a line of text from the keyboard and puts it into a variable named line.
Write a statement that inputs a double number from the keyboard and puts it into a variable named number.
What are Java’s two Boolean values?
Provide a list of Java’s comparison operators.
Provide an if statement that implements this logic:When the water temperature is less than 120 °F, turn the heater on by assigning the value “on” to a heater string variable. When the water temperature is greater than 140 °F, turn the heater off by assigning the value “off” to a heater
What is the maximum number of “else if” blocks allowed in an if statement that uses the “if, else if” form?
The relational and equality operators have higher precedence than the arithmetic operators. (T / F)
Correct the following code fragment so that it executes and outputs. OK if a, an int variable, is equal to either 2 or 3: if (a = 2 || 3) { } print("OK ");
What Java operator reverses the truth or falsity of a condition?
Suppose a switch statement’s controlling expression is (stdIn.next().charAt(0)), and you want a user input of ‘Q’ or ‘q’ to execute the same statement, which is: System.out.println("quitting"); Write the code fragment for a case clause that does that.
Write the header for a switch expression in which each case clause responds to an int variable named dayOfWeek and returns a value that’s assigned to a variable named avgTemp.
Suppose you have an ‘if, else” form of the if statement. If you want to replace it with a switch construct, can you use the if statement’s condition as the controlling expression in the switch header?
What must a while loop condition evaluate to?
Suppose you want to use the user-query technique to terminate a simple while loop. Where should you put the user query?
What’s wrong with this code fragment? int x = 3; do { X 2; } while (X >= 0) (x
If you know ahead of time the exact number of iterations through a loop, what type of loop should you use?
Implement the following as a for loop: int age = 0; while (age < 5) { System.out.println("Happy Birthday# age age + 1; = } // end while 11 + age);
If you know that a loop should be executed at least one time, what type of loop is most appropriate?
Construct a template for a for loop inside a for loop. Use i for the outer for loop’s index variable and use j for the inner for loop’s index variable.
Assume that the variable OK has been declared to be of type boolean. Replace the following code with an equivalent for loop: OK = false; while (!OK) { }
Given the logical expression:Replace it with an equivalent logical expression that is completely devoid of “not” operations. !(la || lb)
Whenever you cook eggs for breakfast, you must decide how many eggs to use. You like to use this rule of thumb—use approximately one and a half eggs per person. Of course, you can’t use half an egg, so, you round up. For example, if you have three people who want to eat, you use five eggs.Write
Given this code fragment:Trace the code using either the short form or the long form. To help you get started, here’s the trace setup. The third column is for switch’s controlling expression. For the short form, you won’t need the line# column.The following main method is supposed to print
Identify the bug. Although not required, to test your answer, you are encouraged to enter your corrected code in a program and run it. public static void main(String[] args) { int count = 0; int sum = 0; int product 1; do { count++; sum + count; product count; } while (count
Given this main method:Trace the code using the long form. To help you get started, here’s the trace setup.The third column is for the switch expression’s controlling expression. When evaluating a switch expression, under line# provide both the line where the expression is evaluated and the
Given the below program skeleton, insert code where it says such that the program prints the sum of odd integers from 1 to num. You are not required to perform input validation. public class SumOdd Ints ( public static void main(String[] args) { Scanner stdIn - new Scanner(System.in); int num, sum;
Given this main method:Trace the code using either the short form or the long form. To help you get started, here’s the trace setup. For the short form, you won’t need the line# column. 123 2 public static void main(String[] args) ( for (int start=8; start>1; start-=4) { 3 4 5 6 7 8 9 10 } 11 }
Given the following code fragment, and assuming that n is an int, write an expression for the total number of lines of output as a function of n.What is the smallest value of n that produces some output, and how many lines does this produce? for (int j-0; j 0; k--) { } System.out.println("***");
Given this main method:Trace the code using either the short form or the long form. To help you get started, here’s the trace setup. For the short form, you won’t need the line# column. 1 2 23 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public static void main(String[] args) { boolean loves = false;
Consider the TestScores program below.In the above program, note how the following lines appear above the loop and also at the bottom of the loop:Modify the program so it avoids having those lines appear twice but keeps the same functionality. For your modification, you are required to use a
Consider the following code fragment. Without changing the loop type, modify the code to prevent output when the input equals the sentinel value of zero. Scanner stdIn = new Scanner(System.in); int x; do { x stdIn.nextInt (); System.out.println("negative " + (-X)); 3 while (x != 0);
Here’s a brain teaser that uses Boolean logic:You’re traveling on a road, and you come to a fork in the road. You know that one path leads to a pot of gold and the other path leads to a dragon. There are two elves at the fork, both of whom know the way to the pot of gold. You know that one elf
Given these declarations:Provide a statement that assigns the length of a circle’s perimeter to the perimeter variable. Use the diameter variable. double diameter = 3.0; double perimeter;
What is the name of the class that contains the abs, min, and round methods?a) Arithmeticb) Mathc) Number.
Provide a statement that assigns positive infinity into a double variable named num.
Provide a statement that converts a string variable named s to a long and assigns the result to a long variable named num.
Provide a statement that converts an int variable named num to a string and assigns the result to a String variable named numStr. Use a wrapper class method.
What does the following code fragment print? System.out.println(Character.isDigit('#')); System.out.println(Character.isWhitespace('\t')); System.out.println(Character. to LowerCase('B'));
Given this declaration:Write a Java statement that finds the index of the letter ‘G’ and prints everything in snyder from that point on. In other words, it prints Go light. String snyder = "Stick together. Learn the flowers. Go light.";
Write a format string that handles the display of three data items in three columns. The first column should be 20 spaces wide, and it should print a left-aligned string. The second column should be 10 spaces wide, and it should print a right-aligned integer. The third column should be 16 spaces
Provide a format specifier that handles the display of a floating-point data item. It should print a rounded version of the data item with no decimal places. It should insert grouping separators, and it should use parentheses if the number is negative.
Write a Java statement that prints a random number for the total number of dots on a roll of a pair of dice.
Write a program that prints five random boolean values with the seed, 123L. Then display those values.
Suppose you own a bond that will pay a future value based on a given annual interest rate and the number of years in the future. Here’s the formula for determining the present value (what you can sell the bond for now):Provide a Java assignment statement that calculates the present value (using
Dropping a pebble in a pond or striking the center of a large drum creates circular waves described by the zero-order Bessel Function, denoted, J0(r), where r is a normalized radial distance. At large normalized radial distances, the zero-order Bessel Function approaches the approximation:Use Math
Write a main method that asks the user for a number between 0 and 1 and prints the arcsine, arccos, and arctan in degrees for the given number. Sample session: Enter number between 0 and 1: 0.5 arcsine (.5)= 30.000000000000004 degrees arccos (.5) = 60.00000000000001 arctan(.5) 26.56505117707799
Imagine that you’re standing 100 meters from the base of a flagpole and the ground is flat. The flagpole is 30 meters tall. Provide a statement that prints the distance from your feet to the top of the flagpole. Use the Math class’s hypot method, described on the Java API website.
The speed of light in a vacuum is 299,792,458 meters/second. That’s an exact number—not just an approximation—because the definition of a meter is based on the speed of light. Because it’s an exact number you can store it in an integer. An int has 32 bits and a long has 64 bits. To know
In the following program skeleton, replace the line with appropriate code. The resulting program should display the initial list of songs, prompt the user for a string of text to be replaced and then prompt for new text to replace it. After replacing every instance of the targeted text, it should
In the following program skeleton, replace the code here> line with appropriate code. The resulting program should prompt the user for some identifying text, like the artist’s name. Then it should display all lines in the songs string that contain that identifying text. Study the sample session.
Given the below program skeleton. Replace the code here> items with appropriate code so that the program produces the output shown below. Try to mimic the output’s format precisely. public class Car Inventory Report ( public static void main(String[] C args) final String HEADING_FMT_STR : final
Given values for previousArrivalTime and averageInterArrivalTime, and assuming a continuous exponential distribution, provide Java code that uses Math.Random to generate a simulated value for nextArrivalTime.
A class is an instance of an object. (T / F)
How many objects may there be within a single class?
A class’s instance variables must be declared outside of all _______, and all instance variable declarations should be located at the _______.
Methods accessible from outside a class are public, but instance variables (even those that an outsider may need to change or read) are usually private. Why?
Where does main go—in the driver class or in one of the driven classes?
When a program has both driver and driven classes, where should most of the program code reside?
How do you retrieve a private instance variable’s value from within a main method?
A reference variable holds the ________ of an object.
An instance method might contain a statement like this.weight = 1.0; but if that method’s class currently has five instantiated objects, there are five different variables called weight. How can we determine which one is getting the new value?
What are the default values for int, double, and boolean for an object’s instance variables?
In the Mouse program of Figures 6.4 and 6.5, what is the persistence of gus’s age variable?Figures 6.4Figures 6.5 /**************** * Mouse.java * Dean & Dean * * This class models a mouse for a growth simulation program. ****************** public class Mouse {
After a program is written, a UML class diagram provides a brief outline of each class in the program. It helps other people see what methods are available and what arguments they need. Give some reasons why it might be helpful to have an already created class diagram in front of you while you are
Assume the main method in Mouse2Driver had started more simply with only Mouse mickey; What would be the value of mickey immediately after this statement?
Usually, the use of multiple return statements leads to code that is more understandable. (T / F)
How is a method parameter like a local variable, and how do they differ?
What is the relationship and difference between a method argument and a method parameter?
What is the standard prefix for an accessor method?
What is the standard prefix for a mutator method?
What is the standard prefix for a Boolean method?
Identify two general ways to reduce the size of the error in a simulation. For a given accuracy, which way is more efficient?
Suppose you are asked to model animals using an OOP program. For each of the following animal-related entities, select one of the following object-oriented programming constructs: class, object, instance variable, or method.a) Whether the animal has a backboneb) Animal weightc) An individual
What are the two kinds of static members?
Given the following Cow class. Provide a complete CowDriver class that calls the emit method. public class Cow ( public void emit() System.out.println("The cow says \"Moo!\""); } // end main 3 // end Cow
Wrapper objects: The wrapper classes also provide you with the ability to instantiate objects that are wrapped versions of primitive variables. For example, to create a wrapped version of the double number x, you can do this:This creates an object of type Double, which is a wrapped version of the
Suppose you own some land and would like to build three houses on it.a) Implement a House class with instance variables floorArea (a double) and salePrice (another double) and these methods:i. A build method with a double floorArea parameter. This method should assign its parameter to the
Given this Computer design program:Use the following trace setup to trace the Computer program. Note that we have used abbreviations to keep the trace setup’s width as small as possible. Don’t forget to specify default and initial values, even if they don’t affect the final result. 1 2 3
What does UML mean? That is, what words do its initials represent?
Construct UML class diagrams for the Computer and ComputerDriver classes in Exercise 6.Exercise 6Given this Computer design program:Use the following trace setup to trace the Computer program. Note that we have used abbreviations to keep the trace setup’s width as small as possible. Don’t
When a method’s execution terminates, its local variable values become garbage. (T / F)
The diagram below shows Mouse2 program methods, with their parameters and local variables indented, and the one instantiated object, with its instance variables indented. Your task is to construct a time line for each method, local variable or parameter, object, and instance variable. Each time
Given the following Earth class and skeleton for an EarthDriver class, provide a futureTemperature method that receives two parameters, years and annualGreenhouseGases. The years parameter holds the number of years into the future that the user is interested in. The annualGreenhouseGases parameter
Showing 400 - 500
of 717
1
2
3
4
5
6
7
8
Step by Step Answers