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

You are given a file of customer data with records in the following format : acc

ID: 3567347 • Letter: Y

Question

You are given a file of customer data with records in the following format : account number, last name, first name, middle name. Write a program to convert the input data and display it to the monitor in the following format : Accout Name Logon ID Initial Pswd 21-88282712-B Samuel K. Adams ADAM21 Adam88282 08-36847734-A John Sturm STUR08 Stur36847 etc. Notes : 1) The account number on the input is 10 digits 2) The names on the input file are 2 strings. The first incoming name string variable has last name, comma and first name in it. The second one contains the middle name. 3) The outputted account must contain hyphens as shown above. The first 2 digits of the account determine the letter at the end of the outputted account : For instance, if the first 2 digits are between 01 and 10 inclusive, the ending letter is A, if the first 2 digits are between 11 and 20 inclusive, the ending letter is B, and so on.. 4) The ouputted name is : first name, middle initial, last name. Use the string function find to find the index of , ; the function length to find the length of the string; and the function substr to extract the first name, last name and middle initial. See table 7-1 in the textbook. 5) Logon ID is formed by taking first 4 characters of last name and making them uppercase, then appending the first 2 digits of the account number. The toupper(x) function can be used to obtain the uppercases of the letter. 6) Initial Pswd consists of up to the first 4 characters of last name and the third to seventh digits of account number 7) Include the column headings in the output and be sure the columns are centered under the headings.

Explanation / Answer

Program code:

//Customer class

public class Customer

{

     //declare the required variables

     String accnum, lname, fname, mname;

     //constuctor

     public Customer(String anum, String lastname, String firstname, String midname)

     {

          accnum=anum;

          lname=lastname;

          fname=firstname;

          mname=midname;

     }

     //get methods to retrieve the values of the

     //instance variables

     public String getAccount()

     {

          return accnum;

     }

     public String getLname()

     {

          return lname;

     }

     public String getFname()

     {

          return fname;

     }

     public String getMname()

     {

          return mname;

     }

     //to modify the Account format and the

     //return the modified account

     public String modifiedAccount()

     {

          String acc, anum;

          int num;

          anum=getAccount().substring(0, 2);

          acc=getAccount().substring(0,2)+'-'+getAccount().substring(2);

          num=Integer.parseInt(anum);

          if(num>=01 && num <=10)

          {

              acc+="-A";

          }

          else if(num>=11 && num <=20)

          {

              acc+="-B";

          }

          else if(num>=21 && num <=30)

          {

              acc+="-C";

          }

          else if(num>=31 && num <=40)

          {

              acc+="-D";

          }

          else if(num>=41 && num <=50)

          {

              acc+="-E";

          }

          else if(num>=51 && num <=60)

          {

              acc+="-F";

          }

          else if(num>=61 && num <=70)

          {

              acc+="-G";

          }

          else if(num>=71 && num <=80)

          {

              acc+="-H";

          }

          else if(num>=81 && num <=90)

          {

              acc+="-I";

          }

          else if(num>=91)

          {

              acc+="-J";

          }

          return acc;

     }

     //to format the logonId

     public String getLogOn()

     {

          String str;

          str=getLname().substring(0, 4).toUpperCase();

          str+=getAccount().substring(0,2);

          return str;

     }

     //to format the Password

     public String getInitialPwd()

     {

          String str;

          str=getLname().substring(0, 4).toUpperCase();

          str+=getAccount().substring(2,7);

          return str;

     }

     //to set the complete name

     public String getName()

     {

          String name;

          name=getFname()+" "+getMname().substring(0,1)+"."+getLname();

          return name;

     }

   

}

import java.io.*;

import java.util.*;

public class CustomerDetials

{

     //main function

     public static void main(String args[])throws Exception

     {

          //declare the required variable

        

          String []str;

          //scanner object to read the data from the text file

          Scanner in=new Scanner(new FileReader(new File("CustomerData")));

          //Customer array list, to store the objects of the

          //customer class

          ArrayList<Customer> cust=new ArrayList<Customer>();

          String line="";

          //until the end of the text file

          //get the each line and split at ','

          while(in.hasNextLine())

          {

              line=in.nextLine();

              str=line.split(",");

              //create object of the Customer class

              Customer c=new Customer(str[0], str[1], str[2], str[3]);

              //add the object to the arraylist

              cust.add(c);

          }

          //close the file

          in.close();

          //create variables to set the alignment

          String ac="Account";

          String name="Name";

          String lg="LogonID";

          String ini="InitialPswd";

          //set the string format for heading

          String heading=" %10s %10s %25s %20s ";

          //set the table info in a format

          String leftAlignFormat = " %s %10s %20s %20s ";

          System.out.format(heading, ac,name,lg,ini);

          System.out.println();

          System.out.println("========================================================================");

          //print the output to the console

          for(int i=0; i< cust.size();i++)

          {

              System.out.format(leftAlignFormat, cust.get(i).modifiedAccount(),cust.get(i).getName(),

                        cust.get(i).getLogOn(), cust.get(i).getInitialPwd());

              System.out.println();

          }

          System.out.println("=========================================================================");

        

     }

}

Sample Output:

    Account        Name                   LogonID          InitialPswd

======================================================================

12-34567890-B Samuel K.Adam               ADAM12           ADAM34567

09-87654321-A William J.Kingston          KING09           KING87654

56-88754321-F Samantha R.William          WILL56           WILL88754

83-41222308-I Johny L.Jane                JANE83           JANE41222

======================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote