Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

TA Task #1 The Cryptology Division of Locklear Al Programming Inc. wants to crea

ID: 3757470 • Letter: T

Question

TA

Task #1 The Cryptology Division of Locklear Al Programming Inc. wants to create an automatic coding method for US Cities based on their name, state abbreviation, and population. This coding process involves the following procedure: . City Name City State City Population Code NewYork NY 9,000,00o 8-NY-9 1st Sequence number of characters in city name (counts white space) 2nd Sequence State Abbreviation 3rd Sequence Population divided by 1 million Create a single static method cityCoder that accepts three parameters corresponding to the city name, city abbreviation, and city population and produces the correct code for the city. fu dpmive Lodb Your method must have the following signature: . public static String cityCoder(String Cname, String Cstate, int Cpop)

Explanation / Answer

class code{
public static String cityCoder(String cname,String cstate,int cpop){ //Task #1
int pop=cpop/1000000;
String res=Integer.toString(cname.length())+"-"+cstate+"-"+Integer.toString(pop);
return res;
  
}
public static void citycodechart(String NArray[],String SArray[],int PArray[]){ //Task #2
for(int i=0;i<NArray.length;i++){
String result=cityCoder(NArray[i],SArray[i],PArray[i]);
if(i==0 || i==NArray.length-2)
System.out.println(NArray[i]+" "+SArray[i]+" "+PArray[i]+" "+result);
else
System.out.println(NArray[i]+" "+SArray[i]+" "+PArray[i]+" "+result);
}
}
  
}
public class HelloWorld{

public static void main(String []args){
code c1=new code();
String cityname[]={"Los Angeles","Chicago","Houston","Philadelphia","Phoenix"}; //Initializing city
String citystate[]={"LA","Il","TX","PA","AZ"}; //Initializing State
int population[]={3971883,2720546,2296224,1567442,1563025}; //Initializing population
System.out.println("City Name State Name Population City Code");
c1.citycodechart(cityname,citystate,population); //Calling the function with parameter.
}
}