dimanche 21 février 2021

How to generate my code to output a specific amount of times

I want to run and print out the loop 3000 times but every time I try to run it, it only prints whatever I called in the loop, once. I am using the random number generator to execute this or at least I think I am doing so. It is not shown in my code but I did import the random class and the IO exception class. What did I do wrong?

Here is my code:

public class ArtificialData{ 
    
   public static String getRandomMake(){
      String[] makes = {"Toyota", "BMW", "Dodge", "Carriage", "Ferrari", 
                        "Sled", "Chevrolet", "Hyundai", "Ford", "Mercedes", "Honda"};
      Random rand = new Random();
      int randomIndex = rand.nextInt(makes.length);
      String randomMake = makes[randomIndex];
      System.out.print(randomMake +", ");
      
      return randomMake;       
   }
 
   public static String getRandomModel(){
      String[] models = {"335xi", "Civic", "Camry", "G500", "Huracan", "3500", "Genesis", 
                          "Corvette", "Viper", "Model S", "Corolla"};
      Random rand = new Random();
      int randomIndex = rand.nextInt(models.length);
      String randModel = models[randomIndex];
      System.out.print(randModel +", " );
      
      return randModel;   
   }
   
   public static String getRandomMPG(){
      int lowest = 7, highest = 80;
      Random rand = new Random();
      
      double randomDouble = rand.nextDouble();
      int randomInt = rand.nextInt((highest - lowest)+1)+lowest;
      String randMPG = String.format("%.1f", (randomInt + randomDouble));
      System.out.print(randMPG + ", ");
      
      return randMPG;
   }
   
   public static String getRandomColor(){
      String[] colors = {"Green", "White", "Red", "Purple", "Blue", "Pink", 
                           "Black", "Lime", "Brown", "Maroon", "Orange", "Yellow"};
      Random rand = new Random();
      int randomIndex = rand.nextInt(colors.length);
      String randColor = colors[randomIndex];
      System.out.print(randColor + ", ");
      
      return randColor;
   }
   
   public static int getRandomYear(){
      Random rand = new Random();
      int randYear = ((2020)+1950);
      System.out.print(randYear + ", ");
      
      return randYear;   
   }

   public static int getRandomNumDoors(){
      int randDoors = ((4)+1);
      System.out.print(randDoors + ", ");
            
      return randDoors;
   }

   public static void main(String[] args)throws IOException{
            System.out.println("Finished..");
      
      FileWriter createData = new FileWriter("CarData.txt", true);
      int x = 0;
      do{
        ++x;
         String randMake = getRandomMake();
         String randModel = getRandomModel();
         String randMPG = getRandomMPG();
         String randColor = getRandomColor();
         int randYear = getRandomYear();
         int randDoors = getRandomNumDoors();
       
       }
       while (x>=3000);
          
      //clossing file
      createData.close();

   }
   
   }



Aucun commentaire:

Enregistrer un commentaire