omplete the Homework11Streams.java using streams. The file has 12 questions to answer using streams. Each question is worth an equal amount of points. Requirement : Use at least one method reference...

1 answer below »





omplete the Homework11Streams.java using streams.



  • The file has 12 questions to answer using streams. Each question is worth an equal amount of points.


  • Requirement: Use at least one method reference somewhere in one of the 12 solutions.

  • For full credit:

    • write compact (and elegant!) solutions

    • use a single, pipelined statement to answer each question





1. There are 11 questions and each question must be created 11 methods but each answer must be using Java Streams2. One txt file and One *.csv file which get the information3. The 11 questions are a java file
Maybe you need to read with time the question in Java.







public class Customer { private String firstName, lastName, id; private String state; private boolean priority; private double amountSpent; public Customer(String firstName, String lastName, String id, String state, boolean priority, double amountSpent) { this.firstName = firstName; this.lastName = lastName; this.id = id; this.state = state; this.priority = priority; this.amountSpent = amountSpent; } public int getInt() { return 0;} public double getAmountSpent() { return amountSpent; } public void setAmountSpent(double amountSpent) { this.amountSpent = amountSpent; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getId() { return id; } public void setId(String id) { this.id = id; } public boolean isPriority() { return priority; } public void setPriority(boolean priority) { this.priority = priority; } public String getState() { return state; } public void setState(String state) { this.state = state; } @Override public String toString() { return "" + lastName + ", " + firstName + " (ID: " + id + ")" + (priority ? " (Priority Customer)" : ""); } @Override public boolean equals(Object obj) { if(obj instanceof Customer) { Customer other = (Customer) obj; return firstName.equals(other.firstName) && id.equals(other.id) && lastName.equals(other.lastName) && state.equals(other.state) && priority==other.priority && Math.abs(amountSpent-other.amountSpent)<0.0001; }="" else="" {="" return="" false;="" }="" }="" }="" adam,="" zapel,az14,ca,true,2876="" al,="" dente,ad62,ny,false,9799="" al,="" fresco,af67,ca,true,2311="" al="" k.="" ,="" seltzer,asg1,ny,false,5243="" alf="" a.,="" romeo,arhc,ny,true,7480="" amanda,="" lynn,alh1,ca,false,8139="" anita,="" job,aj71,ny,true,1712="" anna,="" conda,ac4g,ny,true,4354="" anna,="" graham,agb1,ny,false,2969="" anna,="" prentice,apl2,ca,true,4408="" anna,="" sasin,as1g,ma,true,9278="" anne,="" teak,ath9,ny,false,5767="" b.a.,="" ware,bw90,ny,true,4780="" barb,="" dwyer,bdc1,ca,true,8143="" barb="" e.,="" dahl,bd31,ca,false,4755="" barbara,="" seville,bs20,wy,true,1219="" barry,="" cade,bcg5,wy,true,1979="" bea,="" minor,bmj7,ca,false,2319="" dee,="" major,dm78,il,true,5458="" beau,="" tye,bt65,ca,true,7896="" bill,="" board,bb53,ny,false,5217="" cara,="" van,cv62,ny,true,9195="" chris="" p.,="" bacon,cpa1,ny,true,5198="" constance,="" noring,cn6t,ca,true,2954="" crystal,="" ball,cb41,ny,true,6736="" crystal,="" glass,cgg4,il,false,8148="" earl="" lee,="" riser,er39,ca,true,8455="" easton,="" west,ew12,il,false,7657="" ferris,="" wheeler,fw36,ny,false,1986="" flint,="" sparks,f613,ca,true,1988="" franklin,="" stein,fs13,ny,true,4348="" gene,="" poole,gp19,ny,false,8626="" heidi,="" clare,hc84,ca,true,2550="" helen,="" back,hbb5,ny,true,2329="" helen,="" wiells,hw03,ny,true,568="" holly,="" mcrell,hm00,ca,true,4287="" holly,="" wood,hw32,ny,true,9207="" jack,="" pott,jp87,ca,true,407="" joe,="" kerr,jk87,il,true,5387="" joy,="" rider,jr64,ny,true,1713="" justin,="" case,jct1,ma,true,9211="" justin,="" time,jt13,ca,true,2912="" kandi,="" apple,ka74,il,true,9622="" laura,="" norder,lnb4,il,false,8278="" leigh,="" king,lk71,wy,true,1202="" luke,="" warm,lw13,il,true,8996="" marsha,="" mellow,mm44,ca,false,6858="" marshall,="" law,mlq3,ny,true,7707="" marty,="" graw,mg63,il,true,8709="" olive,="" branch,ob63,il,false,9782="" paige,="" turner,ptc8,wy,true,9678="" pepe,="" roni,pr94,ca,true,4272="" price,="" wright,pw17,ny,true,4731="" rocky,="" beach,rb12,ca,true,364="" sandy,="" beach,sb12,ca,true,3327="" sal="" a.,="" mander,sm62,ca,true,4710="" stanley,="" cupp,sc89,il,false,2989="" tom,="" morrow,tm43,il,true,8682="" warren,="" peace,wp90,il,true,9655="" will,="" power,wp91,ny,false,5809="" x.,="" benedict,xb43,ny,true,5183="" import="" java.io.*;="" import="" java.nio.charset.*;="" import="" java.nio.file.*;="" import="" java.util.*;="" import="" java.util.function.*;="" import="" java.util.stream.*;="" public="" class="" homeworkm11streams="" {="" public="" static=""> customerList = null; public static void main(String[] args) throws Exception { customerList = new ArrayList<>(); fillList(customerList); // Q1: How many customers in CA? System.out.print("Q1: Should print 20: "); long caCustomers = q1(); System.out.println(caCustomers); // Q2: Create a list of all priority customers in MA. System.out.println("\nQ2: Should print \n[ Sasin, Anna (ID: AS1G) (Priority Customer), Case, Justin (ID: JCT1) (Priority Customer)]"); List maPriorityList = q2(); System.out.println(maPriorityList); // Q3: How much money have all customers spent (combined)? System.out.print("\nQ3: Should print 330518.0: "); double total = q3(); System.out.println(total); // Q4: How much money have all priority customers spent (combined)? System.out.print("\nQ4: Should print 226177.0: "); double priorityTotal = q4(); System.out.println(priorityTotal); // Q5: Create a map of all WY priority customers (key=id, value=customer) System.out.println("\nQ5: Should print\n{BS20= Seville, Barbara (ID: BS20) (Priority Customer), BCG5= Cade, Barry (ID: BCG5) (Priority Customer), LK71= King, Leigh (ID: LK71) (Priority Customer), PTC8= Turner, Paige (ID: PTC8) (Priority Customer)}"); Map wyCustomers = q5(); System.out.println(wyCustomers); // Q6: What is the greatest amount of money spent by a NY priority customer? System.out.print("\nQ6: Should print 9207.0: "); double nyHighAmount = q6(); System.out.println(nyHighAmount); //Q7: Find all customers that spent > 9000. // Print a comma-separated String of all customer IDs for customers that spent > 9000: System.out.println("\nQ7: Should print: \nAD62,AS1G,CV62,HW32,JCT1,KA74,OB63,PTC8,WP90"); String highIDList = q7(); System.out.println(highIDList); //Q8: Find any customer that has spent > 9800. // Print the amount spent by the customer. If there is none, nothing should be printed. // Note: you can test your code with a lower amount, too. System.out.println("\nQ8: Should print nothing: "); q8(); // Q9: Find the sum of the numbers represented in an String array. String[] numWords = {"1", "2", "3", "4", "5", "6"}; int sum = q9(numWords); System.out.println("\nQ9: Sum is 21: " + sum); // Q10: Create a String of the numbers represented in the array, separated by semicolons. Integer[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; String concat = q10(nums); System.out.println("\nQ10: Should print \n1;2;3;4;5;6;7;8;9;10 \n" + concat); // Q11: Create an infinite stream of random integers in the range 1-100. // Keep only the numbers that are multiples of 3. // Print the first 5 of these numbers. System.out.println("\nQ11: Should print 5 numbers that are multiples of 3 between 1-100:"); q11(); // Q12: Print the top 9-highest-scoring scrabble word in the list. // Note: a method is provided below to convert from char to score. // Hint: you might consider writing another method to find the score of a word! List scrabbleWords = Files.readAllLines(Paths.get("words.txt"), Charset.forName("Cp1252")); System.out.println("\nQ12 Should print: " + "\n\tpizzazz worth 45 points"+"\n\tpizazz worth 35 points" +"\n\tjazzily worth 35 points" + "\n\tquizzed worth 35 points" + "\n\tjacuzzi worth 34 points" + "\n\tquizzer worth 34 points" + "\n\tquizzes worth 34 points" + "\n\tjazzy worth 33 points" + "\n\tjazzing worth 33 points" ); q12(scrabbleWords); } public static long q1() { // Q1: How many customers in CA? return 0; } public static List q2 () { // Q2: Create a list of all priority customers in MA. return new ArrayList<>(); } public static double q3() { // Q3: How much money have all customers spent (combined)? return 0; } public static double q4() { // Q4: How much money have all priority customers spent (combined)? return 0; } public static Map q5() { // Q5: Create a map of all WY priority customers (key=id, value=customer) return new HashMap<>(); } public static double q6() { // Q6: What is the greatest amount of money spent by a NY priority customer? return 0; } public static String q7() { //Q7: Find all customers that spent > 9000. return ""; } public static void q8() { //Q8: Find any customer that has spent > 9800. // Print the amount spent by the customer. If there is none, nothing should be printed. // Note: you can test your code with a lower amount, too. } public static int q9(String[] numWords) { // Q9: Find the sum of the numbers represented in an String array. return 0; } public static String q10(Integer[] nums) { // Q10: Create a String of the numbers represented in the array, separated by semicolons. return ""; } public static void q11() { // Q11: Create an infinite stream of random integers in the range 1-100. // Keep only the numbers that are multiples of 3. // Print the first 5 of these numbers. } public static void q12(List scrabbleWords) { // Q12: Print the top 9-highest-scoring scrabble word in the list. // Note: a method is provided below to convert from char to score. // Hint: you might consider writing another method to find the score of a word! } public static int charToScore(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'n': case 'r': case 't': case 'l': case 's': return 1; case 'g': case 'd': return 2; case 'b': case 'c': case 'm': case 'p': return 3; case 'f': case 'h': case 'v': case 'w': case 'y': return 4; case 'k': return 5; case 'j': case 'x': return 8; case 'q': case 'z': return 10; default: return -1; } } public static void fillList(List list) { try (Scanner fileScan = new Scanner( new FileReader(new File("Customers.csv")))) { while(fileScan.hasNext()) { String line = fileScan.nextLine(); Scanner lineScan = new Scanner(line); lineScan.useDelimiter(","); String firstName = lineScan.next(); String lastName = lineScan.next(); String id = lineScan.next(); String state = lineScan.next(); boolean priority = Boolean.parseBoolean(lineScan.next()); double amount = Double.parseDouble(lineScan.next()); Customer c = new Customer(firstName, lastName, id, state, priority, amount); list.add(c); } } catch (IOException ex){ ex.printStackTrace(); } } } I a ad ah al am an ar as at au ax ba be bi by cm co do ed eg eh el en er et ex fa ft go gu ha he hi ho id if in is it kg km ko ky la lp ma me mi mo mr ms mu my na no nu ny od of oh ok on op or os ow ox pa pc pe pi po pu ra re sa se so to tv uh un up us ut va vi we wi xi yd ye yo yr abc abe ace act add ado aft age ago aha aid ail aim air alb ale ali all alm alp alt ama ami amp amt amu amy ana and ani ann ant any ape apo apt arc are ark arm art ash ask asp ass ate aug auk aut ave awe awl awn axe aye baa bad bag bah ban bar bas bat bay bed bee beg ben bet bey bib bid big bin bio bit boa bob bog bon boo bop bow
Answered 3 days AfterMay 01, 2021

Answer To: omplete the Homework11Streams.java using streams. The file has 12 questions to answer using streams....

Vaishnavi R answered on May 02 2021
138 Votes
GN assignment 2/.classpath

    
        
            
        
    
    
    
GN assignment 2/.project

     GN assignment 2
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
GN assignment 2/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inline
JsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=15
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=15
GN assignment 2/bin/Customer.class
GN assignment 2/bin/HomeworkM11Streams.class
GN assignment 2/bin/SortbyScore.class
GN assignment 2/bin/WordScore.class
GN assignment 2/src/Customer.java
GN assignment 2/src/Customer.java
public class Customer {

    private String firstName, lastName, id;
    private String state;
    private boolean priority; 
    private double amountSpent;
    public Customer(String firstName, String lastName, String id, 
            String state, boolean priority, double amountSpent) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.id = id;
        this.state = state;
        this.priority = priority;
        this.amountSpent = amountSpent;
    }
    public int getInt() { return 0;}
    public double getAmountSpent() {
        return amountSpent;
    }
    public void setAmountSpent(double amountSpent) {
        this.amountSpent = amountSpent;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public boolean isPriority() {
        return priority;
    }
    public void setPriority(boolean priority) {
        this.priority = priority;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    @Override
    public String toString() {
        return "" + lastName + ", " + firstName + " (ID: " + id + ")" +
                (priority ? " (Priority Customer)" : "");
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Customer) {
            Customer other = (Customer) obj;
            return firstName.equals(other.firstName) &&
                    id.equals(other.id) &&
                    lastName.equals(other.lastName) &&
                    state.equals(other.state) &&
                    priority==other.priority &&
                    Math.abs(amountSpent-other.amountSpent)<0.0001;
        } else {
            return false;
        } 
    }


}
GN assignment 2/src/HomeworkM11Streams.java
GN assignment...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here