Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Contributor { private String name; private String city; private String country; private String phone; private double contribution; private int id; public Contributor(String name,

public class Contributor { private String name; private String city; private String country; private String phone; private double contribution; private int id; public Contributor(String name, String city, String country, String phone, double contribution, int id) { //initialize each value in the Contributor object this.name = name; this.city = city; this.country = country; this.phone = phone; this.contribution = contribution; this.id = id; } public void printContributor() { //display the contents of the Contributor object System.out.println("Name: " + name); System.out.println("City: " + city); System.out.println("Country: " + country); System.out.println("Phone: " + phone); System.out.println("Contribution: " + contribution); System.out.println("ID: " + id); System.out.println(); } }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Node.java:

public class Node { Contributor c; Node next; public Node(Contributor data){ //initialize member variables c=data; next=null; } public void displayNode() { //display the contents of this node c.printContributor(); } void setNext(Node next) { this.next=next; } Node getNext() { return this.next; } }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Stack.java:

public class Stack { Node first; public Stack(){ //initialize the empty stack first=null; } public void push(Node newNode){ //if the stack is empty, make first point to new Node. if(first==null) first=newNode; //if the stack is not empty, loop until we get to the end of the list, //then make the last Node point to new Node else { newNode.setNext(first); first=newNode; } } public Node pop() { //if the stack is empty, return null if(first==null) return null; //Handle the case where there is only one Node in the stack else if(first.getNext()==null) { Node t=first; first=null; return t; } //Handle the case where there are at Least two elements in the stack else { Node t=first; first=first.getNext(); return t; } } public void print() { //display the entire stack Node tempDisplay = first; // start at the beginning of linkedList while (tempDisplay != null){ // Executes until we don't find end of list. tempDisplay.displayNode(); tempDisplay = tempDisplay.next; // move to next Node } System.out.println(); } }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ContributorManager.java:

import java.util.Scanner; import java.io.File; import java.util.regex.Pattern;

public class ContributorManager { public static void main(String [] args) { Scanner inputFile = null; String name = null; String city = null; String country = null; String phone = null; double contribution = 0; int id = 0; Contributor c = null; Stack stack = new Stack(); Node node = null; //open contributors file try { inputFile = new Scanner(new File("contributors.csv")); inputFile.useDelimiter(Pattern.compile("(\ )|(\ )|,")); } catch (Exception e) { System.err.println("Error opening file."); } //create contributors object for each row, and add to the stack while (inputFile.hasNext()) { name = inputFile.next(); city = inputFile.next(); country = inputFile.next(); phone = inputFile.next(); contribution = inputFile.nextDouble(); id = inputFile.nextInt(); inputFile.nextLine(); //advance to the next line c = new Contributor(name, city, country, phone, contribution, id); node = new Node(c); //create a node using the contributor object stack.push(node); //add the node to the top of the stack } stack.pop(); //remove the last node from the top of the stack stack.print(); //print the contents of the entire stack } }

Input file: contributors.csv Tim,Murphy,USA,8285557865,200,25 Gordon,Miner,USA,8285551008,150,32 Jean,Bell,USA,8285557503,225,33 Mike,Prather,USA,8285558497,155,34 George ,Pipps,USA,8285557777,100,35

I need to know where to put the contributors in the code above?????

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

Describe key customer feedback collection tools.

Answered: 1 week ago

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago

Question

Understand why customers complain.

Answered: 1 week ago