1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
denpristay [2]
3 years ago
12

Write a complete program to do the following: The main program calls a method to read in (from an input file) a set of people's

three-digit ID numbers and their donations to a charity (hint: use parallel arrays). Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted lists in tabular form, giving both ID numbers and donations. Then the main program calls another method to sort the donation amounts into descending order, carrying along the corresponding ID numbers. It then, once again, prints the sorted lists, giving both ID numbers and donations. Finally it prints some statistics (see below). Here are the details:
The main program calls a method to read in the data from a file. The data consists of sets of lines of data, each of which contains a person's three-digit integer ID number and a donation in dollars and cents. (e.g., 456 250.00 or 123 175.34). The file is read until end-of-file is reached. The method returns how many sets of data were read in. The main program calls the return value donorCount. The main program calls these arrays idNumbers and donations. A separate printing method prints the original set of data in the form of a neat table (use printf). When the arrays print, there should be an overall heading, plus headings for the columns of ID numbers and donations.
Then the main program sends the array of ID numbers, the array of donations, and the size donorCount to a sorting method. This method sorts the ID numbers into numerical order using a selection (linear) sort. Be sure to maintain the match-up of ID numbers and donations. For example, 456 should always be associated with 250.00, no matter where 456 moves in numerical order; similarly, 123 should stay with 175.34. When the sorting method finishes and returns control to the main program, the main program calls the printing method to once again print the two arrays.
Next, the main program sends the same three parameters to the second sorting method, which sorts the donations into descending numerical order (using a bubble sort), being sure to maintain the linkup of ID numbers and donations. When this sorting method finishes and returns control to the main program, the main program, once again, calls the printing method to print the two arrays with appropriate headings. Your arrays should have room for up to 50 entries. To test the program, have a set of data with at least 15 to 20 values in each array. Make sure that your original order is not close to numerical order for either array and that the two numerical orders are not close to each other.
(NOTE: Why can’t you use the same sorting method for the two sorts???)
Finally, print statistics as follows, based on the array sorted by donation:
The id and donation amount of the highest donor (this is easy once the array is sorted!); and the median donation value, which is the middle value for an odd number of donors (e.g. for 5 donors it would be the donation value of the third) or the average of the two middle donors (e.g. for 6 donors it would be the average of the 3rd and 4th). Your program doesn’t "know" the value of donorCount so you have to check. It should work for even or odd. Also calculate and print the average donation amount.
All donation values should be printed with precision of two decimal places. Columns should be neatly aligned, so format your output carefully.
Print your input file and submit it with your program.
Computers and Technology
1 answer:
zmey [24]3 years ago
3 0

Answer:

See explaination

Explanation:

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class Donor {

public static void main(String[] args){

int idNumbers[] = new int[50]; //created two array each of 50 size

int donations[] = new int[50];

int donorCount=readFile(idNumbers, donations); //calling readfile function

System.out.println("--------------------Original record--------------------");

printDetails(idNumbers,donations,donorCount); //printing details

sortByDonorId(idNumbers,donations,donorCount);

System.out.println("--------------------Sort by donor id--------------------");

printDetails(idNumbers,donations,donorCount);

sortByDonation(idNumbers,donations,donorCount);

System.out.println("--------------------Sort by donation amount--------------------");

printDetails(idNumbers,donations,donorCount);

}

private static void sortByDonation(int[] idNumbers, int[] donations, int donorCount) {

for(int i=0;i<=donorCount;i++){

for(int j=i+1;j<=donorCount;j++){

if(donations[i]>donations[j]){ //comparison based on donations

int temp = idNumbers[i];

idNumbers[i] = idNumbers[j];

idNumbers[j] = temp;

temp = donations[i];

donations[i] = donations[j];

donations[j] = temp;

}

}

}

}

private static void sortByDonorId(int[] idNumbers, int[] donations, int donorCount) {

for(int i=0;i<=donorCount;i++){

for(int j=i+1;j<=donorCount;j++){

if(idNumbers[i]>idNumbers[j]){ //comparison based on donor number

int temp = idNumbers[i];

idNumbers[i] = idNumbers[j];

idNumbers[j] = temp;

temp = donations[i];

donations[i] = donations[j];

donations[j] = temp;

}

}

}

}

public static void printDetails(int[] idNumbers, int[] donations, int donorCount){

System.out.printf("%-5s%s"," ","Donor information"); //using printf for format output

System.out.printf("\n%-20s%-20s","ID number","donations");

for(int i=0;i<=donorCount;i++){

System.out.printf("\n%-20s%-20s",idNumbers[i],donations[i]);

}

System.out.println();

}

public static int readFile(int idNumbers[],int donations[]){

File file = new File("input.txt"); //reading data from this file

Scanner reader;

int donorIndex=-1; //keep track of number of records

try {

reader = new Scanner(file);

while(reader.hasNext()){

donorIndex++;

String line = reader.nextLine();

idNumbers[donorIndex] = Integer.parseInt(line.split(" ")[0]); //spliting line by space,0 is idnumber

donations[donorIndex] = Integer.parseInt(line.split(" ")[1]); //spliting line by space,1 is donations

}

reader.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return donorIndex;

}

}

You might be interested in
Pick the correct statements on the 64-bit machine representation of numbers.
Cerrena [4.2K]

Answer:Floating-point arithmetic is considered an esoteric subject by many people. This is rather surprising because floating-point is ubiquitous in computer systems. Almost every language has a floating-point datatype; computers from PCs to supercomputers have floating-point accelerators; most compilers will be called upon to compile floating-point algorithms from time to time; and virtually every operating system must respond to floating-point exceptions such as overflow. This paper presents a tutorial on those aspects of floating-point that have a direct impact on designers of computer systems. It begins with background on floating-point representation and rounding error, continues with a discussion of the IEEE floating-point standard, and concludes with numerous examples of how computer builders can better support floating-point.

Explanation:

6 0
2 years ago
a _____ is a recreation of a thumbnail in a desktop publishing software, also known as a "rough". a. proof b. digital draft c. l
Dmitrij [34]
D. It’s a sketch. That is, if you talking about, an art piece.
6 0
2 years ago
Provide a brief, high-level description of how the Internet’s connection-oriented service provides reliable transport.
mario62 [17]

Answer:

  Connection-oriented is the method which is implemented in the transport and data link layer. It is basically depend upon the physical connection in the network system.

Transmission control protocol (TCP) is the connection oriented and user datagram protocol (UDP) is the connection less network transport layer. The TCP and UDP both are operate in the internet protocol (IP).

It basically require connection and it can be establish before sending data. This is also known as reliable network connection service. The connection oriented service establish connection between the different connection terminal before sending any data or information. It can easily handle traffic efficiently.

7 0
2 years ago
Kristen wants to view the records of her database in ascending order. What should she do?
Elanso [62]

the answer is Sort the table

6 0
2 years ago
Read 2 more answers
A software development company wants to reorganize its office so that managers and the Computer Programmers they supervise can b
Lelechka [254]

The best way to increase collaboration between a supervisor and her or his subordinates, which in this case is the computer programmers, would be through option (A) remove the private offices and cubicles and replace them with large desks and conference tables out in the open.

By choosing to implement an open office layout, greater communication between the supervisor and computer programmers would occur compared to when they were separated.

7 0
2 years ago
Other questions:
  • Which of the file names below follows standard file naming convention
    13·1 answer
  • Please help.............​
    7·1 answer
  • .Although SQL is a language, you don’t use it to write applications? (true, false)
    8·1 answer
  • Which administrative tool can you use to check your computer's health or troubleshoot problems with the operating system or soft
    11·2 answers
  • Your organization recently deployed a Windows domain controller with Active Directory. All the domain OU users need to run the s
    11·1 answer
  • The merge sort algorithm____________.A. Can be used only on vectors of even length.B. Works by reducing vectors down to the base
    9·1 answer
  • Melanie needs to ensure that readers are able to locate specific sections within a document easily. What should she include in
    8·1 answer
  • After fixing the format of her subheadings, she notices that she misspelled the name of one of the famous people
    7·2 answers
  • Which option on the Format tab is used to modify particular portions of the chart?
    13·1 answer
  • How would you assign roles to your group members?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!