Forum Comments

Java Coding Jam Kahoots 5/16 and 5/23
In Java Question Bank
2D Arrays 05/01/2020
In Java Question Bank
2D Arrays 05/01/2020
In Java Question Bank
2.1 What does this program do?
In ACSL Contest Prep
mr.ricklu
Apr 14, 2019
RI
0
0
11.1 What's a digital circuit? What is a digital signal?
In ACSL Contest Prep
mr.ricklu
Mar 31, 2019
3. !A 4. 4
0
0
2.4 How to come up with problem solving steps and write them in pseudo code?
In ACSL Contest Prep
mr.ricklu
Mar 02, 2019
import java.util.Scanner; class Board{ int[] aPos; int tile; Board(int[] aPos, int tile){ this.aPos = aPos; this.tile = tile; } public boolean check(int[] pos){ if(pos[0]==aPos[0] && (pos[1]==aPos[1] || pos[1]==aPos[1]+1)) return false; else if(pos[0]==aPos[0]-1 && (pos[1]==aPos[1] || pos[1]==aPos[1]+1)) return false; else if(pos[0]==aPos[0] && pos[1]==aPos[1]-1) return false; else if(pos[0]==aPos[0] && pos[1]==aPos[1]+2) return false; else if(pos[0]==aPos[0]+1 && (pos[1]==aPos[1] || pos[1]==aPos[1]+1)) return false; else if(pos[0]>9 || pos[0]<0 || pos[1]>9 || pos[1]<0) return false; else return true; } public boolean placeA(int[] temPos){ int pos[] = temPos.clone(); if(tile == 2) pos[1]--; if(check(pos)){ pos[1]++; return check(pos); } else return false; } public boolean placeB(int[] temPos){ int pos[] = temPos.clone(); if(tile != 1){ pos[1]--; if(tile == 3) pos[0]++; } if(check(pos)){ pos[1]++; if(check(pos)){ pos[0]--; return check(pos); } else return false; } else return false; } public boolean placeC(int[] temPos){ int pos[] = temPos.clone(); if(tile != 1){ pos[0]++; if(tile == 2) pos[1]++; if(tile == 4) pos[1]--; } if(check(pos)){ pos[0]--; if(check(pos)){ pos[1]--; if(check(pos)){ pos[1] += 2; return check(pos); } else return false; } else return false; } else return false; } public boolean placeD(int[] temPos){ int pos[] = temPos.clone(); if(tile != 1){ pos[0]++; if(tile != 3){ pos[1]++; if(tile == 4) pos[0]++; } } if(check(pos)){ pos[0]--; if(check(pos)){ pos[1]--; if(check(pos)){ pos[0] --; return check(pos); } else{ return false; } } else{ return false; } } else{ return false; } } public String[] getOutputs(int aTile){ boolean[] booleanOutputs = new boolean[4]; int[] pos1 = new int[2]; int[] pos2 = new int[2]; if(aTile == 1){ pos1[0] = aPos[0]+1; pos1[1] = aPos[1]-1; pos2[0] = aPos[0]-1; pos2[1] = aPos[1]-1; } else{ pos1[0] = aPos[0]+1; pos1[1] = aPos[1]+2; pos2[0] = aPos[0]-1; pos2[1] = aPos[1]+2; } if(placeA(pos1) || placeA(pos2)) booleanOutputs[0] = true; if(placeB(pos1) || placeB(pos2)) booleanOutputs[1] = true; if(placeC(pos1) || placeC(pos2)) booleanOutputs[2] = true; if(placeD(pos1) || placeD(pos2)) booleanOutputs[3] = true; int count = 0; for(boolean i : booleanOutputs) if(i) count++; String outputs[] = new String[count]; int i = 0; if(booleanOutputs[0]){ outputs[i] = "A"; i++; } if(booleanOutputs[1]){ outputs[i] = "B"; i++; } if(booleanOutputs[2]){ outputs[i] = "C"; i++; } if(booleanOutputs[3]){ outputs[i] = "D"; i++; } return outputs; } } class Main { public static int translate(String input){ int output = 0; switch(input){ case "A": output = 0; break; case "B": output = 1; break; case "C": output = 2; break; case "D": output = 3; break; case "E": output = 4; break; case "F": output = 5; break; case "G": output = 6; break; case "H": output = 7; break; case "I": output = 8; break; case "J": output = 9; break; } return output; } public static void main(String[] args) { Scanner in = new Scanner(System.in); for(int i=0; i<5; i++){ String inputs[] = in.nextLine().split(", "); int[] aPos = {translate(inputs[0].charAt(0)+""),inputs[0].charAt(1)-49}; Board blokus = new Board(aPos,Integer.parseInt(inputs[2])); String outputs[] = blokus.getOutputs(Integer.parseInt(inputs[1])); if(outputs.length!=0){ for(int j=0; j<outputs.length; j++){ System.out.print(outputs[j]); if(j!=outputs.length-1) System.out.print(", "); } System.out.println(""); } else System.out.println("NONE"); } } }
1
0
7-1 Why prefix or post fix notations are used in computers?
In ACSL Contest Prep
3.1 What is a function? What is a recursive function?
In ACSL Contest Prep
mr.ricklu
Dec 06, 2018
1. 79 2. 6 5. 5,6,5,12
1
0
2-6 What is a good way to learn coding?
In ACSL Contest Prep
mr.ricklu
Nov 25, 2018
import java.util.*; import java.io.*; class Scrabble { public static int getLetterValue(String letter){ int lettervalue = 0; switch (letter){ case "A": lettervalue = 1; break; case "E": lettervalue = 1; break; case "D": lettervalue = 2; break; case "R": lettervalue = 2; break; case "B": lettervalue = 3; break; case "M": lettervalue = 3; break; case "V": lettervalue = 4; break; case "Y": lettervalue = 4; break; case "J": lettervalue = 8; break; case "X": lettervalue = 8; break; default: break; } return lettervalue; } public static boolean isHorizontal(String input){ boolean horizontal = false; if(input.equals("H")){horizontal=true;} return horizontal; } public static int getLetterMultiplier(int position){ int multiplier = 1; if(position%3 == 0 && position%2 != 0){multiplier = 2;} else if(position%5 == 0){multiplier = 3;} return multiplier; } public static int getWordValue(String word, int firstLetterPosition, boolean horizontal){ int wordvalue = 0; if(horizontal){ for(int i=0; i<4; i++){ wordvalue += getLetterValue(word.charAt(i)+"")*getLetterMultiplier(firstLetterPosition+i); } } else{ for(int i=0; i<4; i++){ wordvalue += getLetterValue(word.charAt(i)+"")*getLetterMultiplier(firstLetterPosition+ i*10); } } return wordvalue; } public static int getWordMultiplier(int firstLetterPosition, boolean horizontal){ int multiplier = 1; if(horizontal){ for(int i=firstLetterPosition; i<firstLetterPosition+4; i++){ if(i%7 == 0 && getLetterMultiplier(i)==1){multiplier = 2;} else if(i%8 == 0 && getLetterMultiplier(i)==1 && multiplier == 1){multiplier = 3;} } } else{ for(int i=0; i<4; i++){ if((i*10 +firstLetterPosition)%7 == 0 && getLetterMultiplier(i*10 +firstLetterPosition)==1){multiplier = 2;} else if((i*10 +firstLetterPosition)%8 == 0 && getLetterMultiplier(i*10 +firstLetterPosition)==1 && multiplier == 1){multiplier = 3;} } } return multiplier; } public static int getPoints(String word, int firstLetterPosition, boolean horizontal){ return getWordValue(word, firstLetterPosition, horizontal) * getWordMultiplier(firstLetterPosition, horizontal); } public static void main(String[] args) throws IOException{ Scanner Howard = new Scanner(new FileReader("data/input.txt")); String input = Howard.nextLine().replaceAll(", ", ""); for(int i=0; i<5; i++){ String info[] = Howard.nextLine().split(", "); int position = Integer.parseInt(info[0]); boolean horizontal = isHorizontal(info[1]); System.out.println(getPoints(input, position, horizontal)); } } }
0
0
7.1 What is a function or method?
In Introduction to Java
mr.ricklu
Nov 14, 2018
import java.util.Scanner; import java.io.*; class Timesheet { public static double getTime(String timeCode){ double time = 0; switch(timeCode){ case "1": time = 9; break; case "2": time = 9.5; break; case "3": time = 10; break; case "4": time = 10.5; break; case "5": time = 11; break; case "6": time = 11.5; break; case "7": time = 12; break; case "8": time = 12.5; break; case "9": time = 13; break; case "A": time = 13.5; break; case "B": time = 14; break; case "C": time = 14.5; break; case "D": time = 15; break; case "E": time = 15.5; break; case "F": time = 16; break; case "G": time = 16.5; break; case "H": time = 17; break; default: System.exit(1); } return time; } public static double subtractHours(String start, String end){ return getTime(end) - getTime(start); } public static double getRegularRate(int location){ double regularRate = 0; if(location<=199){regularRate = 10;} else if(location>=200 && location<=299){regularRate = 7.5;} else if(location>=300 && location<=399){regularRate = 9.25;} else if(location>=400 && location<=499){regularRate = 6.75;} else{regularRate = 8;} return regularRate; } public static double getOvertimeRate(int location){ double overtimeRate = 0; if(location<=199){overtimeRate = 15;} else if(location>=200 && location<=299){overtimeRate = 15;} else if(location>=300 && location<=399){overtimeRate = 10.5;} else if(location>=400 && location<=499){overtimeRate = 13.5;} else{overtimeRate = 12;} return overtimeRate; } public static double getHoursOfOvertime(int location, int day, double totalhours){ double hours = 0; if(location<=199){ hours = Math.max(0, totalhours-5); } else if(location>=200 && location<=299){ hours = Math.max(0, totalhours-6); } else if(location>=300 && location<=399){ hours = Math.max(0, totalhours-4); } else if(location>=400 && location<=499){ if(day==1 || day==7){hours = totalhours;} } else{ hours = Math.max(0, totalhours-6); } return hours; } public static double getPay(int location, int day, String start, String end){ double hours = subtractHours(start, end); double pay = (hours-getHoursOfOvertime(location, day, hours))*getRegularRate(location); pay += getHoursOfOvertime(location, day, hours) * getOvertimeRate(location); return pay; } public static void main(String[] args) throws IOException { Scanner leslie = new Scanner(new FileReader("data/input.txt")); for(int i=0; i<5; i++){ String inputs[] = leslie.nextLine().split(", "); double pay = getPay(Integer.parseInt(inputs[0]), Integer.parseInt(inputs[1]), inputs[2], inputs[3]); pay += getPay(Integer.parseInt(inputs[4]), Integer.parseInt(inputs[5]), inputs[6], inputs[7]); System.out.print("$" + pay); if((pay*100)%10 == 0){System.out.println("0");} else{System.out.println();} } } }
1
1
Classes and Objects Lesson 4 - Organizing Classes and Passing Objects to Methods
In AP Computer Science A
mr.ricklu
Oct 06, 2018
import java.io.*; import java.util.Scanner; class Player2 { private double data[][] = new double[10][3]; //stores all the inut data of each player private double everyoneannsal[] = new double[10]; //stores every player's annual salary private double everyonepergamesal[] = new double[10]; //stores every player's per game salary private double everyoneexpectval[] = new double[10]; //stores every player's contract's expected value //takes in a player and the number of games in a season and returns the expected value of the player's contract public double getExpectedValue(int forwho, int numberofgames){ double chanceofinjury = 0; if(numberofgames == 18){chanceofinjury = 0.03375;} else{chanceofinjury = 0.03;} return (1- data[forwho][0]*chanceofinjury)*data[forwho][1] + data[forwho][0]*chanceofinjury*data[forwho][2]; } //takes in the number of games in the season and returns an array containing every player's contract's expected value public double[] getEveryoneExpectVal(int numberofgames){ for(int i=0; i<10; i++){ everyoneexpectval[i] = getExpectedValue(i, numberofgames); } return everyoneexpectval; } //takes in the number of games in a season and an expected value and returns which player's it is public double findWhoseExepctVal(int numberofgames, double expectedvalue){ int whose = -1; for(int i=0; i<10; i++){ if(getEveryoneExpectVal(numberofgames)[i]==expectedvalue){ whose = i; } } return whose+1; } //takes in a player and returns their annual salary public double getAnnualSalary(int forwho){ return data[forwho][1]/data[forwho][0]; } //returns an array containing every player's annual salary public double[] getEveryoneAnnSal(){ for(int i=0; i<10; i++){ everyoneannsal[i] = getAnnualSalary(i); } return everyoneannsal; } //takes in the number of games in a season and a player and returns their per game salary public double getPerGameSalary(int numberofgames, int forwho){ return getAnnualSalary(forwho)/numberofgames; } //takes in the number of games in a season and returns an array containing every player's per game salary public double[] getEveryonePerGameSal(int numberofgames){ for(int i=0; i<10; i++){ everyonepergamesal[i] = getPerGameSalary(numberofgames, i); } return everyonepergamesal; } //takes in an array and returns the average value of all the elements in the array public double getAverage(double[] ofwhat){ double sum = 0; for(int i=0; i<ofwhat.length; i++){ sum = sum + ofwhat[i]; } return sum/ofwhat.length; } //takes in an array and returns that array but sorted from least to greatest public double[] sort(double[] what){ double temp; double sortthis[] = what; for (int i=1; i<what.length; i++){ for (int j=i; j>0; j--){ if (sortthis[j]<sortthis[j-1]){ temp = sortthis[j]; sortthis[j] = sortthis[j-1]; sortthis[j-1] = temp; } } } return sortthis; } //processes the input data and puts it into an array Player2() throws IOException{ Scanner TomBrady = new Scanner(new FileReader("data/input.txt")); for(int i=0; i<10; i++){ String input = TomBrady.nextLine(); String inputs[] = input.split(", "); data[i][0] = Double.parseDouble(inputs[0]); data[i][1] = Double.parseDouble(inputs[1])*1000000; data[i][2] = Double.parseDouble(inputs[2])*1000000; } } public static void main(String[] args) throws IOException{ Player2 Contracts = new Player2(); System.out.println(Math.round(Contracts.sort(Contracts.getEveryonePerGameSal(16))[9] - Contracts.sort(Contracts.getEveryonePerGameSal(16))[0])); System.out.println(Math.round((Contracts.sort(Contracts.getEveryonePerGameSal(18))[9] + Contracts.sort(Contracts.getEveryonePerGameSal(18))[0])/2)); double highestexpectval = Contracts.sort(Contracts.getEveryoneExpectVal(16))[9]; System.out.println(Math.round(highestexpectval) + " by #" + Math.round(Contracts.findWhoseExepctVal(16, highestexpectval))); System.out.println(Math.round(Contracts.getAverage(Contracts.getEveryoneExpectVal(18)))); System.out.println(Math.round((Contracts.sort(Contracts.getEveryoneAnnSal())[4] + Contracts.sort(Contracts.getEveryoneAnnSal())[5])/2)); } }
0
Classes and Objects Lesson 4 - Organizing Classes and Passing Objects to Methods
In AP Computer Science A
mr.ricklu
Oct 06, 2018
import java.io.*; import java.util.Scanner; class Player1 { private double data[][] = new double[5][2]; //stores all the input data private double everyoneannualsalary[] = new double[5]; //stores all the annual salaries private double everyonepergamesalary[] = new double[5]; //stores all the per game salaries //takes in a player returns their annual salary public double getAnnualSalary(int forwho){ return data[forwho][1]/data[forwho][0]; } //returns an array containing everyone's annual salary public double[] getEveryoneAnnualSalary(){ for(int i=0; i<5; i++){ everyoneannualsalary[i] = getAnnualSalary(i); } return everyoneannualsalary; } //takes in an amount returns the number of salaries above the amount public int getSalariesAboveAmount(double amount){ int count = 0; for(int i=0; i<5; i++){ if(getAnnualSalary(i)>amount){count++;} } return count; } //takes in a player and the number of games in a season and returns their per game salary public double getPerGameSalary(double annualsalary, int numberofgames){ return annualsalary/numberofgames; } //takes in th number of games in a season and returns an array containing everyone's per game salary public double[] getEveryonePerGameSalary(int numberofgames){ for(int i=0; i<5; i++){ everyonepergamesalary[i] = getPerGameSalary(getAnnualSalary(i), numberofgames); } return everyonepergamesalary; } //takes in an array returns the average value of the array public double getAverage(double[] ofwhat){ double sum = 0; for(int i=0; i<5; i++){ sum = sum + ofwhat[i]; } return sum/ofwhat.length; } //takes in an array and returns the greatest value in the array public double getHighest(double[] ofwhat){ double max = ofwhat[0]; for(int i=0; i<4; i++){ if(max<ofwhat[i+1]){ max = ofwhat[i+1]; } } return max; } //takes in an array and returns the lowest value in the array public double getLowest(double[] ofwhat){ double min = ofwhat[0]; for(int i=0; i<4; i++){ if(min>ofwhat[i+1]){ min = ofwhat[i+1]; } } return min; } //processes all the input data and puts it into an array Player1() throws IOException{ Scanner TomBrady = new Scanner(new FileReader("data/input.java")); for(int i=0; i<5; i++){ String input = TomBrady.nextLine(); String inputs[] = input.split(", "); data[i][0] = Double.parseDouble(inputs[0]); data[i][1] = Double.parseDouble(inputs[1])*1000000; } } public static void main(String[] args) throws IOException{ Player1 Salaries = new Player1(); System.out.println(Math.round(Salaries.getSalariesAboveAmount(10000000))); System.out.println(Math.round(Salaries.getAverage(Salaries.getEveryoneAnnualSalary()))); System.out.println(Math.round(Salaries.getLowest(Salaries.getEveryonePerGameSalary(16)))); System.out.println(Math.round(Salaries.getHighest(Salaries.getEveryonePerGameSalary(18)))); System.out.println(Math.round((Salaries.getAverage(Salaries.getEveryonePerGameSalary(16)))-(Salaries.getAverage(Salaries.getEveryonePerGameSalary(18))))); } }
0
1
Classes and Objects Lesson 3 - Define Classes and Create Objects Part 2
In AP Computer Science A
mr.ricklu
Sep 29, 2018
1. import java.io.IOException; import java.io.FileReader; import java.util.*; class Word { String input; public int getPoints(int position){ int points = 0; int multiplier = 1; for(int j=0; j<4; j++){ int lettervalue = 0; double letterpos = position + j; switch (input.charAt(j)+""){ case "A": lettervalue = 1; break; case "E": lettervalue = 1; break; case "D": lettervalue = 2; break; case "R": lettervalue = 2; break; case "B": lettervalue = 3; break; case "M": lettervalue = 3; break; case "V": lettervalue = 4; break; case "Y": lettervalue = 4; break; case "J": lettervalue = 8; break; case "X": lettervalue = 8; break; default: break; } if(letterpos%3==0 && letterpos%2!=0){ lettervalue = lettervalue*2; } else if(letterpos%5==0){ lettervalue = lettervalue*3; } else if(letterpos%7==0 && multiplier==1){ multiplier = 2; } else if(letterpos%8==0 && multiplier==1){ multiplier = 3; } points = points + lettervalue; } return points*multiplier; } Word(String input){ this.input = input; } public static void main(String[] args) throws IOException { Scanner Howard = new Scanner(new FileReader("data/input.txt")); Word obj1 = new Word(Howard.nextLine()); for(int i=0; i<5; i++){ System.out.println(obj1.getPoints(Howard.nextInt())); } } } 2. import java.io.IOException; import java.io.FileReader; import java.util.*; class Vehicle{ int milesPerGallon; int averageSpeed; public String getTimeTravelled(int distance){ int hours = distance/averageSpeed; int minutes = (int)Math.round((distance%averageSpeed)/((double)averageSpeed)*60); String returnHours = "" + hours; String returnMinutes = "" + minutes; if(hours<9){returnHours = "0" + hours;} if(minutes<9){returnMinutes = "0" + minutes;} return returnHours + ":" + returnMinutes; } public String getGasPrice(double prices, int distance){ double roundPrice = Math.round(prices*100.0*distance/milesPerGallon)/100.0; String finalPrice = "$" + roundPrice; if(((roundPrice*10)%1)/10 == 0){finalPrice = finalPrice + "0";} return finalPrice; } Vehicle(int milesPerGallon, int averageSpeed){ this.milesPerGallon = milesPerGallon; this.averageSpeed = averageSpeed; } } class Trip{ String[] startAndEndCity = new String[2]; double gasPriceToday; int[] distances = {450,140,120,320,250,80}; public int getDistance(){ int[] endpoints = new int[2]; for(int i=0; i<2; i++){ switch(startAndEndCity[i]){ case "A": endpoints[i] = 0; break; case "B": endpoints[i] = 1; break; case "C": endpoints[i] = 2; break; case "D": endpoints[i] = 3; break; case "E": endpoints[i] = 4; break; case "F": endpoints[i] = 5; break; case "G": endpoints[i] = 6; break; default: break; } } int totaldistance = 0; for(int i=endpoints[0]; i<endpoints[1]; i++){ totaldistance = totaldistance + distances[i]; } return totaldistance; } Trip(String startCity, String endCity, double gasPriceToday){ startAndEndCity[0] = startCity; startAndEndCity[1] = endCity; this.gasPriceToday = gasPriceToday; } } class RouteStats { public static void main(String[] args) throws IOException { Scanner Meredith = new Scanner(new FileReader("data/input.txt")); String[] input = Meredith.nextLine().split(", "); Vehicle Car = new Vehicle(Integer.parseInt(input[0]), Integer.parseInt(input[2])); for(int i=0; i<5; i++){ String[] endpoints = Meredith.nextLine().split(", "); Trip Vacation = new Trip(endpoints[0], endpoints[1], Double.parseDouble(input[1])); System.out.print(Vacation.getDistance() + ", "); System.out.print(Car.getTimeTravelled(Vacation.getDistance()) + ", "); System.out.println(Car.getGasPrice(Vacation.gasPriceToday, Vacation.getDistance())); } } }
1
0
Classes and Objects Lesson 2 - Define a class and create objects part 1
In AP Computer Science A
mr.ricklu
Sep 22, 2018
1. class Person { int age; String name; double height; String gender; String nationality; public void changeName(String newName){ name = newName; } public void waitYears(int numberOfYears){ age += numberOfYears; } public void grow(double growth){ height += growth; } public void changeCitizenship(String newCountry){ nationality = newCountry; } public static void main(String[] args) { Person MarkWatney = new Person(); MarkWatney.nationality = "American"; MarkWatney.changeCitizenship("Martian"); System.out.println(MarkWatney.nationality); Person Dwarf = new Person(); Dwarf.name = "Shorty"; Dwarf.height = 100; Dwarf.age = 12; Dwarf.waitYears(5); Dwarf.grow(100); Dwarf.changeName("Giant"); System.out.println(Dwarf.name + " is now " + Dwarf.height + " cm tall and " + Dwarf.age + " years old."); } } class Circle { double radius; public double findArea(){ return radius*radius*Math.PI; } public double findCircumfrence(){ return radius*2*Math.PI; } public void scale(double scalar){ radius = radius*scalar; } public static void main(String[] args) { Circle circleX = new Circle(); circleX.radius = 67; System.out.println(circleX.findArea()); Circle roundBoi = new Circle(); roundBoi.radius = 0.5/Math.PI; System.out.println(roundBoi.findCircumfrence()); roundBoi.scale(6); System.out.println(roundBoi.findCircumfrence()); } } class Car { String colour; double speed; double timeDriving; String licensePlate; double fuelEfficiency; double maxFuel; double currentFuel; public void accelerate(double acceleration){ if(maxFuel>=((speed + acceleration)*timeDriving/fuelEfficiency)){ speed = speed + acceleration; currentFuel = maxFuel-(speed*timeDriving/fuelEfficiency); } else{ speed = 0; currentFuel = 0; } } public void fillTank(){ currentFuel = maxFuel; } public void paintCar(String newColour){ colour = newColour; } public Car(){ speed = 0; timeDriving = 0; } public static void main(String[] args) { Car Ford = new Car(); Ford.colour = "Red"; Ford.paintCar("Green"); System.out.println(Ford.colour); Car USSEnterprise = new Car(); USSEnterprise.maxFuel = 999999999; USSEnterprise.fillTank(); USSEnterprise.fuelEfficiency = 100; USSEnterprise.timeDriving = 48; USSEnterprise.accelerate(300000000); System.out.println(USSEnterprise.currentFuel); } } 2. import java.util.*; class Driving { public static void main(String[] args) { Scanner Meredith = new Scanner(System.in); String input = Meredith.nextLine(); String[] parts = input.split(", "); double gallon = Double.parseDouble(parts[0]); double price = Double.parseDouble(parts[1]); double speed = Double.parseDouble(parts[2]); int[] distances = {450,140,120,320,250,80}; for(int i=0; i<5; i++){ String route = Meredith.nextLine(); String[] components = route.split(", "); int[] endpoints = new int[2]; for(int j=0; j<2; j++){ switch(components[j]){ case "A": endpoints[j] = 0; break; case "B": endpoints[j] = 1; break; case "C": endpoints[j] = 2; break; case "D": endpoints[j] = 3; break; case "E": endpoints[j] = 4; break; case "F": endpoints[j] = 5; break; case "G": endpoints[j] = 6; break; default: break; } } double totaldistance = 0; for(int j=endpoints[0]; j<endpoints[1]; j++){ totaldistance = totaldistance + distances[j]; } System.out.print(totaldistance + ", "); int hours = (int)(totaldistance/speed); int minutes = (int)Math.round((totaldistance%speed)/speed*60); if(hours>9){System.out.print(hours + ":");} else{System.out.print("0" + hours + ":");} if(minutes>9){System.out.print(minutes + ", ");} else{System.out.print("0" + minutes + ", ");} double totalprice = Math.round((totaldistance/gallon*price)*100)/100.0; System.out.print("$" + totalprice); if(((totalprice*10)%1)/10 == 0){System.out.println(0);} else{System.out.println();} } } }
0
0
m
mr.ricklu
More actions