Programming Activity 6-2 Guidance
=================================
For this activity, you are totaling item prices.
You must get each item, get its price, and add that price to the total.
When you have the final total, you output it in the format specified.
Purpose of "for" loop
---------------------
You must understand the purpose of the "for" loop in this assignment.
The "for" loop is to iterate through the items and update a total.
The "for" loop should not be the only thing in the function.
It needs appropriate local variables declared BEFORE it begins.
That means BEFORE the "for" statement line.
You output the total AFTER the "for" loop finishes.
That means AFTER its closing brace.
That is why local variables, like the total, must be declared
BEFORE the "for" loop is entered.
If you declared the total variable inside the "for" loop,
then it could not be referenced after it.
Pseudocode for this assignment
------------------------------
You can find the following in this weeks outline:
Calculate a total (using a for loop) (pseudocode)
total = 0
// There is no need for a priming read.
for (int i = 1; i <= number of items; i++)
{
read next number // Update read
total += number
}
output total
Students who have not taken time to learn about pseudocode,
mistakenly think that it is real code and try to use it verbatim.
Then, when it does not even compile, they get confused.
It is called pseudocode because it is not real, final code.
It requires work to turn it into real code.
Some fragments of it may match real code.
Other parts simply outline what to do.
More specifically for 6-2
-------------------------
initialize variables
The above pseudocode only shows a total variable.
Remember that this is pseudocode.
In Java every variable must have a type.
You need other variables besides the double for the total.
You need a reference to an item of type Item.
Another useful variable is a double to store the price of an item.
Your for loop must iterate once for each item.
Your for loop condition must make use of the parameter numberOfItems,
which is automatically passed into the function you are in by the framework.
Here is an outline for your for loop body:
Get the next item and its price.
Update the total with the current item's price.
Make the call to animate.
After the end of the for loop:
Output the results.
|
/* /** /** |

IF THERE IS ANY PROBLEM OR YOU HAVE ANY QUERY REGARDING THE SOLUTION KINDLY FEEL FREE TO ASK, AND LEAVE A THUMBS UP WHEN YOU ARE SATISFIED. THANKS!.
Description:In this assignment, you will write a program in C++ that uses files and nested loops to create a file for real estate agents home sales and then read the sales from the file and calculates the average sale for each agent. Each agent sold 4 homes. Use a nested loop to write each agent’s sales to a file. Then read the data from the file in order to display the agent’s average sale and the average for all sales....
Need some guidance with the following problems as I am new to Java programming. Any assistance is greatly appreciated. Thanks Using printf and specifiers for all print instructions: 1. Code the following: a. 10% is stored in a variable called discount when the customer is a student; otherwise, it stores 0%. Code this if … else control structure using the conditional operator (ternary operator). The variables discount and student have already been declared. Assume student is a boolean variable. b. ...
CODE MUST BE IN C 1. Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have alreadybeen declared, use a while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total. Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total. Use no variables other than n, k, and...
I currently have a code that I have written that uses global variables. My professor wants me to rewrite this code so that it uses the return function instead. I dont understand why because it works the same, but I am not great at using return and barely understand it. here is my code. This is in Python3 #Created an empty dictionary using variable #grocery_item grocery_item = {} #Created an empty list for using variable #grocery_history grocery_history = [] #This...
Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...
Java Programming: Make a Java program with two processes, a producer and a consumer. If you want to use another language, clear it with me first. The producer process consists of a loop that writes the loop count (a value from 0 to 4) into a variable that it shares with the consumer process (this variable is to be initialized to 100). On each pass through the loop, before the producer writes into the shared variable, it does a random...
Write C code to repeatedly ask the user for a number, then once the user enters 0, the code displays the min, max and average of all values entered. To get proper credit, name the variables as listed below and follow the directions carefully. Do not use any break or similar type of statements. To implement the above code, you will need to count the entries - name the counter variable num_count. You will also need to use a variable,...
Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of the...
Iterating over a 2D array If we want to visit or process every element of a 2D array, we need a nested for loop to do it. Generally, when you iterate over a 2D array, you want to do it in row major order, because this is more memory efficient. The reason why is that adjacent elements in a row are stored contiguously (one after another) in memory. Another reason, for an English speaker, is that this is the same...
Exercise #2:Create a data file named water.dat with the following data: 123 134 122 128 111 110 98 99 78 98 100 120 122 110 111 123 134 122 128 111 110 98 99 78 98 100 120 122 110 111. Each number represents the number of millions of gallons of water provided to a major city over the period of one month. The data runs for quite a number of months. You will write a loop to read all the data...