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

  Application that generates a quiz

Create an application that generates a quiz. Prompt for the user's first and last name, college major, and confidence in test taking (high, medium, or low). The quiz should contain at least five true/false questions about horticulture. When the user ..

  Provide a regular expression that shows the set of strings

Provide a regular expression that shows the set of strings over {a, b} thatcontain at least one b if its length is at least four.

  Write a program to implement bubble sort and insertion sort

Write a program to implement bubble sort, insertion sort, selection sort, merge sort and quick sort (pivot = random index) algorithms

  Write a program cmsc401 java

Write a program cmsc401.java that receives a sequence of commands (from 1 up to 10000 commands)

  String copy and string concatenation functions

Write the string copy and string concatenation functions -  Append n characters from string2 to stringl by using pointer arithmetic

  Guess the number game

The user interface is displayed and the user clicks the "Start Game" button to begin the game - Your application then gets a random number in the range 1-1000 inclusive

  Algorithm analysis with advanced data structures

Algorithm Analysis with Advanced Data Structures, Your good friend, a Rock Star, asked you to create a Time Manager app for him, The Rock Star performs gigs at certain dates, all around the country - at most one gig per day

  Implement a game called bunko-poker

Implement a game called Bunko-Poker. The gameplay is an easily programmed version of the popular game Yahtzee. Your program will make use of the supplied static functions Dice.roll() and, in cases where you might need the string ordered, Dice.ordered..

  Demonstrating your understanding of java collections

Design, write and test the Java program ReadStoreShow.java with the following requirements:

  Write a program that prints a payroll statement

Write a program that accepts the subsequent information from the user and prints a payroll statement:

  Ask the user to input a grade (integer from 1-100)

Program should still ask the user to input a grade (integer from 1-100) and then output the letter grade.  Scale:  Greater than 90 is an "A"; Greater than 80 to 90 is a "B", Greater than 70 to 80 is a "C", Greater than 60 to 70 is a "D", and 60 or le..

  Alter the prototype form page by javascript function

Alter the prototype form page so that when JavaScript function has verified that all the required fields have been filled, cookie is added to user's computer.

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