1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mart [117]
3 years ago
6

Fred wants to analyze his spending habits of the past few years and has gathered information on the checks he has written from 2

014 – 2018. The data is in a file in the form YYYY XXXXXX.XX where YYYY represents the year and XXXXXX.XX represents the dollar amount of the check. Because it took a while to gather the information, the data is not in year order. See the Input Data at the end of the assignment. After reading in the data, he wants to print a report by year of the number of checks written, the total amount spent and the average amount of the check. Also, an overall total of the five years appears after the individual data of each year.
Using one array to store the running total of the check amounts by year, an array to hold the number of checks written by year write the Java code to read and store the data and then do the necessary computations to produce a report in the format below. Use printf to display the dollar amounts with two decimal places and right adjust all output. You can set an int variable baseYear to 2014 and subtract it from the actual year to get the correct subscript in each array.

Sample report
Year # Checks Total Spent Average Check
2014 25 3452.23 198.02
. . . .
. . . .
. . . .
2018 33 1097.87 125.67
Overall Total 254 15478.98 167.65

The numbers appearing in the sample report above are not related to the actual input data to follow.
Input Data

2017 876.20
2014 345.67
2014 100.00
2016 345.89
2017 45.34
2015 89.23
2016 1000.00
2017 239.09
2018 67.89
2018 198.00
2015 145.45
2018 180.00
2015 505.23
2014 78.65
2014 42.98
2014 370.00
Computers and Technology
1 answer:
finlep [7]3 years ago
4 0

Answer:

See explaination

Explanation:

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class SpendAnalysis {

// year 2014 data will be at index 0

// year 2015 data will be at index 1

// year 2016 data will be at index 2

// year 2017 data will be at index 3

// year 2018 data will be at index 4

private static int[] checkIssued={0,0,0,0,0}; // will store the count of check for the year

private static double[] totalAmount={0,0,0,0,0}; // will store the total amount spent for that year

private static final int BASE_YEAR=2014; // base year

// need to update the below line so that it points to the input text file need to be read

private static final String INPUT_FILE="D:\\spent.txt";

public static void main(String[] args) {

// first read all the data from the input file and populate the array

try {

populateData();

} catch (FileNotFoundException e) {

System.out.println(INPUT_FILE+" could not read. Program will terminate now.");

System.exit(1);

}

// second print the data in the console

reportSpending();

}

// read data from input file and update the two arrays

public static void populateData() throws FileNotFoundException {

Scanner fileInput = new Scanner(new File(INPUT_FILE));

while(fileInput.hasNext()){

String[] lineTokens = fileInput.nextLine().split("\\s+");

if(lineTokens.length==2){

int year = Integer.parseInt(lineTokens[0].trim());

double amount = Double.parseDouble(lineTokens[1].trim());

checkIssued[year-BASE_YEAR]+=1;

totalAmount[year-BASE_YEAR]+=amount;

}

}

}

// print the report in the console

public static void reportSpending(){

System.out.println(String.format("%-13s%-15s%-15s%-15s","Year","# Checks","Total Spent","Average Check"));

System.out.println(String.format("%-15d%-15d$%-15.2f$%-15.2f",2014,checkIssued[0],totalAmount[0],totalAmount[0]/checkIssued[0]));

System.out.println(String.format("%-15d%-15d$%-15.2f$%-15.2f",2015,checkIssued[1],totalAmount[1],totalAmount[1]/checkIssued[1]));

System.out.println(String.format("%-15d%-15d$%-15.2f$%-15.2f",2016,checkIssued[2],totalAmount[2],totalAmount[2]/checkIssued[2]));

System.out.println(String.format("%-15d%-15d$%-15.2f$%-15.2f",2017,checkIssued[3],totalAmount[3],totalAmount[3]/checkIssued[3]));

System.out.println(String.format("%-15d%-15d$%-15.2f$%-15.2f",2018,checkIssued[4],totalAmount[4],totalAmount[4]/checkIssued[4]));

int totalChecks = checkIssued[0]+checkIssued[1]+checkIssued[2]+checkIssued[3]+checkIssued[4];

double totalSpent = totalAmount[0]+totalAmount[1]+totalAmount[2]+totalAmount[3]+totalAmount[4];

System.out.println(String.format("%-15s%-15d$%-15.2f$%-15.2f","Overall Total",totalChecks,totalSpent,totalSpent/totalChecks));

}

}

