Java coding if-else while loop

Assignment Help JAVA Programming
Reference no: EM13778479

1. Based on the code below, answer these questions (identify line numbers for Java statements):

Which line(s) will be executed if the condition in line 3 is true?
Processing then will proceed to which line?

Which line(s) will be executed if the condition in line 3 is false?
Processing will then proceed to which line?

Line 10 will always be executed whether line _____ is true or false.

Lines 5-6 will only be executed when line ______ is ____________.
Line 9 will only be executed when line ______ is ____________.

 

1 double purchasesYTD = 200.0;

2 double discount = 0.0;

3 if(purchasesYTD>= 200.00)

4 {

5 System.out.printf("%nUse this promo code on your next purchase ME09X1.");

6 discount = .10;

7 }

8 else

9 System.out.printf("%nPlease check our daily specials.");

10 System.out.printf("%nYou qualify for a %.0f%% discount.", discount);

2. Re-code the IF/ELSE structure in lines 3-9 above so the else statement is now the if statement. HINT: The condition tested should be reversed.

3. Use printf() with format specifiers as needed. Code on this page the following:

a. Code an if statement that prints "I got the promotion!". The if condition tests the boolean variable promotion which is already declared.

b. Given a boolean variable called inactive,use the conditional operator (ternary operator) to assign ‘Y' to the variable closeAcct; otherwise, assign‘N'. Assume both variables are already declared.

c. Write an if-else statement that assigns 2 extra credit points for an 80% class attendance rate, 3 extra credit points for an 85% class attendance rate, and 5 extra credit points for anything 90% and above. Assume extraCreditand attendancearealready declared. Make sure you scope the code properly

d. Code a while loop that keeps printing "You are a DEDICATED student!" as long as the user enters an attendance rate of 90% or greater. Assume the loop-control variable, attendance, is already declared along with input for the Scanner class. The while loop requires a priming read for the loop-control variable prior to entering the loop.

e. There are 20 students. Code a while loop that processes extra credit points for student attendance. Use the if/else coded in 3c. Print "Sorry, you've not earned any extra credit for your attendance." or "Congratulations! You've earned 9extra credit points because of your good attendance." where the 9 is the actual number of points earned based on the if/else from 3c. Assume the input variable for the Scanner class, the attendanceand extraCreditvariables are already declared. Declare the loop-control variable.

 

 

Reference no: EM13778479

Questions Cloud

Describe how the sox act may affect ethical decision : Write a 350- to 700-word review of the article. Your review should discuss how the SOX Act may affect ethical decision making in today's business environment, and the criminal penalties for which the act provides
Arrested for assaulting : Two men were arrested for assaulting each other in what would be called a "bar brawl." The bar owner did not press charges, and the two men were released.
State of decision making and problem diagnosis : Which of the steps in the formal planning process involves studying past events, examining current conditions, and forecasting future trends?
Stereotypes set by culture and society : Sociology came into existence in the 19th century to explain the enormous changes occasioned by the Industrial Revolution, urbanization, and an individualistic mind-set. Unlike agrarian communities, the emerging urban populations were large, numbe..
Java coding if-else while loop : Code a while loop that keeps printing "You are a DEDICATED student!" as long as the user enters an attendance rate of 90% or greater. Assume the loop-control variable, attendance, is already declared along with input for the Scanner class. The w..
Strongly counter-intuitive consequences : Review the Food Environment Atlas maps for variables that seem to affect your selected state the most. Select a state and variables you consider relevant to represent the food environment in you chosen state.
Meaningfulness of a correlation coefficient : What is the coefficient of determination? Why is it important to know the amount of shared variance when interpreting both the significance and the meaningfulness of a correlation coefficient?
How to create both method contract and method specification : Your demonstrations of how to create both method contract and the method specification for the GetCourseByCourseID() method of the CourseList class were very well received by your team members
When making basic marks and marginal comments : When making basic marks and marginal comments, which strategy is LEAST helpful? Which of the following steps do not help writers develop research topics into appropriate lines of inquiry?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a java program that prints the numbers from 1 to 125

Write a Java Program that prints the numbers from 1 to 125. But for multiles of three print "Batman" instead of the number and for the multiples of five print "Superman". For instances which are multiples of both three and five "JusticeLeague".

  Statistics list program

You will also modify your program to accept input from an input file and print a report to an output file. These files are to be named by the user at runtime.

  Create your own date class

You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program:

  Write a blog article for a codingtechnical community

write a blog article for a codingtechnical community blog.the theme is general c or java. choose any subject under this

  Simulate a simple multiuser computer system

Prepare a java program to simulate a simple multiuser computer system

  Write a bag class with a generic type

Write a Bag class with a generic type. Write a class such as item that has a name and price. Add objects of item to the bag and find the average and the total of the price of all items in the bag.

  Concept of java socket programming

Designed to asses learning outcomes and write programs that would communicate with another program running in the network

  Implement a generic class set

Implement a generic class Set that maintains a set of items of generic type T using the class LinkedList in the Java API. Your Set class must provide the subsequent functionality:

  The program reads in names

Write a program and include the following methods. The program reads in names and ages (use 2 parallel arrays, maximum size 50) from a file called Stuff.dat.

  Java program that will add the corresponding elements

Develop a Java program that will add the corresponding elements of two 1-dimensional arrays X and Y to produce the 1-dimensional array Z. Arrays X, Y, Z have the same dimension [M].

  Balancing binary search trees

Balancing Binary Search Trees,  Consider the file BST.java (a link to this file is provided below for downloading purposes) which defines a generic Binary Search Tree class.

  Write a program to find solution tocryparithmetic puzzle

Write a program (Crypta.java) that finds a solution to the cryparithmetic puzzle: TOO + TOO + TOO+ TOO = GOOD

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