Ask Computer Engineering Expert

1. Code a statement that declares a class named BookOrderApp that has public access.

2. After the if statement that follows is executed, what will the value of discountAmount be?

double discountAmount = 0.0;
double orderTotal = 200.0;
if (orderTotal > 200)
discountAmount = orderTotal * .3;
else if (orderTotal > 100)
discountAmount = orderTotal * .2;
else
discountAmount = orderTotal * .1;

a) 0.0

b) 40.0

c) 20.0

d) 60.0

3. Given a double variable named total and an integer variable named quantity, code a statement that divides the total by the quantity, assigns the value to another variable named price, and retains the decimal places in the result.

4. How many times will the while loop that follows be executed if months has a value of 5?

int i = 1;
while (i
{
futureValue = futureValue * (1 + monthlyInterestRate);
i = i+1;
}

a) 0

b) 5

c) 4

d) 6

5. Code a statement that creates an instance of a class named BookOrder and assigns it to a variable named bookOrder. Pass arguments named code, price, and quantity to the constructor of this class.

6. Code a statement that returns a random number as an integer that's greater than or equal to 0 and less than or equal to 10. Store the result in an int variable named random.

7. If the double variables x = 2.5 and y = 4.0, what is the value of z after this statement is
executed?
int z = (int) x + (int) y;

a) 6

b) 6.5

c) 6.0

d) 7

8. Code a statement that converts a double variable named subtotal to a String object named subtotalString.

9. Which of the values below will not be printed to the console when this code is executed?

for (int i = 0; i
{
for (int j = 0; j
{
if (i == j)
continue;
System.out.println("i = " + i + " j = " + j);
}
}

a) i = 0 j = 1

b) i = 2 j = 1

c) i = 1 j = 0

d) i = 1 j = 1

10. If the instance variables of the Employee class are declared as follows, which of the following statements is most likely to be in the constructor of this class?

private String name;
private Address address;
private long employeeNumber;

a) address = 0;

b) address = new Address();

c) address = " ";

d) employeeNumber = "11233444";

11. What happens in the method that follows when s is "two"?

public double parseInterval(String s)
{
double interval = 0.0;
try
{
interval = Double.parseDouble(s);
}
catch(NumberFormatException e)
{
}
return interval;
}

a) 2.0 is returned

b) a compile-time error occurs since the catch block isn't properly coded

c) no value is returned since the catch block doesn't return a value

d) 0.0 is returned

11. Code a private static method named printMessage that accepts a String parameter that represents the message. The method should simply print the message followed by a blank line at the console.

VARIABLE DECLARATION & INITIALIZATION, CONSOLE OUTPUT

12. a) Write a valid statement for declaring and initializing a double variable named length to a starting value of 120?

b) Assume userName equals "Tom" and userAge equals 22. What is printed on the console when the following statement is executed?

System.out.println(userAge + " \nis " + userName + "'s age.");
WHILE STATEMENT

13. a) Code a while statement that will continue executing while a variable named multiplier is not equal to 1. The code within the while loop should start by subtracting 1 from the multiplier variable. Then, it should multiply a numeric variable named number by the multiplier variable and store the result in the number variable. Assume that both variables have already been declared and initialized.

b) Code a statement that creates an object for Scanner class.

IMPORT STATEMENTS

14. a) Code a statement that declares an integer named quantity and assigns an initial value of zero to it.

b)Code a statement that imports all of the classes in the java.io package.

c) Code a statement that imports the Scanner class.

d) Code a statement that imports the NumberFormat class.

STRINGS

15. a) Code a statement that declares a string variable named cityStateZip and then assigns a value that joins three string variables named city, state, and zip and two string literals that separate the city and state by a comma and a space and the state and zip by a space.

b) Code a string that, when displayed on the console, will look like this:

Fresno

CA

93720

GETTING INPUT VALUES & DISPLAYING OUTPUT

16. a) Code a statement that prints a variable named total to the console, followed by a new line character.

b) Given a Scanner variable named sc, code a statement that returns the value the user enters at the console as a String object and stores it in a variable named city.

c) Given a Scanner variable named sc, code a statement that returns the value the user enters at the console as a double object and stores it in a variable named price.

TYPE CASTING, NUMBERFORMAT CLASS

17. a) Given two integers named thisYTDQty and lastYTDQty, code a statement that divides the first value by the second value so that any decimal places in the result are retained. Store the result in a double variable named percentChange.

b) Code the statements needed to format the double variable named percentChange as a percent that always has two decimal places. Store the result in a string named percentString.

c) Code a single statement that formats a double value named total as currency with two decimal places and stores it in a string named totalString.

FOR LOOP

18. a) Code a for loop that adds the integers that are multiples of 5 starting with 50 and ending with 5. Each time the sum is increased, print it on a line at the console. Be sure to declare and initialize any required variables.

b) Code nested for loops that calculate the area of a rectangle that can range in size from a length and width of 1 to a length and width of 10. Print the area for each width for a given length on a single line at the console followed by a space. Be sure to declare and initialize any required variables.

19. Given an String object named shippingType, code an if statement that sets a double variable named shippingBase to 4.95 if shippingType is equal to "FEDEX" and to 5.95 if shippingType contains any other value. Include the code necessary to prevent a NullPointerException.

20. Code a statement that uses a static constant named SALES_TAX_PERCENT that's stored in a class named Sales. This statement should use this constant to calculate the sales tax for a double variable named subtotal and store it in another double variable named salesTax.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92100284

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As