You might be interested in
Your search google for recipe for tonight dinner is an.example of ?​
Rina8888 [55]

The example is, ethier you need cooking classes or you wish to try something new

Hope the little humor helps

3 0
3 years ago
Read 2 more answers
whenever I try to make an account it says it can't sign me up at this time or something- can you help?-
Rus_ich [418]

Answer:

You can try emailing tech support and describing your issue. In order to get the best help as quickly as possible, try providing screenshots of what happens when you sign in or describe everything you see on the screen when the problem occurs, and quote error messages directly when possible.

5 0
2 years ago
In GamePoints' constructor, assign teamWhales with 500 and teamLions with 500. #include using namespace std; class GamePoints {
xxMikexx [17]

Answer:

Here is the GamePoints constructor:

GamePoints::GamePoints() :

/* Your code goes here */

{

teamLions = 500;

teamDolphins = 500;

}    

Explanation:

Here is the complete program:

#include  //to use input output functions

using namespace std; //to identify objects like cin cout

class GamePoints {  //class GamePoints

   public: GamePoints(); // constructor of GamePoints class

   void Start() const;  //method of GamePoints class

   private: //declare data members of GamePoints class

   int teamDolphins; // integer type private member variable of GamePoints

   int teamLions; }; // integer type private member variable of GamePoints

   GamePoints::GamePoints()  //constructor

    { teamLions = (500), teamDolphins= (500); }   //assigns 500 to the data members of teamLions  and teamDolphins of GamePoints class

   void GamePoints::Start() const    { //method Start of classs GamePoints

       cout << "Game started: Dolphins " << teamDolphins << " - " << teamLions << " Lions" << endl; }  //displays the values of teamDolphins and teamLions i.e. 500 assigned by the constructor

       int main() //start of main() function

       { GamePoints myGame;  // creates an object of GamePoints class

       myGame.Start(); //calls Start method of GamePoints class using the object

       return 0; }

The output of the program is:

Game started: Dolphins 500 - 500 Lions                    

8 0
3 years ago
EASY AND I GIVE BRAINLIEST!!! What is a good jeopardy question about operating systems?
madam [21]

 ______ is used in operating system to separate mechanism from policy
<span><span>A. Single level implementation</span><span>B. Two level implementation</span><span>C. Multi level implementation</span><span>D. None</span></span>
3 0
3 years ago
What type of software can you run to help fix computer problems?
GarryVolchara [31]

Answer:

IOBit Driver Booster.

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Which option organizes tasks based on importance?
    12·1 answer
  • What is the output of the following Java code?int x = 1;do{System.out.print(x + " ");x--;}while (x &gt; 0);System.out.println();
    14·1 answer
  • You will be given a string, containing both uppercase and lowercase alphabets(numbers are not allowed).
    14·1 answer
  • True or False <br><br> The term virus and malware may be used interchangeably.
    13·1 answer
  • Consider the following constructor for an immutable matrix ADT:
    8·1 answer
  • Write a program in which given an integer num, return the sum of the multiples of num between 1 and 100. For example, if num is
    7·1 answer
  • MULTIPLE CHOICE QUESTION PLEASE HELP!!!!!!!!!
    14·2 answers
  • Please choose the correct option please tell fast​
    9·1 answer
  • If a document is stored on a file server but team members can edit the document​ anonymously, the content on the file server is:
    14·1 answer
  • An office uses an application to assign work to its staff members. The application uses a binary sequence to represent each of 1
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!