Part B - Searching and Sorting 1. Create a search method in your program that allows the user to find a tax payer and display their information to the user. Change your program to prompt the user for a name to find. Have the main method call this method. 2. Add code to your program to sort the information according to salary in ascending order. Save the sorted information into a new file.

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...
icon
Related questions
Question
Please help with part b using java
1 import java.io.File;
2 import java.io.FileNotFoundException;
3 import java.io.Filewriter;
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Scanner;
7
8 public class Main
99 (
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
MAAARRR
31
32
33 ▼
34
35 ▼
36
37
38
static public double calcTax(double salary, double taxRate)
{
double taxowed = 0;
taxowed
(salary taxRate) / 100;
return taxowed;
}
public static void main(String[] args) throws IOException
{
ArrayList<Double» salary = new ArrayList<Double>();
ArrayList<string> nane = new ArrayList<String>();
ArrayList<String> company_name = new ArrayList<String>();
int lines = 1;
try (
File myFile new File("taxpayer.txt");
Scanner fileReader = new Scanner(myFile);
while (fileReader, hasNextLine()) {
String data fileReader.nextLine();
if(lines 3-1)
name.add(data);
Jelse if(lines
3= 2 )
company name.add(data);
Jelse{
double sal -Double.parseDouble(data);
salary.add(sal);
39
Tines++;
40
}
41
fileReader.close();
42
} catch (FileNotFoundException e) {
43
System.out.println("File with given name not found");
e.printStackTrace();
44
45
}
46
47
try (
48 FileWriter mywriter = new Filewriter("taxinfo.txt", true))
49 ▼ {
50
System.out.println("Records started in file .....");
for (int i = 0; i < name.size(); i++)
51
52
{
53
String name name.get(i);
54
String company Name = company_name.get(t);
55
double salaryP = salary.get(i);
56
double taxRate, taxowed=0;
57
58
if(salary.get(i) < 10000000){
59
taxRate = 40;
60 -
} else{
61
taxRate = 53;
62
}
63
tax0wed= calcTax(salary.get(i), taxRate);
String tax =String.valueof(taxowed);
64
65
mywriter.write(nameP+"\n"+companyName+"\n"+salaryP+"\n"+tax+"\n");
66
67
System.out.println(nameP+"\n"+companyName);
68
}
69
}
70
71
72
}
}
Transcribed Image Text:1 import java.io.File; 2 import java.io.FileNotFoundException; 3 import java.io.Filewriter; 4 import java.io.IOException; 5 import java.util.ArrayList; 6 import java.util.Scanner; 7 8 public class Main 99 ( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 MAAARRR 31 32 33 ▼ 34 35 ▼ 36 37 38 static public double calcTax(double salary, double taxRate) { double taxowed = 0; taxowed (salary taxRate) / 100; return taxowed; } public static void main(String[] args) throws IOException { ArrayList<Double» salary = new ArrayList<Double>(); ArrayList<string> nane = new ArrayList<String>(); ArrayList<String> company_name = new ArrayList<String>(); int lines = 1; try ( File myFile new File("taxpayer.txt"); Scanner fileReader = new Scanner(myFile); while (fileReader, hasNextLine()) { String data fileReader.nextLine(); if(lines 3-1) name.add(data); Jelse if(lines 3= 2 ) company name.add(data); Jelse{ double sal -Double.parseDouble(data); salary.add(sal); 39 Tines++; 40 } 41 fileReader.close(); 42 } catch (FileNotFoundException e) { 43 System.out.println("File with given name not found"); e.printStackTrace(); 44 45 } 46 47 try ( 48 FileWriter mywriter = new Filewriter("taxinfo.txt", true)) 49 ▼ { 50 System.out.println("Records started in file ....."); for (int i = 0; i < name.size(); i++) 51 52 { 53 String name name.get(i); 54 String company Name = company_name.get(t); 55 double salaryP = salary.get(i); 56 double taxRate, taxowed=0; 57 58 if(salary.get(i) < 10000000){ 59 taxRate = 40; 60 - } else{ 61 taxRate = 53; 62 } 63 tax0wed= calcTax(salary.get(i), taxRate); String tax =String.valueof(taxowed); 64 65 mywriter.write(nameP+"\n"+companyName+"\n"+salaryP+"\n"+tax+"\n"); 66 67 System.out.println(nameP+"\n"+companyName); 68 } 69 } 70 71 72 } }
Part B - Searching and Sorting
1. Create a search method in your program that allows
the user to find a tax payer and display their
information to the user. Change your program to
prompt the user for a name to find. Have the main
method call this method.
2. Add code to your program to sort the information
according to salary in ascending order. Save the sorted
information into a new file.
Part C-Suggested enhancements (for an even more
satisfied customer)
1. Ask the user for all file names instead of hard coding
them in the code.
2. Change your text based application into a graphical
user interface application.
3. Create code to sort the file according to the tax payer
names in alphabetical order.
4. Move the sort code from the main method into
methods. Note that the sort method needs to have as
input all of the arrays.
5. Use a JTextArea or other more interesting means to
display your results on the screen.
6. Add information to your input file that will allow you
to create arrays of sizes defined within the input file.
This way Revenue Canada could use files of different
sizes with your application.
7. Include Error Trapping structures to deal with
possible errors.
Transcribed Image Text:Part B - Searching and Sorting 1. Create a search method in your program that allows the user to find a tax payer and display their information to the user. Change your program to prompt the user for a name to find. Have the main method call this method. 2. Add code to your program to sort the information according to salary in ascending order. Save the sorted information into a new file. Part C-Suggested enhancements (for an even more satisfied customer) 1. Ask the user for all file names instead of hard coding them in the code. 2. Change your text based application into a graphical user interface application. 3. Create code to sort the file according to the tax payer names in alphabetical order. 4. Move the sort code from the main method into methods. Note that the sort method needs to have as input all of the arrays. 5. Use a JTextArea or other more interesting means to display your results on the screen. 6. Add information to your input file that will allow you to create arrays of sizes defined within the input file. This way Revenue Canada could use files of different sizes with your application. 7. Include Error Trapping structures to deal with possible errors.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY