CSCI 141: Assignment 3

This program is meant to give you practice with a 2D array and defining your own functions. You will create a 2D array filled with random sales figures and the tax per sale. Then you will write 2 functions (methods), one to print the information out, and one to sum up all the totals and print those out as well. See the example Output.

Here is the link to the GitHub Classroom assignment:



First create your Random and Scanner objects, as you will need both in this program.



Next, ask the user for the number of sales they want to load (generate). Use their answer to create a 2D array where the number of rows is the number of sales, and the number of columns is 2. This array will hold both randomly generated sales figures (in the first column) and the computed tax per sale (in the second column). Next, create a float variable to hold the tax rate. Ask the user which state these figures are coming from. If the user specifies “FL” (case insensitive), then the tax rate should be 6% (0.06f). If any other state or input, just make the tax rate 0.



Next, it’s time to populate your 2D array of sales figures with actual random numbers and taxes. Use a definite loop (for) to loop through the number of sales (the number of rows of the 2D array). For each loop iteration, set each sale’s column 0 to a random double between 0.0 and 100.0, and set column 1 to the value of column 0 multiplied by the tax rate. In other words, for each sale, column 0 holds the sale amount, and column 1 holds the computed tax for that sale.



Now you will write 2 separate functions (methods). Write a function called listSales() which takes a 2D double array as an argument and returns nothing. This function will loop through all the provided sales and print out each sale, its tax, and the total of sale + tax per line. Next, write a function called runTotals() which takes a 2D double array as an argument and returns nothing. This function will loop through all the sales and sum up three values: (1) the total of all sales (without tax), (2) the total of all taxes, and (3) the total of all sales with tax. Then you will display these final totals in a single line just under the full list of sales. Call both of these functions from main() passing your array of sales to each.



Example output

Image 1


Image 2


Image 3

Need a custom answer at your budget?

This assignment has been answered 3 times in private sessions.

© 2024 Codify Tutor. All rights reserved