RSS

A guide to programming in java chapter 4 critical thinking

13 Oct

 

A guide to programming in java chapter 4 critical thinking

  1. a) List four legal identifier names

 

 

. b) List four illegal identifier names and explain why each is illegal.

 

 

  1. a) In two statements, declare a variable named numBeads and assign it the value 5.

 

 

 

  1. b) In one statement, declare a variable named numBeads and assign it the value 5.

 

 

 

  1. a) What is the final value of yourNumber after the last statement executes?

intmyNumber = 5;

intyourNumber = 4;

myNumber = yourNumber * 2;

yourNumber = myNumber + 5;

 

 

 

  1. b) What is the final value of yourNumber after the last statement executes?

intmyNumber;

intyourNumber = 4;

myNumber = yourNumber + 7;

yourNumber = myNumber;

 

  1. Determine the appropriate data type for each of the following values:
  2. a) the number of basketballs in a department store.
  3. b) the price of a basketball.
  4. c) the number of players on a basketball team.
  5. d) the average age of the players on a basketball team.
  6. e) whether a basketball player has received a jersey or not.
  7. f) the first initial of a basketball player’s first name.

 

  1. a) What is the difference between a primitive data type and an abstract data type?

 

  1. b) What is the difference between a class and an object?

 

  1. Assume a class named Team defines a sports team.
  2. a) Methods define the actions in a class and typically include action words in their name. For example, getTeamName is a method name that returns the name of the team. List three more possible method names for the Team class

 

  1. b) List three possible object names of type Team..

 

  1. The java.util package contains a class named R ando m. Write a statement that makes the Random class accessible to an application.

 

  1. What is the value of each of the following expressions?
  2. a) 5 + 7 – 3
  3. b) 10 * 2 – 3
  4. c) 10 * (2 – 3)
  5. d) 8 – 3 * 2
  6. e) 10 / 5 * 4
  7. f) 10 / 2 + 3
  8. g) 6 % 3 + 4
  9. h) 12 % 5 * 3
  10. i) 12 % (5 * 3)

 

  1. What is the result of the following expression when x is 2005? When x is 1776? When x is 39?

 

(x/10)%10

 

  1. Write each equation as a valid Java expression: a) (geometry) b) (business) c) (geometry) d) (geometry) e) (algebra) f) (physics) g) (business)

A

B

C

D

E

F

G

 

  1. Using the following declarations, rewrite the statements to include the appropriate type casting, rounding where necessary. If type casting is not necessary, explain why: int j = 5; double k = 1.6; int y; double z; a) y = j * k; b) z = j * k

 

  1. a) y = j * k;
  2. b) z = j * k;
  3. c) z = k * k;
  4. d) j = k; e) k = j;
  5. f) y = j + 3;

 

  1. Compare the way the / and % operators perform to the effects of type casting.

 

  1. Rewrite the statements below using the appropriate assignment operator: a) total = total + 10; b) numStones = numStones – 1; c) days = days % 24; d) price = price * 1.2;

 

  1. Determine if each of the following are better represented by a variable or a constant and then write declarations using appropriate data types and descriptive identifiers: a) the number of votes received by an election candidate b) the percentage of votes won by a candidate c) the first, middle, and last initials of an election candidate d) the year of the election d) Values typed by the user cannot be used in an application. e) The Scanner class is part of a Java package. f) The + operator has higher precedence than the – operator. g) The – operator has lower precedence than the % operator. h) byte is a keyword. i) The identifiers apple and Apple are considered the same in Java. j) Errors that violate the rules of Java are called semantic errors

 

  1. Determine if each of the following segments of code contain a syntax error, logic error, or runtime error. Explain. a) duble salary; b) intnumHats c) length == 12; d) int test1 = 90; int test2 = 85; double avg; avg = test1 + test2 / 2; e) double x = 12; double y = 0; double z; z = x / y; f) double payCheck = 120.00; NumberFormat money = NumberFormat.getPercentInstance(); System.out.println(money.format(payCheck);

 

  1. Determine if each of the following are true or false. If false, explain why.
  2. a) An identifier can contain spaces.-
  3. b) Data of type double is sometimes referred to as floating point-

. c) An abstract data type is also called a primitive data type.-

 

 
Leave a comment

Posted by on October 13, 2017 in Academic Writing

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: