Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- /**
- * Write a description of class CarTest here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class CarTest
- {
- public static double startKM;
- public static double endKM;
- public static double litre;
- public static double kpl;
- /**
- * Initialization Section.
- */
- public static void main(String[] args)
- {
- double a = 0;
- Scanner sc = new Scanner(System.in);
- Car[] car = new Car[9];
- for (int i = 0; i< car.length; i++)
- {
- car[i] = new Car();
- }
- String info = "";
- System.out.println ("Enter car number");
- String temp = sc.nextLine();
- int carNum = Integer.parseInt(temp);
- int startLine = 3*carNum;
- int endLine = (3*carNum)+2;
- try
- {
- BufferedReader in = new BufferedReader(new FileReader("data.txt"));
- double line;
- int counter = 0;
- double[] lineNum = new double[3];
- for (int i = 0; i < startLine; i++) { info = in.readLine(); }
- for (int i = startLine; i < endLine + 1; i++) {
- line = Double.parseDouble(in.readLine());
- lineNum[counter] = line;
- counter = counter + 1;
- }
- in.close();
- startKM = lineNum[0];
- endKM = lineNum[1];
- litre = lineNum[2];
- kpl = (endKM - startKM) / litre;
- }
- catch (IOException ex)
- {
- System.out.println ("IOException error");
- }
- catch (NumberFormatException ex)
- {
- System.out.println ("NumberFormatException error");
- }
- System.out.println ("The kpl is " + kpl);
- } // end of method double CalculateKPL(int carNum)
- } // end of class CarTest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement