o 93% o T-Mobile LTE 9:00 PM Lab 14 Figure 1 Source Code for the Database File P
ID: 3839151 • Letter: O
Question
o 93% o T-Mobile LTE 9:00 PM Lab 14 Figure 1 Source Code for the Database File Processing Program javaie.File: javai FileNetF javautil-ArrayList Sammy Student blic class DataApplication public static veid mainestringll arro File Filer' data tut Scanner sean Scanner ArrayList String theData Mread the column headings the nat text String line scan-nevtline0 Stringll list lineaplitu". int fee String specialty thrData add name): theData add(String valueof in count %4 0) Systema PROJECT Java File Processing Application Database Application STEP2 Create and Save a Text Data FileExplanation / Answer
Program
----------------
package chegg.linkedlist;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class DataProcessing {
public static void main(String[] args) {
List<Consultant> personList = DataProcessing.readFile();
System.out.println(" ID LName Fee Speciality");
for (Consultant person : personList) {
System.out.println(person.toString());
}
DataProcessing.searchData(personList);
DataProcessing.consltantsChargedMoreThan(personList, 2000);
DataProcessing.getMediaConsltantList(personList);
}
public static List<Consultant> readFile() {
int firstRow = 0;
List<Consultant> list = new ArrayList<Consultant>();
File file = new File("d://data.txt");
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String sCurrentLine;
while ((sCurrentLine = br.readLine()) != null) {
if (firstRow != 0) {
String[] strArray = sCurrentLine.split(",");
Consultant person = new Consultant(
Integer.parseInt(strArray[0]), strArray[1],
Double.parseDouble(strArray[2]), strArray[3]);
list.add(person);
}
firstRow++;
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
public static void searchData(List<Consultant> personList) {
boolean isRecordfound = false;
Scanner scanner = new Scanner(System.in);
System.out
.println("Enter the name of person for which you are looking data ");
String name = scanner.next();
for (Consultant person : personList) {
if (person.getlName().equalsIgnoreCase(name)) {
System.out
.println("Name is found in the file with below records ");
System.out.println(person.toString() + " ");
isRecordfound = true;
break;
}
}
if (!isRecordfound)
System.out.println("Name is not found in the file ");
if (scanner != null) {
scanner.close();
}
}
public static void consltantsChargedMoreThan(
List<Consultant> consultantList, double fees) {
List<Consultant> tempConsultantList = null;
if (consultantList != null) {
tempConsultantList = new ArrayList<Consultant>();
for (Consultant consultant : consultantList) {
if (consultant.getFees() > fees) {
tempConsultantList.add(consultant);
}
}
}
if (tempConsultantList == null || tempConsultantList.size() == 0) {
System.out.println("Consltant is not found who have more than "
+ fees + " fees ");
} else {
System.out.println("Consltant list who charge more than 2000$ ");
for (Consultant consultant : tempConsultantList) {
System.out.println(consultant.toString());
}
}
}
public static void getMediaConsltantList(List<Consultant> consultantList) {
List<Consultant> tempConsultantList = null;
if (consultantList != null) {
tempConsultantList = new ArrayList<Consultant>();
for (Consultant consultant : consultantList) {
if (consultant.getSpecialtiy().equalsIgnoreCase("media")) {
tempConsultantList.add(consultant);
}
}
}
if (tempConsultantList == null || tempConsultantList.size() == 0) {
System.out
.println("Consltant is not found who provides media services ");
} else {
System.out.println("Consltant list who provides media services ");
for (Consultant consultant : tempConsultantList) {
System.out.println(consultant.toString());
}
}
}
}
class Consultant implements Comparable<Consultant> {
private int id;
private String lName;
private double fees;
private String specialtiy;
public Consultant(int id, String lName, double fees, String specialtiy) {
super();
this.id = id;
this.lName = lName;
this.fees = fees;
this.specialtiy = specialtiy;
}
public int getId() {
return id;
}
public String getlName() {
return lName;
}
public double getFees() {
return fees;
}
public String getSpecialtiy() {
return specialtiy;
}
@Override
public int compareTo(Consultant o) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String toString() {
return " " + id + " " + lName + " " + fees + " " + specialtiy
+ " ";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(fees);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + id;
result = prime * result + ((lName == null) ? 0 : lName.hashCode());
result = prime * result
+ ((specialtiy == null) ? 0 : specialtiy.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Consultant other = (Consultant) obj;
if (Double.doubleToLongBits(fees) != Double
.doubleToLongBits(other.fees))
return false;
if (id != other.id)
return false;
if (lName == null) {
if (other.lName != null)
return false;
} else if (!lName.equals(other.lName))
return false;
if (specialtiy == null) {
if (other.specialtiy != null)
return false;
} else if (!specialtiy.equals(other.specialtiy))
return false;
return true;
}
}
Description :
1. I have provided input and ouput of above program. Please check the same below.
2. I have added following methods to cater all the fuctionalities whihc are mentioned in above given question.
3. let me know, if you face any dificulties to make understanding on abpove code.
Input :
-----------
ID,LName,Fee,Speciality
101,Roberts,3500,Media
102,Peters,2700,Accounting
103,Paul,1600,Media
104,Michael,2300,Web Design
105,Manfred,3500,Broadcasting
Output 1
---------
Record founds
ID LName Fee Speciality
101 Roberts 3500.0 Media
102 Peters 2700.0 Accounting
103 Paul 1600.0 Media
104 Michael 2300.0 Web Design
105 Manfred 3500.0 Broadcasting
Enter the name of person for which you are looking data
Peters
Name is found in the file with below records
102 Peters 2700.0 Accounting
Consltant list who charge more than 2000$
101 Roberts 3500.0 Media
102 Peters 2700.0 Accounting
104 Michael 2300.0 Web Design
105 Manfred 3500.0 Broadcasting
Consltant list who provides media services
101 Roberts 3500.0 Media
103 Paul 1600.0 Media
Output 2 :
-------------
ID LName Fee Speciality
101 Roberts 3500.0 Media
102 Peters 2700.0 Accounting
103 Paul 1600.0 Media
104 Michael 2300.0 Web Design
105 Manfred 3500.0 Broadcasting
Enter the name of person for which you are looking data
Abc
Name is not found in the file
Consltant list who charge more than 2000$
101 Roberts 3500.0 Media
102 Peters 2700.0 Accounting
104 Michael 2300.0 Web Design
105 Manfred 3500.0 Broadcasting
Consltant list who provides media services
101 Roberts 3500.0 Media
103 Paul 1600.0 Media
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.