import java.util.*;
import java.io.*;
import java.io.IOException;
import java.io.RandomAccessFile;
public class TestingOnly {
public static double distanceForLong;
public static double tripCostForLong = 0 ;
public static double distanceLongRandom;
public static int amountOfTripsForLong= 0;
public static Random rndmLong = new Random();
public static Random bookedLong = new Random();
public static double totalCostForLong = 0;
public static double amountOfTanksUsedLong = 0;
public static double amountOfLitersUsedLong = 0;
public static double rateLong = .5;
public static double milageLong = 7.6;
public static int longtripLong = 50;
public static int tankLong = 65;
public static int minimumLong = 10;
public static int startLong = 4;
public static int bookedstartLong = 6;
public static double longDistance =0;
public static double randomTime = 0;
public static long timeTaken =0;
public static double distanceForShort;
public static double tripCostForShort = 0 ;
public static double distanceShortRandom;
public static int amountOfTripsForShort= 0;
public static Random rndmShort = new Random();
public static Random bookedShort = new Random();
public static double totalCostForShort = 0;
public static double amountOfTanksUsedShort = 0;
public static double amountOfLitersUsedShort = 0;
public static double rateShort = .5;
public static double milageShort = 7.6;
public static int shorttripShort = 15;
public static int tankShort = 65;
public static int minimumShort = 10;
public static int startShort = 4;
public static int bookedstartShort = 6;
public static double shortDistance = 0;
public static long timeTakenShort= 0;
public static Random timeTakenRandomShort = new Random();
public static int randomTimeTaken = 0;
public static int randomTimeTakenTemp = 0;
public static double randomTimeLong = 0;
public static double randomWait = 0;
public static int arrayCounter = 0;
public static int arrayCounterLong = 0;
public static double longArray[] = new double[1000];
public static double shortArray[] = new double[1000];
public static int amountOfTimes = 0;
public static long shortTime = 0;
public static double longTime = 0;
public static Scanner kb = new Scanner(System.in);
public static int io = 0;
public static double average = 0;
public static double averageLong = 0;
static RandomShort file = new RandomShort();
public static void main(String args[]) throws IOException, NullPointerException{
System.out.println("How many times do you want to run the simulation?");
System.out.println(" ");
amountOfTimes = kb.nextInt();
for(io = 0; io <= amountOfTimes; io++)
{
shortTime = Shorttrip();
shortArray[arrayCounter] = shortTime;
RandomShort.editShort(shortTime);
longTime = longerTrips();
longArray[arrayCounterLong] = longTime;
timeTakenShort = 0;
longDistance = 0;
timeTaken = 0;
RandomShort.closeshort();
}
for(int j = 0; j <= amountOfTimes; j ++)
{
average += shortArray[j];
averageLong += longArray[j];
}
average = average/amountOfTimes;
averageLong = averageLong/amountOfTimes;
System.out.println("The average amount of Hours it took for a taxi driver doing short trips to reach the 350DHS limit is " + average/60 + " And the long trips " + averageLong/60);
}
public static long Shorttrip()throws IOException, NullPointerException{
for(totalCostForShort = 0; totalCostForShort <= 350; amountOfTripsForShort++ )
{
distanceShortRandom = rndmShort.nextInt(shorttripShort) + 1;
int bookeddShort = bookedShort.nextInt(1) + 1;
randomTime= rndmShort.nextInt(1) + 1;
if(bookeddShort == 0)
{
tripCostForShort = distanceShortRandom*rateShort + startShort;
}
else if(bookeddShort== 1 )
{
tripCostForShort = distanceShortRandom*rateShort + bookedstartShort;
}
if ( tripCostForShort < 10)
{
tripCostForShort = 10;
}
totalCostForShort = totalCostForShort + tripCostForShort;
amountOfLitersUsedShort = amountOfLitersUsedShort + (distanceShortRandom / milageShort);
shortDistance = distanceShortRandom + shortDistance;
amountOfTanksUsedShort =(amountOfLitersUsedShort /tankShort);
timeTakenShort = (long) (distanceShortRandom * randomTime + rndmShort.nextInt(10) +1 + timeTakenShort);
}
arrayCounter ++;
return timeTakenShort;
}
public static double longerTrips()throws IOException, NullPointerException
{
for(totalCostForLong = 0; totalCostForLong <= 350; amountOfTripsForLong++ )
{
randomTimeLong = rndmLong.nextInt(1) + 1;
distanceLongRandom = 15 + rndmLong.nextInt(longtripLong);
int bookeddLong = bookedLong.nextInt(1) + 1;
if(bookeddLong == 0)
{
tripCostForLong = distanceLongRandom*rateLong + startLong;
}
else if(bookeddLong== 1 )
{
tripCostForLong = distanceLongRandom*rateLong + bookedstartLong;
}
if ( tripCostForLong < 10)
{
tripCostForLong = 10;
}
totalCostForLong = totalCostForLong + tripCostForLong;
amountOfLitersUsedLong = amountOfLitersUsedLong + (distanceLongRandom / milageLong);
longDistance = distanceLongRandom + longDistance;
amountOfTanksUsedLong =(amountOfLitersUsedLong /tankLong);
timeTaken =(long) (longDistance/randomTimeLong);
}
arrayCounterLong ++;
return timeTaken;
}
}
To manage the random access files i have created a second class because i have had troubles with using Random access files because of static class references. here is the code for the Random access files:
import java.util.*;
import java.io.IOException;
import java.io.RandomAccessFile;
public class RandomShort {
public void main(String[] args) throws IOException{
RandomAccessFile shortData = new RandomAccessFile("TaxiDataShort.txt", "rw");
}
public static void editShort(long x) throws IOException{
shortData.writeLong(x);
}
public static void closeshort() throws IOException{
shortData.close();
}
}
Any idea what I'm doing wrong? if so, your input would be greatly appreciated. If i am using random access files completely wrong, it would be appreciated if you could explain what I'm doing wrong and what i need to improve on
Thanks for your time.

New Topic/Question
Reply



MultiQuote



|