Question: Please code the following in java according to the specifications: Below is a working Name class with the following behavior: Constructor A getFormal method that

Please code the following in java according to the specifications:

Please code the following in java according to the specifications: Below is

a working Name class with the following behavior: Constructor A getFormal method

that returns the first name followed by the last name (separated bya space) A getofficial method that returns the last name followed by

a comma and space), followed by the first name tostring and equals

Below is a working Name class with the following behavior: Constructor A getFormal method that returns the first name followed by the last name (separated by a space) A getofficial method that returns the last name followed by a comma and space), followed by the first name tostring and equals methods A class (i.e., static) method named read that is passed a scanner object and returns a Name object created from data (last and first names) read in from the scanner. A main method that reads in Name objects, prints out the formal and official versions of the name and keeps count of how many names were processed. import java.io.*; import java.util.*; class Name { public Name (String last, String first) { this. last = last; this.first = first; } public Name (String first) {this("", first);} public String getFormal() {return first +""+ last;} public String getofficial() {return last + ", " + first;} public boolean equals(Name other) {return first.equals(other.first) && last .equals(other.last);} public String toString() {return first + "" + last;} public static Name read (Scanner scanner) { if (!scanner.hasNext()) return null; String last = scanner.next(); String first = scanner.next(); return new Name(last, first); } private String first, last; public static void main(String [] args) throws Exception { Scanner scanner = new Scanner(new File("names.text")); int count = 0; Name name = read(scanner); while(name != null) { System.out.println("formal: " + name.getFormal(); System.out.println("official: " + name.getOfficial(); System.out.println(); count++; name = read(scanner); } System.out.println("---"); System.out.println(count + " names processed."); } Your job is to make the following changes: Add a getInitials method that returnd a string consisting of the first and last initials, each followed by a period (-). Add the following logic to main : Print out the Name object resd in using the tostring method Print out the Name 's initials (using the getInitials method). Add logic so that if two consecutive names match, and error message is printed. The name of your class should be Name . Plase remove the public attribute from your class definition (CodeLab restriction). For example, if the file names.text contains: Edwards Carter Carter Jackson Carter Evans White White Taylor Baker Young Hall Steven Joshua Joshua Anthony Barbara Edward Christopher Christopher Michelle Melissa Anthony Michael the program should produce the following output: name: Steven Edwards formal: Steven Edwards official: Edwards, Steven initials: S.E. name: Joshua Carter formal: Joshua Carter official: Carter, Joshua initials: J.C. Duplicate name "Joshua Carter" discovered name: Anthony Jackson formal: Anthony Jackson official: Jackson, Anthony initials: A.J. name: Barbara Carter formal: Barbara Carter official: Carter, Barbara initials: B.C. name: Edward Evans formal: Edward Evans official: Evans, Edward initials: E.E. name: Christopher White formal: Christopher White official: White, Christopher initials: C.W. Duplicate name "Christopher White" discovered name: Michelle Taylor formal: Michelle Taylor official: Taylor, Michelle initials: M.T. name: Melissa Baker formal: Melissa Baker official: Baker, Melissa initials: M.B. name: Anthony Young formal: Anthony Young official: Young, Anthony initials: A.Y. name: Michael Hall formal: Michael Hall official: Hall, Michael initials: M.H. 12 names processed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!