daily pastebin goal
42%
SHARE
TWEET

JOHHNY IS MEAN

a guest Jan 18th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.lang.reflect.Method;
  4.  
  5. public class Dashboard
  6. {
  7.  
  8.    int Speedometer = 00000;
  9.    int odometer = 00000;
  10.    boolean checkEngine = false;
  11.    Dashboard()
  12.    {
  13.        this(0,0);
  14.    }
  15.     Dashboard(int milesTravelled, int speed)
  16.     {
  17.         odometer = milesTravelled;
  18.         if (!((milesTravelled >= 0) && (milesTravelled<99999)))
  19.         {
  20.             odometer = 0;
  21.             checkEngine = true;
  22.  
  23.         }
  24.         Speedometer = speed;
  25.         if (Speedometer > 100 || (Speedometer < 0))
  26.         {
  27.             Speedometer = 0;
  28.             checkEngine = true;
  29.  
  30.  
  31.         }
  32.  
  33.     }
  34.  
  35.    public void accelerate()
  36.     {
  37.         Speedometer += 1;
  38.         if (Speedometer > 100)
  39.         {
  40.             Speedometer = 0;
  41.             checkEngine = true;
  42.  
  43.  
  44.         }
  45.  
  46.  
  47.     }
  48.  
  49.     public void drive(int numMinutes) {
  50.  
  51.  
  52.         double mpm = (double)Speedometer/60;
  53.         double totalMiles = mpm * numMinutes;
  54.         odometer += (int)totalMiles;
  55.  
  56.         if (odometer > 99999) {
  57.             odometer = 0;
  58.             checkEngine = true;
  59.         }
  60.     }
  61.  
  62.     public String toString()
  63.     {
  64.         String assemblyRequired = "";
  65.         assemblyRequired += ("\nSpeedometer: " + Speedometer + " MPH");
  66.  
  67.  
  68.         int oLength = Integer.toString(odometer).length();
  69.         String toDisplay = "";
  70.         if (oLength == 1){
  71.             toDisplay = "0000" + odometer;
  72.         }
  73.         if (oLength == 2){
  74.             toDisplay = "000" + odometer;
  75.         }
  76.         if (oLength == 3) {
  77.             toDisplay = "00" + odometer;
  78.         }
  79.         if (oLength == 4){
  80.             toDisplay = "0" + odometer;
  81.         }
  82.         if (oLength == 5){
  83.             toDisplay =  Integer.toString(odometer);
  84.         }
  85.  
  86.         assemblyRequired += ("\nOdometer: " + toDisplay);
  87.  
  88.         if (checkEngine )
  89.         {
  90.             assemblyRequired += ("\nCheck Engine: On");
  91.  
  92.         }
  93.         else
  94.         {
  95.             assemblyRequired += ("\nCheck Engine: Off");
  96.  
  97.         }
  98.         return assemblyRequired;
  99.     }
  100.  
  101. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top