Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey, I have some trouble with this Java assignment. This is the original code given. I've coded mine but it's not compiling for some reason,

Hey, I have some trouble with this Java assignment. This is the original code given. I've coded mine but it's not compiling for some reason, and I would love your help to understand how to fix my code better. Thanks in advance!

//Write a program that opens the salesdat.txt file and processes it contents. The program should display the following per store:

The total sales for each week. (Should print 5 values - one for each week).

The average daily sales for each week. (Should print 5 values - one for each week).

The total sales for all the weeks. (Should print 1 value)

The average weekly sales. (Should print 1 value)

The week with the highest amount in sales. (Should print 1 week #)

The week with the lowest amount in sales. (Should print 1 week #)

The file contains the dollars amount of sales that a retail store made each day for a number of weeks. Each line in the file contains thirty five numbers, which are sales numbers for five weeks. The number are separated by space. Each line in the file represents a separate store.

//Driver.java

public class Driver {

public static void main(String[] args) {

// TODO Auto-generated method stub

FileIO a1 = new FileIO("Z:\\JavaPrograms2\\assignment336b\\src\\Salesdat.txt");

Franchise f = a1.readData();

}

}

//FileIO.java

import java.io.*;

import java.util.*;

public class FileIO {

private String fname = null;

private boolean DEBUG = true;

public FileIO(String fname) {

this.fname = fname;

}

public Franchise readData() {

Franchise a1 = null;

int counter = 0;

try {

FileReader file = new FileReader(fname);

BufferedReader buff = new BufferedReader(file);

String temp;

boolean eof = false;

while (!eof) {

String line = buff.readLine();

counter++;

if (line == null)

eof = true;

else {

if (DEBUG)

System.out.println("Reading" + line);

if (counter == 1) {

temp = line;

a1 = new Franchise(Integer.parseInt(temp));

if (DEBUG)

System.out.println("d " + a1.numberofstores());

}

if (counter == 2)

;

if (counter > 2) {

int x = buildStore(a1, (counter-3), line);

if (DEBUG)

System.out.println("Reading Store # "+(counter-2)+" Number of weeks read = " + x);

if (DEBUG)

{

System.out.println("Data read:");

a1.getStores(counter-3).printdata();

}

}

}

}

buff.close();

} catch (Exception e) {

System.out.println("Error -- " + e.toString());

}

return a1;

}

public int buildStore(Franchise a1, int counter, String temp) {

Store tstore = new Store();

String s1 = "";

float sale = 0.0f;

int week = 0;

int day = 0;

StringTokenizer st = new StringTokenizer(temp);

while (st.hasMoreTokens()) {

for(day=0;day<7;day++)

{

s1 = st.nextToken();

sale = Float.parseFloat(s1);

tstore.setsaleforweekdayintersection(week, day, sale);

}

week++;

}

a1.setStores(tstore, counter);

return week;

}

}

//Store.java

public class Store {

private float salesbyweek[][];

Store() {

salesbyweek = new float[5][7];

}

// getter and setters

// setsaleforweekdayintersection(int week, int day, float sale)

public void setsaleforweekdayintersection(int week, int day, float sale) {

salesbyweek[week][day] = sale;

}

public void printdata() {

for (int i = 0; i < 5; i++)

{

for (int j = 0; j < 7; j++)

{

System.out.print(salesbyweek[i][j] + " ");

}

System.out.println("");

}

}

// float [] getsalesforentireweek(int week)

// float getsaleforweekdayintersection(int week, int day)

// businessmethod

// a. totalsalesforweek

// b. avgsalesforweek

// c. totalsalesforallweeks

// d. averageweeklysales

// e. weekwithhighestsaleamt

// f. weekwithlowestsaleamt

// analyzeresults //call a through f

// print()

}

//Franchise.java

public class Franchise {

private Store stores[];

public Franchise(int num) {

stores = new Store[num];

}

public Store getStores(int i) {

return stores[i];

}

public void setStores(Store stores, int i) {

this.stores[i] = stores;

}

public int numberofstores()

{

return stores.length;

}

}

//Salesdat.txt

6

Day1 Day2 Day3 Day4 Day5 Day6 Day7 Day8 Day9 Day10 Day11 Day12 Day13 Day14 Day15 Day16 Day17 Day18 Day19 Day20 Day21 Day22 Day23 Day24 Day25 Day26 Day27 Day28 Day29 Day30 Day31 Day32 Day33 Day34 Day35

2541.56 2258.96 2214 2256 2154 2398 2597 2684 2771 2858 2945 3032 3119 3206 3293 3380 3467 3554 3641 3728 3815 3902 3989 4076 4163 4250 4337 4424 4511 4598 4685 4772 4859 4946 5033

2041.56 1758.96 1714 1756 1654 1898 2097 2184 2271 2358 2445 2532 2619 2706 2793 2880 2967 3054 3141 3228 3315 3402 3489 3576 3663 3750 3837 3924 4011 4098 4185 4272 4359 4446 4533

3041.56 2758.96 2714 2756 2654 2898 3097 3184 3271 3358 3445 3532 3619 3706 3793 3880 3967 4054 4141 4228 4315 4402 4489 4576 4663 4750 4837 4924 5011 5098 5185 5272 5359 5446 5533

3563.54 3280.94 3235.98 3277.98 3175.98 3419.98 3618.98 3705.98 3792.98 3879.98 3966.98 4053.98 4140.98 4227.98 4314.98 4401.98 4488.98 4575.98 4662.98 4749.98 4836.98 4923.98 5010.98 5097.98 5184.98 5271.98 5358.98 5445.98 5532.98 5619.98 5706.98 5793.98 5880.98 5967.98 6054.98

2547.21 2264.61 2219.65 2261.65 2159.65 2403.65 2602.65 2689.65 2776.65 2863.65 2950.65 3037.65 3124.65 3211.65 3298.65 3385.65 3472.65 3559.65 3646.65 3733.65 3820.65 3907.65 3994.65 4081.65 4168.65 4255.65 4342.65 4429.65 4516.65 4603.65 4690.65 4777.65 4864.65 4951.65 5038.65

4040.55 3757.95 3712.99 3754.99 3652.99 3896.99 4095.99 4182.99 4269.99 4356.99 4443.99 4530.99 4617.99 4704.99 4791.99 4878.99 4965.99 5052.99 5139.99 5226.99 5313.99 5400.99 5487.99 5574.99 5661.99 5748.99 5835.99 5922.99 6009.99 6096.99 6183.99 6270.99 6357.99 6444.99 6531.99

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PC Magazine Guide To Client Server Databases

Authors: Joe Salemi

1st Edition

156276070X, 978-1562760700

More Books

Students also viewed these Databases questions

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago