Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, please provide solution answer, thank you! Below is a working Name class with the following behavior: - Constructor - A getformal method that returns

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedJava, please provide solution answer, thank you!

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 f rom 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. 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); 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: the program should produce the following output: 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 initi - . r t. 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. 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. Additional Notes: - names.text should not be modified Instructor Notes: [notes toc="Lab 3.1: A Class Named Name (Name)" nonum="yes"] - There is a compilation error in your submission. Compiler Errors Name.java: 10: error: cannot find symbol Scanner scanner = new Scanner(new File("names.text")); symbol: class Scanner location: class Name Name.java: 10: error: cannot find symbol Scanner scanner = new Scanner(new File("names.text")); symbol: class Scanner location: class Name Name.java: 10: error: cannot find symbol Scanner scanner = new Scanner(new File("names.text")); symbol: class File location: class Name Name.java: 20: error: cannot find symbol HashSet set = new HashSet String >(); n symbol: class HashSet location: class Name Name.java: 20: error: cannot find symbol WorkArea Results name =read(scanner); 3 System.out.println("---"); System.out.println(count + " names processed."); 3 83 9 Solution 80 class NameApp \{ 81 public static void main(String [] args) throws Exception \{ Name name = new Name ("Weiss", "Gerald"); Name.main(null); 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions

Question

Discuss the degrees of performance.

Answered: 1 week ago

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago