Coder Social home page Coder Social logo

routerunner's People

Contributors

miguelangeltamargo avatar

Watchers

 avatar

routerunner's Issues

Try: Adder

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Random;

class Adder extends Routes {
public static void main(String[] args) {
Routes routes = new Routes();
String[] carArray = new String[] {"null", "null", "Compact", "Truck", "null", "Midsize", "Truck with double trailer", "Truck with quad trailer", "null", "null", "SUV", "null", "SUV with double trailer", "null", "SUV with quad trailer" };
Scanner scan = new Scanner(System.in);
Random rand = new Random();
int randomNum;
int choice; // this will be the random vehicle generated which is added to the
//array for the caravan as an integer based on the capacitySize
//note: special case on truck with double trailer because
//midsize = 5 capacity and truck with double trailer = 5
ArrayList arrayList1 = new ArrayList();
ArrayList arrayList2 = new ArrayList();
ArrayList arrayList3 = new ArrayList();

	while (true) {
		randomNum = rand.nextInt(15);
		System.out.println("\nMake a choice:\n1.)Add to caravan 1\t\t2.)Add to caravan 2\t\t3.)Add to caravan 3\t\t4.)Check caravanLists\t\t5.)CarArray Checker and getter.\t\t6.)Send Caravan Array on Route");
		choice = scan.nextInt();
		
		switch (choice) {
			case 1:
				arrayList1.add(randomNum);
				break;
			case 2:
				arrayList2.add(randomNum);
			
				break;
			case 3:
				arrayList3.add(randomNum);
				break;
			case 4:
				System.out.println("\n" + arrayList1.size() +"\n" + arrayList1 + "\n");
				System.out.println("\n" + arrayList2.size() +"\n" + arrayList2 + "\n");
				System.out.println("\n" + arrayList3.size() +"\n" + arrayList3 + "\n");
				break;
			case 5:
				System.out.println("\n"+carArray.length);
				System.out.println(carArray[scan.nextInt()]); 
				break;
			case 6:
				System.out.println("Select which caravan to send.");
				System.out.println("1.) Caravan 1: "+arrayList1);
				System.out.println("2.) Caravan 2: "+arrayList2);
				System.out.println("3.) Caravan 3: "+arrayList3);
				switch (scan.nextInt()) {
					case 1:
						//print caravan sorted or not
						//add caravan 1 to certain variable
						//break to pick which route to compare
						break;
					case 2:
						break;
					case 3:
						break;
				}
			
				switch (scan.nextInt()){
					case 1:
					System.out.println("Route 1: \nPass Rate: 20.00 %");
					System.out.println("Route 2: ");
					routes.routeRate();
					System.out.println("Route 3: ");
					routes.routeRate();
					break;
					case 2:
					System.out.println("Route 1: \nPass Rate: 20.00 %");
					System.out.println("Route 2: ");
					routes.routeRate();
					System.out.println("Route 3: ");
					routes.routeRate();
					break;
					case 3:
					System.out.println("Route 1: \nPass Rate: 20.00 %");
					System.out.println("Route 2: ");
					routes.routeRate();
					System.out.println("Route 3: ");
					routes.routeRate();
					break;
				}
		}
	}
}

}

Try:

import java.util.Random;

public class Routes {

        public Random rando = new Random(); //initializing the "rando" variable with random class
        public float passRate = rando.nextFloat();
        public float failRate = (1-passRate);

        //failChance must be 0.3 at most and 0.1 at the least and successChance must be 0.7 at least and 0.9 at the most
    public void routeRate() {
        float passRate = rando.nextFloat();
        float failRate = (1-passRate);
        if (passRate < 0.7 || passRate > 0.9) {
            while (passRate < 0.7 || passRate > 0.9) {
                passRate = rando.nextFloat();//declaring new pass rate
                failRate = (1-passRate);//declaring new fail rate
            }
            //printing new pass and fail rates
            System.out.print("Pass Rate: ");
            System.out.printf("%.2f", passRate*100);
            System.out.print(" %\n");
            //System.out.println("\nFail Rate: "+failRate);
        }
        else {//keeping first pass and fail rates
            System.out.print("\n Pass Rate: ");
            System.out.printf("%.2f", passRate*100);
            System.out.print(" %\n");
            //System.out.println("\nFail Rate: "+failRate);
        }
    }

    public void attemptRate() {
        routeRate();
        float attempt = rando.nextFloat();
        System.out.println("Route pass rate is ");
        System.out.printf("%.2f", passRate*100);
        System.out.print(" %");
        //System.out.println("\nAttempt chance is "+(attempt*100)+"\n");
        
        if (attempt <= passRate) {
            System.out.println("\nRoute passed\n");
        }
        else {
            System.out.println("\nRoute failed\n");
        }
    }

    }

RUNTIME NOTES

change line 48 "

change "Add to caravan function to add, first random generator car and store in array list for caravan and also create that caravan.

add values of capacity count to an arrayList, inseart them as integers per index then create a sort by lasrgest to smallest or smallest to largest to print them as the

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.