Starting from:

$40

CS221 Assignment 6 – Solved


Assignment 6 – 


How to submit: upload solution file to Blackboard

This assignment focuses on Java’s Lambdas and Streams discussed in Chapter 17 and generic classes discussed in Chapter 20. You will need to implement the four methods declared in the provided Java file.

For    this    assignment,    you    must    use    Java’s    streams    with    intermediate    and    terminal    operations    (e.g.

𝑓𝑖𝑙𝑡𝑒𝑟, 𝑚𝑎𝑝, 𝑙𝑖𝑚𝑖𝑡, 𝑠𝑢𝑚 …). You are not allowed to use any looping structures (i.e. For, While, and Do‐While). For file input, you must use the 𝑗𝑎𝑣𝑎. 𝑛𝑖𝑜 package and not the 𝑗𝑎𝑣𝑎. 𝑖𝑜 package. However, you may use any of the exception classes from 𝑗𝑎𝑣𝑎. 𝑖𝑜 since there aren’t any in 𝑗𝑎𝑣𝑎. 𝑖𝑜!

Consult each method’s Javadoc for a description of that method’s task.

Note: 

ü  This is an individual assignment; please do your own work, sharing and/or copying code and/or solution ideas with/from others will result in a grade of 0 and disciplinary actions for all involved parties. If you run into problems and have done your best to solve them, please contact me before/after class or by e-mail. 

ü  A 20% grade deduction for every day the assignment is late. 

Figures: 

 
 


 
 

50 
 
Figure 1: Sum illustration between 10 and 20 (must account for 0-based indexes) 
 
 


 
 

51 
 
 
 


 
 

52 
 
 
 


 
 

53 
 
 
 


 
 

54 
 
 
 


 
 

55 
 
 
 


 
 

56 
 
 
 


 
 

57 
 
 
 


 
 

58 
 
 
 


 
 

59 
 
 
 

10 
 
 

60 
 
 
 

11 
 
 

61 
 
 
 

12 
 
 

62 
 
 
 

13 
 
 

63 
 
 
 

14 
 
 

64 
 
 
 

15 
 
 

65 
 
 
 

16 
 
 

66 
 
 
 

17 
 
 

67 
 
 
 

18 
 
 

68 
 
 
 

19 
 
 

69 
 
 
 

20 
 
 

70 
 
 
 

… 
 
 

… 
 
 
 
 
 
 
 
Ignored Elements Summed Elements 
 
 

1. 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝑡𝑜𝑄𝑢𝑒𝑢𝑒 𝑢𝑠𝑖𝑛𝑔 𝑎𝑛 𝑒𝑚𝑝𝑡𝑦 𝑠𝑡𝑎𝑐𝑘. 𝑉𝑎𝑙𝑢𝑒𝑠:  

 

2. 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝑡𝑜𝑄𝑢𝑒𝑢𝑒 𝑢𝑠𝑖𝑛𝑔 𝑠𝑡𝑎𝑐𝑘𝐶ℎ𝑎𝑟. 𝑉𝑎𝑙𝑢𝑒𝑠: 𝐴𝐵𝐶𝐷𝐸𝐹𝐺𝐻𝐼𝐽𝐾𝐿𝑀𝑁𝑂𝑃𝑄𝑅𝑆𝑇𝑈𝑉𝑊𝑋𝑌𝑍 

 

3. 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝑟𝑒𝑣𝑒𝑟𝑠𝑒𝑆𝑡𝑎𝑐𝑘 𝑢𝑠𝑖𝑛𝑔 𝑠𝑡𝑎𝑐𝑘𝐶ℎ𝑎𝑟. 𝑉𝑎𝑙𝑢𝑒𝑠: 𝑍𝑌𝑋𝑊𝑉𝑈𝑇𝑆𝑅𝑄𝑃𝑂𝑁𝑀𝐿𝐾𝐽𝐼𝐻𝐺𝐹𝐸𝐷𝐶𝐵𝐴 

 4. 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝑠𝑢𝑚𝐵𝑒𝑡𝑤𝑒𝑒𝑛 𝑢𝑠𝑖𝑛𝑔 𝑠𝑡𝑎𝑐𝑘𝐼𝑛𝑡. 𝑆𝑢𝑚 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 2 𝑎𝑛𝑑 0:       1 

 5. 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝑠𝑢𝑚𝐵𝑒𝑡𝑤𝑒𝑒𝑛 𝑢𝑠𝑖𝑛𝑔 𝑠𝑡𝑎𝑐𝑘𝐼𝑛𝑡. 𝑆𝑢𝑚 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 10 𝑎𝑛𝑑 20: 704 

 

5. 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝑠𝑢𝑚𝐵𝑒𝑡𝑤𝑒𝑒𝑛 𝑢𝑠𝑖𝑛𝑔 𝑠𝑡𝑎𝑐𝑘𝐼𝑛𝑡. 𝑆𝑢𝑚 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 1000 𝑎𝑛𝑑 2000:     1 

 

6. 𝑇𝑒𝑠𝑡𝑖𝑛𝑔 𝑟𝑒𝑎𝑑𝑁𝑢𝑚𝑒𝑟𝑖𝑐𝐹𝑟𝑜𝑚𝐹𝑖𝑙𝑒. 1𝑠𝑡 10 𝑁𝑢𝑚𝑒𝑟𝑖𝑐 𝑐ℎ𝑎𝑟𝑎𝑐𝑡𝑒𝑟𝑠 𝑓𝑜𝑢𝑛𝑑: 7, 4, 6, 9, 6, 8, 6, 1, 3, 2 

Figure 2: Test script output 

More products