PRG420 Week 3 Individual Assignment Coding a Program Containing Loops

$ 10

PRG420 Week 3 Individual Assignment Coding a Program Containing Loops

Individual: Coding a Program Containing Loops

Includes Working Java Build and Program File and Explanation of Code
Resource:  Week Three Coding Assignment Zip File (starter code for this assignment that includes placeholders)
For this assignment, you will apply what you learned in analyzing for, while, and do-while loops by writing these statements yourself. The Java™ program you write should do the following:
• Display a pyramid of asterisks onscreen (i.e., a nested for loop)
• Display the integers 10 to 1 in decreasing order, one number per line (i.e., a while/do-whlie loop)
• Add 7 until the sum becomes greater than 157, at which point the program should display both the sum and the number of 7s added Complete this assignment by doing the following:
1. Download and unzip the linked Week Three Coding Assignment Zip File.
2. Add comments to the code by typing your name and the date in the multi-line comment header.
3. Replace the following lines with Java™ code as directed in the file:
• LINE 1
• LINE 2
• LINE 3
4. Comment each line of code you add to explain what you intend the code to do and why you chose each type of loop.
5. Test and modify your Java™ program until it runs without errors and produces the results as described above.
Note: Refer to this week’s analyzing code assignment if you need help.
Submit your Java source (.java) code file using the Assignment Files tab.

/**********************************************************************
* Program: PRG420Week3_CodingAssignment
*  Purpose: Week 3 Individual Assignment #2
* Programmer: Iam A. Student
* Class: PRG/420 PRG420 PRG 420
* Creation Date: TODAY’S DATE GOES HERE
***********************************************************************
*
***********************************************************************
* Program summary: For, while, do-while loops; nested loops
*
* For this assignment, you will add code to create:
*
* a for loop nested inside another for loop
* a while loop
* a do-while loop
*************************************************************************/

package prg420week3_codingassignment;

public class PRG420Week3_CodingAssignment {

public static void main(String[] args) {

// The following code should print asterisks: 1 on line 1, 2 asterists on line 2,
// 3 on line 3, 4 on line 4… for as many lines as the variable linesOfAsterisks.
// To do this, we can use 2 nested for loops. The first for loop is coded for you.
// You will need to add another for lop, NESTED INSIDE the first, that prints
// a certain # of asterisks based on the # of times the loop code has been executed.
// The result should look like this:
// *
// **
// ***
// ****
// *****
// etc.
int linesOfAsterisks = 5;
for (int i = 1; i <= linesOfAsterisks; i++) { // for each line…
// LINE 1. ADD A NESTED FOR LOOP THAT DISPLAYS ONE ASTERISK ON LINE 1, TWO ASTERISKS ON LINE 2, 3 ASTERISKS ON LINE 3, ETC.
System.out.println();
}
//////////////////////////////////////////////////////////////////////
// Add a while or do-while loop that displays the numbers from 10 to 1 in that order, like so:
// 10
// 9
// 8
// 7
// …
// 1
//////////////////////////////////////////////////////////////////////
int num=10;
//LINE 2. ADD A LOOP THAT DISPLAYS NUMBERS 10 TO 1 IN DECREASING ORDER (HINT: DECREMENT OPERATOR)
///////////////////////////////////////////////////////////////////////
// Write a loop that adds 7s one at a time until the sum becomes > 157.
// Then print out both the sum and the number of 7s that were aded.
// Write a while or do-while loop, whichever you think is most appropriate.
//////////////////////////////////////////////////////////////////////////
int sum = 0;
int numberOfSevens = 0;
//LINE 3. ADD ANOTHER LOOP THAT ADDS 7s UNTIL SUM > 157. THEN DISPLAY SUM AND NUMBER OF SEVENS ADDED.
}

989 in stock

SKU: PRG420W3CODING Category:

Description

PRG420 Week 3 Individual Assignment Coding a Program Containing Loops

Individual: Coding a Program Containing Loops

Includes Working Java Build and Program File and Explanation of Code
Resource:  Week Three Coding Assignment Zip File (starter code for this assignment that includes placeholders)
For this assignment, you will apply what you learned in analyzing for, while, and do-while loops by writing these statements yourself. The Java™ program you write should do the following:
• Display a pyramid of asterisks onscreen (i.e., a nested for loop)
• Display the integers 10 to 1 in decreasing order, one number per line (i.e., a while/do-whlie loop)
• Add 7 until the sum becomes greater than 157, at which point the program should display both the sum and the number of 7s added Complete this assignment by doing the following:
1. Download and unzip the linked Week Three Coding Assignment Zip File.
2. Add comments to the code by typing your name and the date in the multi-line comment header.
3. Replace the following lines with Java™ code as directed in the file:
• LINE 1
• LINE 2
• LINE 3
4. Comment each line of code you add to explain what you intend the code to do and why you chose each type of loop.
5. Test and modify your Java™ program until it runs without errors and produces the results as described above.
Note: Refer to this week’s analyzing code assignment if you need help.
Submit your Java source (.java) code file using the Assignment Files tab.

/**********************************************************************
* Program: PRG420Week3_CodingAssignment
*  Purpose: Week 3 Individual Assignment #2
* Programmer: Iam A. Student
* Class: PRG/420 PRG420 PRG 420
* Creation Date: TODAY’S DATE GOES HERE
***********************************************************************
*
***********************************************************************
* Program summary: For, while, do-while loops; nested loops
*
* For this assignment, you will add code to create:
*
* a for loop nested inside another for loop
* a while loop
* a do-while loop
*************************************************************************/

package prg420week3_codingassignment;

public class PRG420Week3_CodingAssignment {

public static void main(String[] args) {

// The following code should print asterisks: 1 on line 1, 2 asterists on line 2,
// 3 on line 3, 4 on line 4… for as many lines as the variable linesOfAsterisks.
// To do this, we can use 2 nested for loops. The first for loop is coded for you.
// You will need to add another for lop, NESTED INSIDE the first, that prints
// a certain # of asterisks based on the # of times the loop code has been executed.
// The result should look like this:
// *
// **
// ***
// ****
// *****
// etc.
int linesOfAsterisks = 5;
for (int i = 1; i <= linesOfAsterisks; i++) { // for each line...
// LINE 1. ADD A NESTED FOR LOOP THAT DISPLAYS ONE ASTERISK ON LINE 1, TWO ASTERISKS ON LINE 2, 3 ASTERISKS ON LINE 3, ETC.
System.out.println();
}
//////////////////////////////////////////////////////////////////////
// Add a while or do-while loop that displays the numbers from 10 to 1 in that order, like so:
// 10
// 9
// 8
// 7
// …
// 1
//////////////////////////////////////////////////////////////////////
int num=10;
//LINE 2. ADD A LOOP THAT DISPLAYS NUMBERS 10 TO 1 IN DECREASING ORDER (HINT: DECREMENT OPERATOR)
///////////////////////////////////////////////////////////////////////
// Write a loop that adds 7s one at a time until the sum becomes > 157.
// Then print out both the sum and the number of 7s that were aded.
// Write a while or do-while loop, whichever you think is most appropriate.
//////////////////////////////////////////////////////////////////////////
int sum = 0;
int numberOfSevens = 0;
//LINE 3. ADD ANOTHER LOOP THAT ADDS 7s UNTIL SUM > 157. THEN DISPLAY SUM AND NUMBER OF SEVENS ADDED.
}

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.