You are tasked with the job of scanning names and putting them in bins by their first
Question:
- You are tasked with the job of scanning names and putting them in bins by their first letter.
- You will only need to bin names starting with 'A', 'B', 'C','D'
- If the user gives you a name that doesn't start with the above letter, prompt for a different name.
- No names will start with lower case letters.
- The first name you see starting with A should go into A Names at index 0. The second A name at index 1. The third at 2, etc.
- The first name you see starting with B should go into B Names at index 0. The second B name at index 1. The third at 2, etc.
- The first name you see starting with C should go into C Names at index 0. The second C name at index 1. The third at 2, etc.
- The first name you see starting with D should go into D Names at index 0. The second D name at index 1. The third at 2, etc.
- No test cases will have more than 5 names per bin.
- The arrays have already been created for you.
- You should use a switch statement for this exercise.
- When you finish binning, call print Bins() with you four arrays as input.
Given Code:
import java.util.Scanner;
public class NameBins {public static void printBins(String[] A, String[] B, String[] C,String[] D){String [][] names={A, B, C, D};for(int binNo = 0; binNo if(names[binNo][0]!="NOTANAME"){System.out.print("Names starting with " + (char)(binNo + 65) + ":");for(int name = 0; name if(names[binNo][name] != "NOTANAME"){System.out.print(names[binNo][name]);if(name+1 System.out.print(", ");}}}System.out.println("");}}}public static void main(String[] args) {String [] ANames = new String[5];String [] BNames = new String[5];String [] CNames = new String[5];String [] DNames = new String[5];for (int x = 0; xANames[x] = BNames[x] = CNames[x] = DNames[x] = "NOTANAME";}int a = 0; //use this as the counter for the index of ANamesint b = 0; //use this as the counter for the index of BNamesint c = 0; //use this as the counter for the index of CNamesint d = 0; //use this as the counter for the index of DNamesScanner scnr = new Scanner(System.in);String nextName = scnr.next();while (!nextName.equals("-1")){//Write your logic here.//Put each name into a bin as it comes in from scanner.nextName = scnr.next();}}}
Output Examples
Transportation A Global Supply Chain Perspective
ISBN: 9781337406642
9th Edition
Authors: Robert A. Novack, Brian Gibson, Yoshinori Suzuki, John J. Coyle