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

....Important...... I have written the main introduction and the lab instruction

ID: 3721103 • Letter: #

Question

....Important......

I have written the main introduction and the lab instructions below. I have also included the part 2 and part 4 of the lab. Can I have the answers separately for each question? for example:- lab instructions, part 2, part 4 answers separately.

...................

With the value of Us dollar constantly changing it can be difficult to compare dollar amounts from a different point in time.

To make the comparisons we will use inflation rate from the Bureau of Labor Statistics that can be downloaded in CSV format from https://fred.stlouisfed.org/series/CPIAUCSL. You should download the CSV file into your project folder and load this data into your program. This file contains inflation data (Consumer Price Index) by month from 1947-2018.The index serves as a number that can be used to compare dollar amounts from different times. For example, on 1975-09-01 the index was 54.6 and on 1991-11-01 the index was 137.8 meaning that $54.60 on 1975 -09-01 is equivalent to $137.80 on 1991-11-01. The format of data is (DATE,CPIAUCSL) where CPIAUCSL is the index on DATE is in the format yyyy-mm-dd. Since the data is by month the day is always 01. This file does have a header line that must be handled accordingly.

.......Lab Instruction......

In a class named "Lab" write a public static method named "totalPercentageChange" that takes 5 strings as parameters and returns a double. In order, the 5 parameter strings are the name of the file containing the inflation data, the name of a file containing all the purchase price for items on the base date in YYYY-MM-DD format, the name of the file containing all the purchase price on the target date, and the target date in YYYY-MM-DD format. Each of the purchase prices files are csv files in the format (item_id_price) where item_id is an identifier for each item. These files will not have a header line. This method will return the total percentage change of the prices over this time period after adjusting for inflation

Explanation / Answer

// this is the method which accepts 5 parameters

// basefilename in string format containing the location of the CPIAUCSL.csv

// file

// basepricelistfile in string format containing the location of the file

// containing the price list of all the items at base date

// targetpricelistfile in string format containing the location of the file

// containing the price list of all the items at target date

// basedate is the base date in string format at which the comparision should

// begin

// targetdate is the target date in string format at which the comparision

// should begin

public static float totalPercentageChange(String basefilename, String basepricelistfile, String targetpricelistfile,

String basedate, String targetdate) throws IOException, ParseException {

// we use the file reader and buffer read the file line by line and we skip the

// first line in the file

// basefilename as if contains headers

File file = new File(basefilename);

FileReader fr = new FileReader(file);

BufferedReader br = new BufferedReader(fr);

String line;

// basedatevalue is used to store the dollar value on base date

String basedatevalue = null;

// targetdatevalue is used to store the dollar value on target date

String targetdatevalue = null;

line = br.readLine();

line = br.readLine();

// this while loop will read the data until file is read completely

while (line != null) {

// we strore each line in string array by splitting them by comma as it is a csv

// file

String[] lines = line.split(",");

if (lines[0].equals(basedate))

basedatevalue = lines[1];

else if (lines[0].equals(targetdate))

targetdatevalue = lines[1];

line = br.readLine();

}

// here we close the buffer reader for file above

// we perform the similar operations for other files

br.close();

File file1 = new File(basepricelistfile);

FileReader fr1 = new FileReader(file1);

BufferedReader br1 = new BufferedReader(fr1);

String line1;

// totalbaseprice is use to caliculate and store the total price of goods at

// base date

float totalbaseprice = 0;

line1 = br1.readLine();

while (line1 != null) {

String[] lines = line1.split(",");

totalbaseprice += Integer.parseInt(lines[1]);

line1 = br1.readLine();

}

br1.close();

File file2 = new File(targetpricelistfile);

FileReader fr2 = new FileReader(file2);

BufferedReader br2 = new BufferedReader(fr2);

String line2;

// totaltargetprice is use to calculate and store the total price of goods at

// target date

float totaltargetprice = 0;

line2 = br2.readLine();

while (line2 != null) {

String[] lines = line2.split(",");

totaltargetprice += Integer.parseInt(lines[1]);

line2 = br2.readLine();

}

br2.close();

// percentage_change_in_dollar_value is used to find the percentage difference

// in the dollar value in the two dates base and target

float percentage_change_in_dollar_value = 0;

percentage_change_in_dollar_value = ((Float.parseFloat(targetdatevalue) - Float.parseFloat(basedatevalue))

/ Float.parseFloat(basedatevalue)) * 100;

// percentage_change_in_goods_value is used to find the percentage difference in

// the total goods value in the two dates base and target

float percentage_change_in_goods_value = 0;

percentage_change_in_goods_value = ((totaltargetprice - totalbaseprice) / totalbaseprice) * 100;

// here we return the required value

return percentage_change_in_dollar_value - percentage_change_in_goods_value;

}