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
What specific record type is found in every zone and contains information that identifies the server primarily responsible for t
ValentinkaMS [17]

The SOA is the specific record type found in every zone and contains information that identifies the sever primarily responsible for the zone as well as some operational properties for the zone.

Explanation:

The Start of Authority Records (SOA) has the following information they are

Serial Number: This number is used to find when zonal information should be replicated.

Responsible person: The Email address of a person is responsible for managing the zone.

Refresh Interval: It specifies how often a secondary DNS server tries to renew its zone information.

Retry Interval: It specifies the amount of time a secondary server waits before retrying the zone information has failed.

Expires After: IT specifies the amount of time before a secondary server considers its zone data if it can't contact with the primary server.

Minimum TTL: It specifies the default TTL value for a zone data when a TTL is not supplied.

4 0
3 years ago
Hexadecimal to denary gcse method
Anuta_ua [19.1K]

There are two ways to convert from hexadecimal to denary gcse method. They are:

  • Conversion from hex to denary via binary.
  • The use of base 16 place-value columns.

<h3>How is the conversion done?</h3>

In Conversion from hex to denary via binary:

One has to Separate the hex digits to be able to know or find its equivalent in binary, and then the person will then put them back together.

Example - Find out the denary value of hex value 2D.

It will be:

2 = 0010

D = 1101

Put them them together and then you will have:

00101101

Which is known to be:

0 *128 + 0 * 64 + 1 *32 + 0 * 16 + 1 *8 + 1 *4 + 0 *2 + 1 *1

= 45 in denary form.

Learn more about hexadecimal from

brainly.com/question/11109762

#SPJ1

3 0
2 years ago
Each Google My Business location has a unique ID that applies changes to the right listing.
Soloha48 [4]

Answer:

The correct answer to the following question will be option c. Store Code.

Explanation:

A store code will be the unique ID which can uniquely identify any location of that store.

  • Any random number or name can be the store code.
  • A store code in each Google My Business (GMB) will only be viewable to the person who is managing that locations arround the store.
  • Any costumer doesn't have possibility to see it.

Hence, Option C is the right answer.

6 0
3 years ago
Which quality of service (QoS) mechanism provided by the network does real-time transport protocol (RTP) rely on to guarantee a
Radda [10]

Answer:

The real-time transport protocol (RTP) carries the audio and video data for streaming and uses the real-time control Protocol to analyse the quality of service and synchronisation. The RTP uses the user datagram protocol ( UDP) to transmit media data and has a recommended Voice over IP configuration.

Explanation:

RTP is a network protocol used alongside RTCP to transmit video and audio file over IP networks and to synchronise and maintain its quality of service.

8 0
3 years ago
write an expression taht evaluated to true if and only if the variable s does not contain the string 'end'
natima [27]

Answer:

//check which string is greater

if(strcmp(name1,name2)>0)

//assign name1 to first, if the

    //name1 is greater than name2

    first=name1;

else

    //assign name2 to first, if the

    //name2 is greater than name1

    first=name2;

5)

//compare name1 and name2

    if(strcmp(name1,name2)>0)

   

         //compare name1 and name3

         if(strcmp(name1,name3)>0)

       

             //assign name1 to max, becuase

             //name1 is greater than name2 and name3

             max=name1;

       

Explanation:

7 0
2 years ago
Other questions:
  • You type. The word "weather" when you ment "whether" when will the writer or word flag this as a misspelling or a grammar proble
    13·1 answer
  • The encapsulation unit on the presentation layer of the osi model is
    10·1 answer
  • Using the phase plane program, plot the phase plane for the Lotka-Volterra model:
    11·1 answer
  • Plzz help.... <br><br>i will mark u as brainliest if u answer correct
    10·1 answer
  • What dog breed is this
    6·1 answer
  • La estructura basica de una pagina web en Html​
    11·1 answer
  • A serial schedule:
    8·1 answer
  • HELP 20 points THIS IS ON EDGE IF YOU DON'T KNOW THE ANSWER DON'T RESPOND
    12·2 answers
  • it is good to know and use the npsd framework while solution envisioning as part of the value discovery cycle. What is NPSD?
    10·1 answer
  • 40 points for this question
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!