Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This app will use two arrays of equal length - one for sales and the other for t

ID: 3682952 • Letter: T

Question

This app will use two arrays of equal length - one for sales and the other for the divisions names.

The data in these arrays will be positioned so that the divisions will share the same indexes in both arrays.

Work with the data, which is already included with the start file.

Note that there are three functions instead of two, this time.

From now on, use the convention of adding f_ in front of variables passed to a function definition, in order to be clear that it relates directly to the calling variable but lives in the function (f_). For example: populate_div_sales(div_sales, div_regions, 4); //function call void populate_div_sales(float f_div_sales[], string f_div_regions[], int size ) //function definition

Same as always, do not accept dollar amounts less than $0.00.

Explanation / Answer

import java.io.*;

public class Saleregion {
  
   public static void main(String[] args) {
       try {   
int i=0,lines=0;
String[] ars=new String[2];
           File file = new File("sales.txt");
           FileReader fileReader = new FileReader(file);
           BufferedReader bufferedReader = new BufferedReader(fileReader);
           String line;
lines=countlines();
  
float[] sales=new float[lines];
String[] regions=new String[lines];
           while ((line = bufferedReader.readLine()) != null) {
               ars=line.split(" ");
  
regions[i]=ars[0];
sales[i]=Float.parseFloat(ars[1]);
i++;
           }
  
populate_div_sales(sales,regions,lines);
  
           fileReader.close();
       } catch (IOException e) {
           e.printStackTrace();
       }
   }
static void populate_div_sales(float f_div_sales[], String f_div_regions[], int size )
{
System.out.println("Region Sales ");
for(int i=0;i<size;i++)
System.out.println(f_div_regions[i]+" "+f_div_sales[i]);
}
static int countlines() throws FileNotFoundException, IOException
{
File file = new File("sales.txt");
int c=0;
String line;
           FileReader fileReader = new FileReader(file);
           BufferedReader bufferedReader = new BufferedReader(fileReader);
while ((line = bufferedReader.readLine()) != null) {
c++;
}
return c;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote