All the requirements are attachedContents
Program
2
(a) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(b) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
(d) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2
2
2
Submission
3
Rubric
3
Example Output
3
1
Program
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.
(a)
First create your Random and Scanner objects, as you will need both in this program.
(b)
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.
(c)
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
CSCI 141: Assignment 3
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.
Tip
Youcangeneratearandom
between
and
methodandmultiplyingthereturned
bycallingyour
by
.
object’s
(d)
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.
Tip
Toformatadisplay
witha
valueroundedto2decimalplacesright-alignedand
fillingatleast7digitsofwhitespace,dothis:
Program
Submission
You will commit and push your changes to your specific GitHub Classroom repository for this
assignment. Although you are encouraged to use an IDE for development, we will compile and run
your program using the shell during grading. So it isn’t a bad idea to test it in the shell. Please
follow the directions below, make the requested code changes, and commit and push your changes
any time before the due date. Your final output should have the functionality displayed in the
Example Output below.
Rubric
Task
Percentage
General attempt at solving the problem
30%
Program compiles and runs
20%
Properly creating and filling the 2D array
20%
Printing out all sales figures
20%
Computing and printing totals
10%
Total
100%
Page 2 of
4
CSCI 141: Assignment 3
Example Output
Example Output continued on next page…
Example Output (continued)
Page 3 of
4
CSCI 141: Assignment 3
Page 4 of
4
public class Main
{
public static void main(String[] args)
{
// TODO: create your Random and Scanner objects
// TODO: ask how many sales
// TODO: create a 2D array of doubles to hold sales and taxes
// TODO: ask which state?
// TODO: create float for taxrate
// TODO: if state is “fl” (case insensitive), taxrate is 0.06f,
otherwise 0
// TODO: fill array column 0 with random sales figures between 0-99
// TODO: fill array column 1 with computed tax (sale * taxrate)
// TODO: call listSales() method, passing sales array
// TODO: call runTotals() method, passing sales array
}
// TODO: create listSales() method, which takes a double[][] and returns
nothing,
// this method loops through array and prints all sales, taxes, and
combined figures, per line
// TODO: create runTotals() method, which takes a double[][] and returns
nothing,
// this method loops through array to compute totals (sales, taxes,
gross),
// then prints them on a single line
}

Purchase answer to see full
attachment




Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.