+ 2

New Driver's License

HI! I had completed this task, but I'm not sure that this solution is the best one. Any ideas how to complete this task more professional and easier? 😅 import java.util.Scanner; import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; public class Program { public static void main(String[] args) { Scanner inputs = new Scanner(System.in); String me = inputs.nextLine(); String ag = inputs.nextLine(); String in = inputs.nextLine(); String[] inPeople = in.split(" "); ArrayList<String> otherPeople = new ArrayList<String>(Arrays.asList(inPeople)); otherPeople.add(me); Collections.sort(otherPeople); int myPosition = otherPeople.indexOf(me) + 1; int agents = Integer.parseInt(ag); int timeToWait; switch (agents) { case 1: timeToWait = myPosition * 20; System.out.println(timeToWait); break; case 2: if (myPosition <= 2) { timeToWait = 20; } else if ((myPosition == 3) || (myPosition == 4)){ timeToWait = 40; } else { timeToWait = 60; } System.out.println(timeToWait); break; case 3: if (myPosition <= 3) { timeToWait = 20; } else { timeToWait = 40; } System.out.println(timeToWait); break; case 4: if (myPosition <= 4) { timeToWait = 20; } else { timeToWait = 40; } System.out.println(timeToWait); break; default: timeToWait = 20; System.out.println(timeToWait); } } }

1st Apr 2020, 2:59 AM
Mark Ivanov
Mark Ivanov - avatar
3 Réponses
+ 2
very cool! thank you!
1st Apr 2020, 4:21 AM
Mark Ivanov
Mark Ivanov - avatar
0
Simple Python solution for this problem https://www.sololearn.com/coach/18?ref=app
13th Aug 2020, 9:00 PM
Harsh Singhaniya
Harsh Singhaniya - avatar