CS HELP
Use sets to solve this problem
package log;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class LogParser {
/**
* Returns a list of SuspectEntries corresponding to the CSV data supplied by the given Reader.
*
* The data contains one or more lines of the format:
*
* Marc,413-545-3061,1234567890
*
* representing a name, phone number, and passport number.
*
* @param r an open Reader object
* @return a list of SuspectEntries
* @throws IOException
*/
public static List parseLog(Reader r) throws IOException {
}
/**
* Returns a sorted list of SuspectEntries whose passport numbers are common to all
* of the supplied entryLists.
*
* The list is sorted lexicographically by passport number, breaking ties by name
* and then by phone number.
*
* @param list a list of lists of SuspectEntries
* @return a sorted list of SuspectEntries whose passport numbers are common to all
* of the supplied entryLists
*/
public static List findCommonEntries(List> list) {
}
}
package log;
public class SuspectEntry {
private String name;
private String phoneNumber;
private String passportNumber;
private String cardNumber;
public SuspectEntry(String name, String phoneNumber, String passportNumber, String cardNumber) {
this.name = name;
this.phoneNumber = phoneNumber;
this.passportNumber = passportNumber;
this.cardNumber=cardNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getPassportNumber() {
return passportNumber;
}
public void setPassportNumber(String passportNumber) {
this.passportNumber = passportNumber;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber=cardNumber;
}
public String toString() {
return "name='" + name + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", passportNumber='" + passportNumber+'\''+", cardNumber='"+cardNumber;
}
}
Hi.. I have written java program for the above. Please check below code.
LogParser.java
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class LogParser {
/**
* Returns a list of SuspectEntries corresponding to the CSV data supplied by the given Reader.
*
* The data contains one or more lines of the format:
*
* Marc,413-545-3061,1234567890
*
* representing a name, phone number, and passport number.
*
* @param r an open Reader object
* @return a list of SuspectEntries
* @throws IOException
*/
public static void main(String args[]) throws IOException{
Scanner input = new Scanner(System.in);
//File f = new File("C:/Santhosh/Abc.csv");
FileInputStream fstream = new FileInputStream("C:/Santhosh/Abc.csv");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
List<SuspectEntry> lst = parseLog(br);
System.out.println("After reading file:");
for(SuspectEntry se:lst){
System.out.println(se.toString());
}
List<SuspectEntry> lst1 = findCommonEntries(lst);
System.out.println("\n After calling findcommon entries");
for(SuspectEntry se:lst1){
System.out.println(se.toString());
}
}
public static List parseLog(BufferedReader r) throws IOException {
String strLine;
List<SuspectEntry> lst1 = new ArrayList<SuspectEntry>();
//Read File Line By Line
while ((strLine = r.readLine()) != null) {
// Print the content on the console
//System.out.println (strLine);
String vals[] = strLine.split(",");
SuspectEntry se = new SuspectEntry(vals[0], vals[1], vals[2], vals[3]);
lst1.add(se);
}
//Close the input stream
r.close();
return lst1;
}
/**
* Returns a sorted list of SuspectEntries whose passport numbers are common to all
* of the supplied entryLists.
*
* The list is sorted lexicographically by passport number, breaking ties by name
* and then by phone number.
*
* @param list a list of lists of SuspectEntries
* @return a sorted list of SuspectEntries whose passport numbers are common to all
* of the supplied entryLists
*/
public static List findCommonEntries(List<SuspectEntry> list) {
if (list.size() > 0) {
Collections.sort(list, new Comparator<SuspectEntry>() {
@Override
public int compare(SuspectEntry o1, SuspectEntry o2) {
// TODO Auto-generated method stub
return o1.getPassportNumber().compareTo(o2.getPassportNumber());
}
});
}
String indexes = "";
for(int i=0;i<list.size();i++){
for(int j=i+1;j<list.size();j++){
if(list.get(i).getPassportNumber().equalsIgnoreCase(list.get(j).getPassportNumber())){
if(indexes.isEmpty()){
indexes = String.valueOf(i);
indexes+=","+String.valueOf(j);
}else{
String n = String.valueOf(i);
String m = String.valueOf(j);
if(indexes.indexOf(n)>-1){
}else{
indexes+=","+n;
}
if(indexes.indexOf(m)>-1){
}else{
indexes+=","+m;
}
}
}
}
}
String it[];
int abs[];
if(indexes.indexOf(",")>-1){
it = indexes.split(",");
abs = new int[it.length];
for(int i=0;i<it.length;i++){
abs[i] = Integer.parseInt(it[i]);
}
}else{
abs = new int[1];
abs[0] = Integer.parseInt(indexes);
}
List<SuspectEntry> lm = new ArrayList<SuspectEntry>();
for(int i=0;i<abs.length;i++){
lm.add(list.get(abs[i]));
}
return lm;
}
}
SuspectEntry.java
public class SuspectEntry {
private String name;
private String phoneNumber;
private String passportNumber;
private String cardNumber;
public SuspectEntry(String name, String phoneNumber, String passportNumber, String cardNumber) {
this.name = name;
this.phoneNumber = phoneNumber;
this.passportNumber = passportNumber;
this.cardNumber=cardNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getPassportNumber() {
return passportNumber;
}
public void setPassportNumber(String passportNumber) {
this.passportNumber = passportNumber;
}
public String getCardNumber() {
return cardNumber;
}
public void setCardNumber(String cardNumber) {
this.cardNumber=cardNumber;
}
public String toString() {
return "name='" + name + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
", passportNumber='" + passportNumber+'\''+", cardNumber='"+cardNumber;
}
}
Output:
After reading file:
name='Marc', phoneNumber='413-545-3061',
passportNumber='1234567890', cardNumber='543534524
name='Anil', phoneNumber='413-545-3261',
passportNumber='1234567890', cardNumber='322123133
name='Picc', phoneNumber='413-545-3061',
passportNumber='1239967890', cardNumber='543534524
After calling findcommon entries
name='Marc', phoneNumber='413-545-3061',
passportNumber='1234567890', cardNumber='543534524
name='Anil', phoneNumber='413-545-3261',
passportNumber='1234567890', cardNumber='322123133
Please test it and let me know any querries. Thank you. All the best.
CS HELP Use sets to solve this problem package log; import java.io.IOException; import java.io.Reader; import java.util.ArrayList;...
write comments // on this program please //Inside package bloodDonation //BloodDonor.java class package bloodDonation; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class BloodDonor { long idNumber, cardNumber; String name, bloodGroup, homePhone, mobilePhone, address, lastDateOfDonation; SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy"); public BloodDonor(){ this.idNumber = 0; this.cardNumber = 0; this.name = ""; this.bloodGroup = ""; this.homePhone = ""; this.mobilePhone = ""; this.address = ""; ...
package cards; import java.util.ArrayList; import java.util.Scanner; public class GamePlay { static int counter = 0; private static int cardNumber[] = {1,2,3,4,5,6,7,8,9,10,11,12,13}; private static char suitName[] = { 'c', 'd', 'h', 's' }; public static void main(String[] args) throws CardException, DeckException, HandException { Scanner kb = new Scanner(System.in); System.out.println("How many Players? "); int numHands = kb.nextInt(); int cards = 0; if (numHands > 0) { cards = 52 / numHands; System.out.println("Each player gets " + cards + " cards\n"); } else...
PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...
I need help converting the following two classes into one sql table package Practice.model; import java.util.ArrayList; import java.util.List; import Practice.model.Comment; public class Students { private Integer id; private String name; private String specialties; private String presentation; List<Comment> comment; public Students() {} public Students(Integer id,String name, String specialties, String presentation) { this.id= id; this.name = name; this.specialties = specialties; this.presentation = presentation; this.comment = new ArrayList<Commment>(); } public Students(Integer id,String name, String specialties, String presentation, List<Comment> comment) { this.id= id; this.name...
How to complete this methods: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; /** * Utility class that deals with all the other classes. * * @author EECS2030 Summer 2019 * */ public final class Registrar { public static final String COURSES_FILE = "Courses.csv"; public static final String STUDENTS_FILE = "Students.csv"; public static final String PATH = System.getProperty("java.class.path"); /** * Hash table to store the list of students using their...
package scheduler; import java.util.List; public class Scheduler { /** * Instantiates a new, empty scheduler. */ public Scheduler() { } /** * Adds a course to the scheduler. * * @param course the course to be added */ public void addCourse(Course course) { } /** * Returns the list of courses that this scheduler knows about. * * This returned object does not share state with the internal state of the Scheduler. * * @return the list of courses */...
JAVA How to add array to develop a contact list application for the person class objects developed in this code? The application will include functionality to add, remove, sort and search the contact list. You should also include a method to output the contents of a contact searched for, and also to output the entire list. The code: package BankProg; public class personal { private String facebook; public personal() { } public personal(String facebook) { this.facebook...
departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore { private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee; } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...
Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car { private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...