Please help me I need as searching algorithm for the program below
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Please help me I need as searching algorithm for the program below. User must be able to search for any names and the programs will display their information (full name, company they are the ceo, salary and tax owed.
Java code is below
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Demo{
//Method to calculate the tax
static public double calcTax(double salary , double taxRate){
double taxOwed = 0;
//Calclate and return the tax
taxOwed = (salary * taxRate) / 100;
//return the value
return taxOwed;
}
//Main method
public static void main(String[] args) throws IOException{
//Create three array to add the data
ArrayList salary = new ArrayList();
ArrayList name = new ArrayList();
ArrayList company_name = new ArrayList();
//to count the lines
int lines = 1;
try {
//Open the file
File myFile = new File("taxpayer.txt");
//to read the file
Scanner fileReader = new Scanner(myFile);
//Check if file has next line
while (fileReader.hasNextLine()) {
//get the line into the string data
String data = fileReader.nextLine();
//Check the line number before adding that into the array
if(lines % 3 == 1){
//FOr the lines 1 , 4 , 7 add them into the name array
name.add(data);
}else if(lines % 3 == 2 ){
//for line 2 , 5 , 8 add them into the company_name array
company_name.add(data);
}else{
//FOr lines 3, 6 , 9 add them into the salary array
//First parse the value into double before adding
double sal =Double.parseDouble(data);
salary.add(sal);
}
//Increment the number of line
lines++;
}
//Close the file
fileReader.close();
//Check if any exceptions is there
} catch (FileNotFoundException e) {
System.out.println("File with given name not found");
e.printStackTrace();
}
try (//Now we have to add the records into the new File
//Create the my file writer class object to write into the file
FileWriter myWriter = new FileWriter("taxInfo.txt",true)) {
System.out.println("Records started in file .....");
//Iterate over the list to add the data into the file
for (int i = 0 ; i < name.size() ; i++){
//Get the data to add into the file
String nameP = name.get(i);
String companyName = company_name.get(i);
double salaryP = salary.get(i);
double taxRate = 0 , taxOwed = 0;
//Decide the tax rate
if(salary.get(i)
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY