Question

need this in java Using the mileage data file provided. The file contains a log of...

need this in java

Using the mileage data file provided. The file contains a log of miles and the gas used at each fill up. The fields are the model, miles and gallons of gas used. Use the data to create a set of parallel arrays to produce inquires and reports. Your program will produce a miles per gallon report. The report will consist of the following elements. Model, Total Gallons, Total Miles and Miles Per Gallons. This is a summary report per model summarizing the entries. Model Miles Gallons MPG The second report is a transaction report. The user will enter the name of the model, the report display all of the log entries the miles, the gallons and the Miles Per Gallon per fill up and MPG cumulative to that point ( use the total of the miles and gallons to that point) Model: Entry # Miles Gallons MPG MPG Cumulative Lastly you will you provide an inquiry. The user will enter the model and will return the total miles, the total gallons and the Mile per Gallon. Your reports will give the user the option to write to the screen, a file or to both.

data file Toyota RAV4 224 5.47

Honda CR-V 338 12.05

Chrysler Pacifica 318 7.35

Ford Edge 140 11.84

Chevrolet Equinox 344 17.70 Ford Edge 270 13.10 Honda CR-V 126 10.36 Nissan Rogue 151 18.19 Chrysler Pacifica 82 17.39 Chevrolet Equinox 243 17.76 Toyota RAV4 200 10.10 Toyota RAV4 258 15.91 Honda CR-V 301 19.08 Chrysler Pacifica 133 13.65 Ford Edge 280 6.96 Chevrolet Equinox 213 16.15 Ford Edge 103 16.98 Honda CR-V 146 9.13 Nissan Rogue 286 13.69 Chrysler Pacifica 275 15.85 Chevrolet Equinox 115 11.60 Toyota RAV4 346 9.68 Toyota RAV4 79 10.05 Honda CR-V 252 6.42 Chrysler Pacifica 224 15.30 Ford Edge 133 7.05 Chevrolet Equinox 205 19.94 Ford Edge 223 16.43 Honda CR-V 262 10.23 Nissan Rogue 242 7.01 Chrysler Pacifica 81 18.96 Chevrolet Equinox 248 19.95 Toyota RAV4 108 7.26 Toyota RAV4 139 9.75 Honda CR-V 166 5.08 Chrysler Pacifica 119 15.04 Ford Edge 157 18.65 Chevrolet Equinox 225 13.52 Ford Edge 212 10.68 Honda CR-V 232 11.16 Nissan Rogue 318 6.85 Chrysler Pacifica 111 12.69 Chevrolet Equinox 256 18.89 Toyota RAV4 348 6.59 Toyota RAV4 139 5.40 Honda CR-V 118 15.70 Chrysler Pacifica 138 17.14 Ford Edge 152 17.45 Chevrolet Equinox 171 19.80 Ford Edge 119 9.70 Honda CR-V 142 10.89 Nissan Rogue 266 12.00 Chrysler Pacifica 345 12.66 Chevrolet Equinox 75 7.42 Toyota RAV4 133 16.28 Toyota RAV4 262 14.42 Honda CR-V 213 13.00 Chrysler Pacifica 100 19.53 Ford Edge 325 17.05 Chevrolet Equinox 326 5.34 Ford Edge 240 13.36 Honda CR-V 109 6.21 Nissan Rogue 279 8.64 Chrysler Pacifica 232 16.19 Chevrolet Equinox 316 7.18 Toyota RAV4 193 10.92 Toyota RAV4 110 17.04 Honda CR-V 275 12.19 Chrysler Pacifica 242 6.29 Ford Edge 265 8.51 Chevrolet Equinox 271 5.04 Ford Edge 192 14.78 Honda CR-V 152 19.57 Nissan Rogue 220 7.81 Chrysler Pacifica 215 14.99 Chevrolet Equinox 200 9.36 Toyota RAV4 334 5.56 Toyota RAV4 237 12.79 Honda CR-V 182 9.37 Chrysler Pacifica 234 6.05 Ford Edge 91 19.97 Chevrolet Equinox 324 18.43 Ford Edge 320 10.29 Honda CR-V 84 10.38 Nissan Rogue 328 15.48 Chrysler Pacifica 250 14.84 Chevrolet Equinox 218 7.30 Toyota RAV4 228 16.42 Toyota RAV4 83 11.99 Honda CR-V 115 18.15 Chrysler Pacifica 171 15.69 Ford Edge 214 6.02 Chevrolet Equinox 298 12.44 Ford Edge 127 12.06 Honda CR-V 294 14.85 Nissan Rogue 211 14.24 Chrysler Pacifica 89 5.09 Chevrolet Equinox 296 9.23 Toyota RAV4 210 5.87

0 0
Add a comment Improve this question Transcribed image text
Answer #1

INPUT
##########

00000 Input Notepad File Edit Format View Help Chevrolet Equinox 344 17.70 Ford Edge 270 13.10 Honda CR-V 126 10.36 Nissan Ro

########################################################################

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class VehicleSummary {

   public static void main(String[] args) {
       Scanner s=new Scanner(System.in);
       int count=0;
      
       System.out.print("Enter the name of the file: ");
       String fileName=s.nextLine();
      
      
      
       String model[]=new String[100];
       double miles[]=new double[100];
       double fuel[]=new double[100];
      
       Scanner inFile=null;
       try {
           inFile=new Scanner(new File(fileName));
           while(inFile.hasNext()) {
              
              
               String line[]=inFile.nextLine().toLowerCase().split(" ");
               String name=line[0]+" "+line[1];
               int index=-1;
               for(int i=0;i<count;i++) {
                   if(model[i].equals(name)) {
                       index=i;
                       break;
                   }
               }
               if(index!=-1) {
                   miles[index]=miles[index]+Double.parseDouble(line[2]);
                   fuel[index]=fuel[index]+Double.parseDouble(line[3]);
               }else {
                   model[count]=name;
                   miles[count]=Double.parseDouble(line[2]);
                   fuel[count]=Double.parseDouble(line[3]);
                   count++;
               }
              
           }
       } catch (FileNotFoundException e) {
           System.out.println("Unable to find the file in current directory.Please check file name and path");
       }
       System.out.print("Enter the model name to find: ");
       String modelName=s.nextLine();
       int i;
       for(i=0;i<count;i++) {
           if(model[i].equalsIgnoreCase(modelName)) {
               System.out.println("Model        : "+modelName);
               System.out.println("Total Miles : "+miles[i]);
               System.out.println("Total Gallons: "+fuel[i]);
               System.out.println("MPG          : "+miles[i]/fuel[i]);
               break;
           }
       }
       if(i==count)
           System.out.println("Model is not found!!!!!!!!!!!!!!!!!!!");
   }

}

//######################################################################
OUTPUT
###########
Problems JavadocDeclaration Console Coverage <terminated> VehicleSummary [Java Application] C\Program Files\Java\jdk- Enter t

Add a comment
Know the answer?
Add Answer to:
need this in java Using the mileage data file provided. The file contains a log of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • As part of a study designed to compare hybrid and similarly equipped conventional vehicles, Consumer Reports...

    As part of a study designed to compare hybrid and similarly equipped conventional vehicles, Consumer Reports tested a variety of classes of hybrid and all-gas model cars and sport utility vehicles (SUVs). The following data show the miles-per-gallon rating Consumer Reports obtained for two hybrid small cars, two hybrid midsize cars, two hybrid small SUVs, and two hybrid midsize SUVs; also shown are the miles per gallon obtained for eight similarly equipped conventional models. Dataset: CarModels What are the treatment(s)...

  • The table shows a short excerpt from the "car weight and mileage" data file on the...

    The table shows a short excerpt from the "car weight and mileage" data file on the text CD. That file lists several 2004 model cars with automatic transmission and their x = weight (in pounds) and y = mileage (miles per gallon of gas). The scatterplot is roughly linear and r = -0.86. The regression equation is û = 49.586 -0.0058x. Automobile Brand Honda Accord Sedan LX Toyota Corolla Dodge Dakota Club Cab Jeep Grand Cherokee Laredo Hummer H2 Weight...

  • 23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4...

    23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same...

  • 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this...

    23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same as what you had for your chapter 13 labs). The following is an example of...

  • Following are data on price, curb weight, horsepower, time to go from 0 to 60 miles...

    Following are data on price, curb weight, horsepower, time to go from 0 to 60 miles per hour, and the speed at 1/4 mile for 16 sports and gt cars. Sports & GT Car/ Price ($1000s)/ Curb Weight (lb.)/ Horsepower /0-60 mph (seconds) /Speed at 1/4 mile (mph): Acura Integra Type R/ 25.035 /2577/ 195/ 7/ 90.7 Acura NSX-T/ 93.758/ 3066/ 290/ 5/ 108 BMW Z3 2.8/ 40.900/ 2844/ 189/ 6.6/ 93.2 Chevrolet Camaro Z28/ 24.865/ 3439/ 305/ 5.4/ 103.2...

  • The data file Motor Trend is a random sample of 32 automobiles.   The miles per gallon ...

    The data file Motor Trend is a random sample of 32 automobiles.   The miles per gallon (mpg), weight (wt), horsepower (hp) and type of transmission (manual or automatic) is recorded for each sampled automobile. The file is available on Blackboard. Transmission is a categorical variable. Code the variable transmission so that it can be used in a regression model. Your coding should assign a 1 to manual transmission and a 0 to automatic. Develop a regression model with mpg as...

  • (I did this homework in completion but professor was not happy with answers whatsoever, need additional...

    (I did this homework in completion but professor was not happy with answers whatsoever, need additional answers and especially improvement to 1.b help!! photos not attaching? mean by severai steps. inis is a View Feedback homework and will need you to work, in one two View Feedback or various steps. Unfortunately, I cannot read your screen shot of what you did on excel. As I have said in numerous messages announcements etc, I cannot аcсept pictures. You need to write...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT