Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. /**
  4. * Write a description of class CarTest here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class CarTest
  10. {
  11. public static double startKM;
  12. public static double endKM;
  13. public static double litre;
  14. public static double kpl;
  15. /**
  16. * Initialization Section.
  17. */
  18. public static void main(String[] args)
  19. {
  20. double a = 0;
  21. Scanner sc = new Scanner(System.in);
  22. Car[] car = new Car[9];
  23. for (int i = 0; i< car.length; i++)
  24. {
  25. car[i] = new Car();
  26. }
  27. String info = "";
  28. System.out.println ("Enter car number");
  29. String temp = sc.nextLine();
  30.  
  31. int carNum = Integer.parseInt(temp);
  32. int startLine = 3*carNum;
  33. int endLine = (3*carNum)+2;
  34. try
  35. {
  36. BufferedReader in = new BufferedReader(new FileReader("data.txt"));
  37. double line;
  38. int counter = 0;
  39. double[] lineNum = new double[3];
  40. for (int i = 0; i < startLine; i++) { info = in.readLine(); }
  41.  
  42. for (int i = startLine; i < endLine + 1; i++) {
  43. line = Double.parseDouble(in.readLine());
  44. lineNum[counter] = line;
  45. counter = counter + 1;
  46. }
  47. in.close();
  48. startKM = lineNum[0];
  49. endKM = lineNum[1];
  50. litre = lineNum[2];
  51. kpl = (endKM - startKM) / litre;
  52. }
  53. catch (IOException ex)
  54. {
  55. System.out.println ("IOException error");
  56. }
  57. catch (NumberFormatException ex)
  58. {
  59. System.out.println ("NumberFormatException error");
  60. }
  61.  
  62. System.out.println ("The kpl is " + kpl);
  63. } // end of method double CalculateKPL(int carNum)
  64. } // end of class CarTest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement