Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

A company that supplies batteries for watches guarantees

A company that supplies batteries for watches guarantees that 95% of the batteries it ships will be free from defects. You test a sample of 50 batteries you received. You find that fewer than 10 have defects. Does this l ...

Iq test scores of students are normally distributed with

IQ test scores of students are normally distributed with mean μ=100 and standard deviation σ=10. What is the 33th percentile of the IQ scores? For a randomly chosen student, what is the probability that his or her IQ sco ...

This subject is computer architecture organizationdraw a

This subject is computer Architecture organization Draw a flowchart showing the steps for a CPU program that uses programmed I/O to send a string consisting of 10 characters to a printer connected through a UART interfac ...

A biostatistician is investigating the timenbspt to death

A biostatistician is investigating the time,  T , to death of a mouse exposed to a newly developed pesticide. He finds that the pdf of T is given by the following formula  f(t) = 15t 2 e -5t3 . Which of the following sta ...

Suppose that we want to convert the small computer into a

Suppose that we want to convert the small computer into a 16- bit RISC type of processor (address and data buses are both 16-bits wide and each instruction is supposed to occupy 16 bits in the instruction memory). If the ...

Decision support systemsnbspvary greatly in application and

Decision support systems  vary greatly in application and complexity, but they all share specific features. A typical Decision support systems has four components: data management, model management, knowledge management ...

Suppose the cost function of making jackets is cx x2 -

Suppose the cost function of making jackets is C(x)= x^2 - 50x+1500. How many jackets should you make to minimize the cost of the jackets? How much would be the minimum cost?

It has been argued that although there may be more claims

It has been argued that although there may be more claims when road conditions are slippery in the winter, this should not affect the average claim. Malpeque took a sample of 50 claims from the winter of 2018 and found t ...

Question skyeducation will develop a new branch in the city

Question : SkyEducation will develop a new branch in the city for J2EE programming training. The information is given in the following table. (Ignore the crashing parameters.) Task a b c d e f g Predecessors - - - a b c ...

Give examples of how dominos has adapted its global

Give examples of how Domino's has adapted its global marketing mix to meet the needs of local consumers. Are you their customer? If so, why?

  • 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