miguelangeltamargo / routerunner Goto Github PK
View Code? Open in Web Editor NEWProgramming II Assignment 1
Programming II Assignment 1
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;
}
}
}
}
}
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");
}
}
}
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.