What will the value of discountamount be

Assignment Help Basic Computer Science
Reference no: EM131346717

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.

Reference no: EM131346717

Questions Cloud

What were specific reasons why gold standard was eliminated : What were the specific reasons why the gold standard was eliminated? How does a floating exchange rate system work? What is managed float or a managed floating exchange rate system?
Explain the importance of knowing the glycemic index : Fitness experts are often consulted on the best dietary practices prior to a race or competition. Athletes should understand the importance of consuming high-glycemic carbohydrates prior to competition. Watch the video Eat to Win: Nutrition for A..
Determine the critical clearingtime for a fault : Determine the critical clearingtime (to the nearest 0.01 second) for a fault on the line between buses 2 and 5 at thebus 5 end which is cleared by opening the line.
Fastest method of finding square of any number ending with 5 : Fastest method of finding Square of any number ending with 5
What will the value of discountamount be : 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.
Define religion and discuss why it is useful in society : Define religion, and discuss why it is useful in society. Explain why it is important for you personally to understand the beliefs of other religious groups.
Write the classification of economy : Write the classification of economy in the same way which will include fishers resource, trade resource, etc.- write any trade agreement (from UAE and other countries).
Investors expect stock to pay year-end dividend : A share of stock with a beta of .76 now sells for $51. Investors expect the stock to pay a year-end dividend of $2. The T-bill rate is 3%, and the market risk premium is 7%. Suppose investors believe the stock will sell for $53 at year-end. Is the st..
In terms of maslows hierarchy what motivates you : GOV 10- In terms of Maslow's hierarchy, what motivates you? How would you determine what motivates employees? What if your wrong about what motivate certain employees, how would you reassess your determination?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  A task of getting ip addresses

A task of getting IP addresses and subnets for three fully functional labs

  Designing a social networking website

Your employer has tasked you with designing a social networking website. You are free to design either a blog, a micro-blog, or a wiki.

  Describe about power wall and ilp wall

Describe about Power wall and ILP wall

  What terms would you give these approaches

What terms would you give these approaches?

  Does a similar process describe the 2d fourier transform

Does a similar process describe the 2D Fourier transform? The general 2D transform (10.38 )?

  Ensure security, integrity, and operability of the database.

Select one of the steps you perform in the physical design of this database. Analyze how this step helps ensure security, integrity, and operability of the database.

  Various ways of representing a function

What are the various ways of representing a function? What methods can you use to determine whether a relation is a function?

  Technology and job design

Advancements in technology have certainly made our lives easier over the last twenty years. They've also changed the nature of how many of us do our jobs. A great example is right here in this course...professors can teach from home!

  Describe three olap uses of this data warehouse

Design a multidimensional database using a star schema for a data warehouse for the Super Baseball League business environment described in Minicase 2.2.

  Modify the algorithm so that it overcomes this problem

This would happen because if there was a space at the end of an input line it would be turned into two spaces in the reformatted output. Modify the algorithm so that it overcomes this problem.

  Determine the date in opening of letter

If /home/jenny/draft and /home/alex/letter are links to same file and following sequence of events occurs, what will be date in opening of letter? Alex gives command vim letter.

  Can you make the code faster

Can you make the code faster?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd