Please help me with this a lab For this lab, implement the solutions to each of
ID: 3763600 • Letter: P
Question
Please help me with this a lab
For this lab, implement the solutions to each of the problems as private methods in a single class Lab11Solution . The main() method should simply invoke each of them. Include some visual delineation between the invocations of the two methods. You do not need to do any prompting Make sure you release any resources you use. The methods problem1() and problem2) should not take any parameters Answer these questions in your write-up: Define class Lab11Solution as public final. Does this affect the definitions of the methods in the class? Can another (derived) class extend the Lab11Solution class/use it as a base class? Why/why not? Put your class in an appropriately named package (refer to labs 9 or 10 for examples). What is the path name for Lab11Solution.java? Your output does not need to match the format in the samples but you must display the same content/information Create private utility methods if useful Problem 1 The names.txt file contains one name per line. There are duplicate names in the file. We would like to generate an invitation list but don't want to send multiple invitations to the same person. Write a method that eliminates the duplicate names by using a HashSet. Read each name from the file, echo it to the console, add it to the HashSet, and then output all names in the HashSet to generate the invitation list without duplicates Hint: You can use following code to open a file Scanner inputStream = new Scanner (new FileInputStream ("names. txt")); You do not need to handle file open errors for this assignment it is ok to assume the file exists and is accessible to your program. It is not necessary to validate the input for this problem. Page | 1 Tuesday, November 17, 2015 Dynamic Data Structures - Assignment DMR 2015-11-17 01.docx Comp 2070 Lab 11 David M Rosenberg Expected Sample Result: The invitation 1ist contains: Bruce Banne: Tony Stark Natasha Romanoff Clint Bartor Steve RogersExplanation / Answer
In Java, items with the final modifier cannot be changed!
This includes final classes, final variables, and final methods:
1. A final class cannot be extended by any other class
2. A final variable cannot be reassigned to another value
3. A final method cannot be overridden
package com.service;
public final class Lab11Solution {
public static void main(String args[]) {
Lab11Solution solution = new Lab11Solution();
solution.problem1();
solution.problem2();
}
public void problem1() {
System.out.println("p1");
}
public void problem2() {
System.out.println("p2");
}
}
Problem1 :
import java.io.FileInputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
public class SendInvitation {
HashSet<String> hashSet = new HashSet<String>();
public static void main(String args[]) throws Exception {
SendInvitation invitation = new SendInvitation();
invitation.removeDuplicates();
invitation.generateInvitations();
}
public void removeDuplicates() throws Exception {
Scanner scanner = new Scanner(new FileInputStream("names.txt"));
while (scanner.hasNext()) {
String name = scanner.nextLine();
hashSet.add(name);
}
}
public void generateInvitations() {
Iterator<String> iterator = hashSet.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}
names.txt
Bruce Banner
Tony Stark
Natasha Romanoff
Clint Barton
Steve Rogers
Natasha Romanoff
OUTPUT:
Bruce Banner
Tony Stark
Natasha Romanoff
Clint Barton
Steve Rogers
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.