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
starting out with java from control structures
Starting Out With Java From Control Structures Through Data Structures 6th Edition Tony Gaddis - Solutions
Write a method named times Ten. The method should accept a double argument, and return a double value that is ten times the value of the argument.
In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy: The variables in the formula are as follows: KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s
This statement causes a method to end and sends a value back to the statement that called the method.a. Endb. Sendc. Exitd. Return
Write a method named square that accepts an integer argument and returns the square of that argument.
Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selections: 1. Convert to kilometers2. Convert to inches3. Convert to feet4. Quit the programThe program will convert the distance to kilometers, inches, or feet, depending on
This javadoc tag is used to document a method’s return value.a. @methodreturnb. @retc. @returnd. @returnval
Write a method named get Name that prompts the user to enter his or her first name, and then returns the user’s input.
True or False: You terminate a method header with a semicolon.
The profit from the sale of a stock can be calculated as follows: Profit = ((NS × SP) - SC) - ((NS × PP) + PC)Where NS is the number of shares, PP is the purchase price per share, PC is the purchase commission paid, SP is the sale price per share, and SC is the sale commission paid. If the
True or False: When passing an argument to a method, Java will automatically perform a widening conversion (convert the argument to a higher-ranking data type), if necessary.
True or False: When passing an argument to a method, Java will automatically perform a narrowing conversion (convert the argument to a lower-ranking data type), if necessary.
Suppose you want to deposit a certain amount of money into a savings account, and then leave it alone to draw interest for the next 10 years. At the end of 10 years, you would like to have $10,000 in the account. How much do you need to deposit today to make that happen? You can use the following
True or False: A parameter variable’s scope is the entire program that contains the method in which the parameter is declared.
True or False: When code in a method changes the value of a parameter, it also changes the value of the argument that was passed into the parameter.
You can use the following logic to determine whether a number is even or odd: if ((number % 2) == 0){ // The number is even.}else{ // The number is odd.}Write a program with a method named is Even that accepts an int argument. The method should return true if the argument is even, or
True or False: When an object, such as a String, is passed as an argument, it is actually a reference to the object that is passed.
True or False: The contents of a String object cannot be changed.
True or False: When passing multiple arguments to a method, the order in which the arguments are passed is not important.
Write a program that tests your ESP (extrasensory perception). The program should randomly select the name of a color from the following list of words: Red, Green, Blue, Orange, Yellow To select a word, the program can generate a random number. For example, if the number is 0, the
True or False: No two methods in the same program can have a local variable with the same name.
True or False: It is possible for one method to access a local variable that is declared in another method.
True or False: You must have a return statement in a value-returning method.
What does an object use its fields for?
This is a collection of programming statements that specify the fields and methods that a particular type of object may have.a. Classb. Methodc. Parameterd. Instance
Find the error in the following class: public class MyClass{ private int x; private double y; public void MyClass(int a, double b) { x = a; y = b; }}
What is the difference between a class and an instance of a class?
Write a class named Employee that has the following fields: • Name. The name field references a String object that holds the employee’s name.• IdNumber. The idNumber is an int variable that holds the employee’s ID number.• Department. The department field references a String object
What are an object’s methods?
A class is analogous to a(n) __________.a. Houseb. Blueprintc. Drafting tabled. Architect
Assume that the following method is a member of a class. Find the error.public void total(int value1, value2, value3){ return value1 + value2 + value3;}
A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses?
How is a class like a blueprint?
An object is a(n) __________.a. Blueprintb. Primitive data typec. Variabled. Instance of a class
The following statement attempts to create a Rectangle object. Find the error. Rectangle box = new Rectangle;
Consider the following class declaration: public class Square{ private double sideLength; public double getArea() { return sideLength * sideLength; } public double getSideLength() { return sideLength; }}a. Write a no-arg constructor for this class.
What is an accessor method? What is a mutator method?
Design a class that holds the following personal data: name, address, age, and phone number. Write appropriate accessor and mutator methods. Demonstrate the class by writing a program that creates three instances of it. One instance should hold your information, and the other two should hold your
You have programs that create Scanner, Random, and PrintWriter objects. Where are the Scanner, Random, and PrintWriter classes?
This is a class member that holds data.a. Methodb. Instancec. Fieldd. Constructor
Find the error in the following class: public class TwoValues{ private int x, y; public TwoValues() { x = 0; } public TwoValues() { x = 0; y = 0; }}
Look at the following description of a problem domain:The bank offers the following types of accounts to its customers: savings accounts, checking accounts, and money market accounts. Customers are allowed to deposit money into an account (thereby increasing its balance), withdraw money from an
Is it a good idea to make fields private? Why or why not?
What does the new operator do?
This key word causes an object to be created in memory.a. Createb. Newc. Objectd. Construct
Find the error in the following class: public class FindTheError{ public int square(int number) { return number * number; } public double square(int number) { return number * number; }}
What values do reference variables hold?
This is a method that gets a value from a class’s field, but does not change it.a. Accessorb. Constructorc. Voidd. Mutator
What is the purpose of the new key word?
Design a TestScores class that has fields to hold three test scores. The class should have a constructor, accessor and mutator methods for the test score fields, and a method that returns the average of the test scores. Demonstrate the class by writing a separate program that creates an instance of
How is the relationship between an object and a reference variable similar to a kite and a spool of string?
This is a method that stores a value in a field or in some other way changes the value of a field.a. Accessorb. Constructorc. Voidd. Mutator
Assume a program named MailList.java is stored in the Data Base folder on your hard drive. The program creates objects of the Customer and Account classes. Describe the steps that the compiler goes through in locating and compiling the Customer and Account classes.
Write a Circle class that has the following fields: • Radius: a double• PI: a final double initialized with the value 3.14159The class should have the following methods: • Constructor. Accepts the radius of the circle as an argument.• Constructor. A no-arg constructor that sets
You hear someone make the following comment: “A blueprint is a design for a house. A carpenter can use the blueprint to build the house. If the carpenter wishes, he or she can build several identical houses from the same blueprint.” Think of this as a metaphor for classes and objects. Does the
When the value of an item is dependent on other data, and that item is not updated when the other data is changed, what has the value become?a. Bitterb. Stalec. Asynchronousd. Moldy
Why are constructors useful for performing “start-up” operations?
In this chapter we used the metaphor of a kite attached to a spool of string to describe the relationship between an object and a reference variable. In this metaphor, does the kite represent an object, or a reference variable?
This is a method that is automatically called when an instance of a class is created.a. Accessorb. Constructorc. Voidd. Mutator
Under what circumstances does Java automatically provide a default constructor for a class?
When a variable is said to reference an object, what is actually stored in the variable?
When a local variable has the same name as a field, the local variable’s name does this to the field’s name.a. Shadowsb. Complementsc. Deletesd. Merges with
What do you call a constructor that accepts no arguments?
For this assignment, you will write a program that lets the user play against the computer in a variation of the popular blackjack card game. In this variation of the game, two six-sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computer’s hidden total
A string literal, such as "Joe", causes what type of object to be created?
This is automatically provided for a class if you do not write one yourself.a. Accessor methodb. Default instancec. Default constructord. Variable declaration
When the same name is used for two or more methods in the same class, how does Java tell them apart?
The following table lists the freezing and boiling points of several substances. Design a class that stores a temperature in a temperature field and has the appropriate accessor and mutator methods for the field. In addition to appropriate constructors, the class should have the following
Look at the UML diagram in Figure 6-17 and answer the following questions:a) What is the name of the class?b) What are the fields?c) What are the methods?d) What are the private members?e) What are the public members?Data in Figure 6-17 Car - make yearModel - + setMake() + set YearModel() +
Two or more methods in a class may have the same name, as long as this is different.a. Their return valuesb. Their access specifierc. Their parameter listsd. Their memory address
Assume that limo is a variable that references an instance of the class shown in Figure 6-17. Write a statement that calls set Make and passes the argument "Cadillac".Figure 6-17. Car - make - yearModel setMake() + set YearModel() + getMake() getYearModel()
How does method overloading improve the usefulness of a class?
The process of matching a method call with the correct method is known as __________.a. Matchingb. Bindingc. Linkingd. Connecting
What does the key word new do?
A class’s responsibilities are __________.a. The objects created from the classb. Things the class knowsc. Actions the class performsd. Both b and c
Write a program that uses the Die class that was presented in this chapter to play a simple dice game between the computer and the user. The program should create two instances of the Die class (each a 6-sided die). One Die object is the computer’s die, and the other Die object is the user’s
What is an accessor? What is a mutator?
True or False: The new operator creates an instance of a class.
On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are as follows: • Pocket 0 is green.• For pockets 1 through 10, the odd numbered pockets are red and the even numbered pockets are black.• For pockets 11 through 18, the odd numbered pockets are black
What is a stale data item?
Write a class named Coin. The Coin class should have the following field: • A String named sideUp. The sideUp field will hold either “heads” or “tails” indicating the side of the coin that is facing up. the Coin class should have the following methods:• A no-arg constructor that
Describe a programming problem that would require the use of an accumulator.
Write the header for a method named light Years. The method should return a long and have one long parameter variable: miles.
Write the header for a method named distance. The method should return a double and have two double parameter variables: rate and time.
Write the header for a method named days. The method should return an int and have three int parameter variables: years, months, and weeks.
Look at the following method header. What type of value does the method return? Public static double getValue(int a, float b, String c)
In Java, method arguments are passed by value. What does this mean?
Suppose a method named show Values accepts two int arguments. Which of the following method headers is written correctly?a) Public static void showValues()b) Public static void showValues(int num1, num2)c) Public static void showValues(num1, num2)d) Public static void showValues(int num1, int num2)
What is the difference between an argument and a parameter?
Write a void method that displays your full name. The method should be named my Name.
Is the following line of code a method header or a method call? Public static void calcTotal()
Is the following line of code a method header or a method call? CalcTotal();
True or False: To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.
Assume x is an int variable, and rand references a Random object. What does the following statement do?x = rand.nextInt(100);
True or False: A variable may be defined in the initialization expression of the for loop.
Assume x is an int variable, and rand references a Random object. What does the following statement do?x = rand.nextInt();
Write a program that plays a simple dice game between the computer and the user. When the program runs, a loop should repeat 10 times. Each iteration of the loop should do the following: • Generate a random integer in the range of 1 through 6. This is the value of the computer’s die.•
This type of method does not return a value. a. Nullb. Voidc. Emptyd. Anonymous
What is the difference between a void method and a value-returning method?
Assume x is a double variable, and rand references a Random object. What does the following statement do? x = rand.nextDouble();
Assume x is an int variable, and rand references a Random object. What does the following statement do? x = rand.nextInt(9) + 1;
Showing 800 - 900
of 1251
1
2
3
4
5
6
7
8
9
10
11
12
13
Step by Step Answers