SlideShare a Scribd company logo
1 of 7
Assignment 8 using arrays
FOR MORE CLASSES VISIT
tutorialoutletdotcom
Assignment 8: Collection CPSC 1150-005/006, Spring 2017
Instructor: A. Goldberg
Langara College Introduction
You may work in pairs for this assignment. You will be using arrays to
create and organize a
collection of your favourite collector’s item! You will first create a
utility class with helper methods,
and use it when creating your MyCollection program. You will
eventually submit both classes
(with Javadoc comments). Preparation
Textbook sections
• 4.2.5
• 7.2, 7.6-7, 7.10-11 Most relevant lectures
• L14-15 Exercises
1. Read through the lab.
2. Decide on a type of item to collect, and make a list of at least 5
different types of that item.
The more the better. If you are typing your list, type it in array syntax,
for easy copying
later. For example: Rocks. Types are ["granite",
"limestone", "sandstone", . . . 1 Assignment 8:
1 Collection CPSC 1150-005/006, Spring 2017
Instructor: A. Goldberg
Langara College Utility class: ArrayHelpers
1. Create a class called ArrayHelpers. Create a main method which you
will use to test the
methods you develop.
2. Inside this class, create (and test) the following seven methods. You
must write all of the
methods yourself, and not use built-in array methods to help you.
(a) public static void printArrayQuantities(String arr)
Displays all the unique elements of arr, along with a quantity of each
element. You may
assume the array is sorted.
(b) public static String getRandomElement(String arr)
Returns a random element from the array arr.
(c) public static String getRandomArray(int size, String stockElements)
Generates and returns a String array of length size. The Strings in the
array should be
selected randomly from the array stockElements (use
getRandomElement(stockElements)
to do this). It’s okay if an element appears multiple times! Think of
stockElements as
a list of all the possible Strings that might appear in your random array.
(d) public static void sort(String arr)
Sorts the array arr using any sorting algorithm you prefer. Do not use a
built-in sorting
method. You must state in your comments which algorithm you are
using. Sort by
alphabetical order and ignore case.
(e) public static int binarySearch(String arr, String key)
Performs binary search on the array arr. Returns position of key, if
found, or returns
-low - 1 if not found. Do not use a built-in search method. Ignore case in
your search.
(f) public static String insert(String arr, String item, int pos)
Generates and returns a new String array, which consists of the original
array arr with
the String item inserted at position pos. Note that the new array will
have a greater
length than the original array.
(g) public static String remove(String arr, int pos)
Generates and returns a new String array, which consists of the original
array arr, with
the String at position pos having been removed. Note that the new array
will have a
smaller length than the original array.
3. Note: It may be tempting to use a resizable structure that is not an
array, however, the
purpose of this assignment is to practice using arrays, so you may not
use a different built-in
data structure.
4. When all the methods in ArrayHelpers are working properly, delete
the main method
(including the method header). ArrayHelpers can no longer be run by
itself, but the methods
inside can be invoked from other classes (in the same directory or
package). 2 Assignment 8:
2 Collection CPSC 1150-005/006, Spring 2017
Instructor: A. Goldberg
Langara College The main program: MyCollection Write a program
called MyCollection that creates a random collection of your type of
item, and
then repeatedly displays a menu to the user, allowing them to perform
some actions to your collection. The collection should remain sorted
(alphabetically) at all times.
You will need to use methods from ArrayHelpers. Do not copy-paste the
method definitions into your new program! Instead, you must invoke the
methods directly from ArrayHelpers.
Your program should be modular (made up of strongly cohesive and
independent methods).
You should use the top-down design process. A program with
everything in the main method will
not receive any design marks. 2.1 Specifications Start-up: Generate a
random collection of 10 items, then sort that collection. The items
should
be selected from a larger stock list that you prepared earlier.
Menu: The option numbers should be as follows (but you can customize
the labels for your own
collection):
Select an action, or enter 0 to exit.
1. Display
2. Search
When an option is selected, perform that action, then display the menu
again. Inputs other
than the possible options should not be accepted. The user should be
prompted again until
a valid input is selected. You may add extra options that provide extra
functionality if you
like!
Display: Displays the entire collection (should appear in alphabetical
order). Do not display
duplicates separately. Instead, display a quantity for each item. Should
also indicate the
total size of the collection.
Search: Ask the user to input an item to search for.
• If the item is found, ask if the user would like to remove that item. If
they say yes, ask if
the user would like to remove just one, or all copies of that item. If they
say yes to any
kind of removal, confirm before removing the item. After removing,
display the quantity
of items removed.
• If the item is not found, notify the user, and ask if the user would like
to add that item
to their collection. If they say yes, insert the item in the correct position.
Validation: It should not be possible for a user to crash the program.
Validate all inputs, and
prompt again if an input is not understood. 3 Assignment 8:
2.2 Collection CPSC 1150-005/006, Spring 2017
Instructor: A. Goldberg
Langara College Sample output Note: I am aware that some of my
“rocks” are actually minerals.
Welcome to your rock collection!
Select an option, or enter 0 to exit.
1. Display all rocks
2. Search for a specific rock
1
You have 10 rocks.
feldspathic gneiss 2
limestone 2
magnetite 1
pyrite 1
quartz 1
schist 3
Select an option, or enter 0 to exit.
1. Display all rocks
2. Search for a specific rock
2
Enter a rock to search for: limestone
Found limestone. Would you like to remove:
1. Just one
2. All
0. Do not remove any
1
Are you sure? y/n
y
Okay, 1 limestone removed.
Select an option, or enter 0 to exit.
1. Display all rocks
2. Search for a specific rock
2
Enter a rock to search for: granite
Did not find granite. Would you like to add a granite rock to your
collection? y/n
y
Okay, 1 granite added. 4 Assignment 8: Collection CPSC 1150-005/006,
Spring 2017
Instructor: A. Goldberg
Langara College Select an option, or enter 0 to exit.
1. Display all rocks
2. Search for a specific rock
1
You have 10 rocks.
feldspathic gneiss 2
granite 1
limestone 1
magnetite 1
pyrite 1
quartz 1
schist 3
Select an option, or enter 0 to exit.
1. Display all rocks
2. Search for a specific rock
0
Goodbye! Submission
Recall that submission instructions are in the Lab Guide. Your group is
required to submit one
.zip folder (in one person’s D2L dropbox) containing the modular,
internally documented with
javadoc, and properly styled source code files
• ArrayHelpers.java (should not have a main method)
• MyCollection.java
External documentation is not necessary. The files should contain both
partners’ names in the
headers. Make sure both partners save copies of the finished code to
their personal H: drive. 5
************************************************
Spring 2017
Instructor: A. Goldberg
Langara College Select an option, or enter 0 to exit.
1. Display all rocks
2. Search for a specific rock
1
You have 10 rocks.
feldspathic gneiss 2
granite 1
limestone 1
magnetite 1
pyrite 1
quartz 1
schist 3
Select an option, or enter 0 to exit.
1. Display all rocks
2. Search for a specific rock
0
Goodbye! Submission
Recall that submission instructions are in the Lab Guide. Your group is
required to submit one
.zip folder (in one person’s D2L dropbox) containing the modular,
internally documented with
javadoc, and properly styled source code files
• ArrayHelpers.java (should not have a main method)
• MyCollection.java
External documentation is not necessary. The files should contain both
partners’ names in the
headers. Make sure both partners save copies of the finished code to
their personal H: drive. 5
************************************************

More Related Content

What's hot (18)

Scala test
Scala testScala test
Scala test
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Property based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rulesProperty based Testing - generative data & executable domain rules
Property based Testing - generative data & executable domain rules
 
Effective Java - Generics
Effective Java - GenericsEffective Java - Generics
Effective Java - Generics
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Extending javascript part one
Extending javascript part oneExtending javascript part one
Extending javascript part one
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 
Collections
CollectionsCollections
Collections
 
How Scala promotes TDD
How Scala promotes TDDHow Scala promotes TDD
How Scala promotes TDD
 
Scala - core features
Scala - core featuresScala - core features
Scala - core features
 
Generics
GenericsGenerics
Generics
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
All about unit testing using (power) mock
All about unit testing using (power) mockAll about unit testing using (power) mock
All about unit testing using (power) mock
 
Interaction testing using mock objects
Interaction testing using mock objectsInteraction testing using mock objects
Interaction testing using mock objects
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Java generics
Java genericsJava generics
Java generics
 
Java 104
Java 104Java 104
Java 104
 

Similar to Assignment 8 using arrays/tutorialoutlet

Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arraymybrands2
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arraynikig6806
 
ECET 370 Effective Communication/tutorialrank.com
 ECET 370 Effective Communication/tutorialrank.com ECET 370 Effective Communication/tutorialrank.com
ECET 370 Effective Communication/tutorialrank.comjonhson275
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arraymailemail
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayolivergeorg
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayuopassignment
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comledlang1
 
ECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.comECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.comlechenau124
 
ECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.comECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.comshanaabe90
 
ECET 370 Inspiring Innovation--ecet370.com
ECET 370 Inspiring Innovation--ecet370.comECET 370 Inspiring Innovation--ecet370.com
ECET 370 Inspiring Innovation--ecet370.comkopiko106
 
ECET 370 Redefined Education--ecet370.com
ECET 370 Redefined Education--ecet370.comECET 370 Redefined Education--ecet370.com
ECET 370 Redefined Education--ecet370.comagathachristie210
 
ECET 370 Education Planning--ecet370.com
 ECET 370 Education Planning--ecet370.com ECET 370 Education Planning--ecet370.com
ECET 370 Education Planning--ecet370.comWindyMiller46
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxalfred4lewis58146
 
Assignment2 A
Assignment2 AAssignment2 A
Assignment2 AMahmoud
 
ECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comGVlaxmi7
 
ECET 370 HELPS Education Counseling--ecet370helps.com
ECET 370 HELPS  Education Counseling--ecet370helps.comECET 370 HELPS  Education Counseling--ecet370helps.com
ECET 370 HELPS Education Counseling--ecet370helps.comclaric64
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7ashhadiqbal
 

Similar to Assignment 8 using arrays/tutorialoutlet (20)

Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab array
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab array
 
ECET 370 Effective Communication/tutorialrank.com
 ECET 370 Effective Communication/tutorialrank.com ECET 370 Effective Communication/tutorialrank.com
ECET 370 Effective Communication/tutorialrank.com
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab array
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab array
 
Devry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab arrayDevry ecet 370 week 1 i lab array
Devry ecet 370 week 1 i lab array
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.com
 
ECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.comECET 370 Invent Yourself/newtonhelp.com
ECET 370 Invent Yourself/newtonhelp.com
 
ECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.comECET 370 Achievement Education -- www.ecet370.com
ECET 370 Achievement Education -- www.ecet370.com
 
ECET 370 Inspiring Innovation--ecet370.com
ECET 370 Inspiring Innovation--ecet370.comECET 370 Inspiring Innovation--ecet370.com
ECET 370 Inspiring Innovation--ecet370.com
 
ECET 370 Redefined Education--ecet370.com
ECET 370 Redefined Education--ecet370.comECET 370 Redefined Education--ecet370.com
ECET 370 Redefined Education--ecet370.com
 
ECET 370 Education Planning--ecet370.com
 ECET 370 Education Planning--ecet370.com ECET 370 Education Planning--ecet370.com
ECET 370 Education Planning--ecet370.com
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docx
 
Assignment2 A
Assignment2 AAssignment2 A
Assignment2 A
 
ECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.comECET 370 HELPS Redefined Education--ecet370helps.com
ECET 370 HELPS Redefined Education--ecet370helps.com
 
ECET 370 HELPS Education Counseling--ecet370helps.com
ECET 370 HELPS  Education Counseling--ecet370helps.comECET 370 HELPS  Education Counseling--ecet370helps.com
ECET 370 HELPS Education Counseling--ecet370helps.com
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
 
Lecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 SlideLecture 2: ES6 / ES2015 Slide
Lecture 2: ES6 / ES2015 Slide
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
l2-es6-160830040119.pdf
l2-es6-160830040119.pdfl2-es6-160830040119.pdf
l2-es6-160830040119.pdf
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 

Assignment 8 using arrays/tutorialoutlet

  • 1. Assignment 8 using arrays FOR MORE CLASSES VISIT tutorialoutletdotcom Assignment 8: Collection CPSC 1150-005/006, Spring 2017 Instructor: A. Goldberg Langara College Introduction You may work in pairs for this assignment. You will be using arrays to create and organize a collection of your favourite collector’s item! You will first create a utility class with helper methods, and use it when creating your MyCollection program. You will eventually submit both classes (with Javadoc comments). Preparation Textbook sections • 4.2.5 • 7.2, 7.6-7, 7.10-11 Most relevant lectures • L14-15 Exercises 1. Read through the lab. 2. Decide on a type of item to collect, and make a list of at least 5 different types of that item. The more the better. If you are typing your list, type it in array syntax, for easy copying later. For example: Rocks. Types are ["granite", "limestone", "sandstone", . . . 1 Assignment 8: 1 Collection CPSC 1150-005/006, Spring 2017 Instructor: A. Goldberg Langara College Utility class: ArrayHelpers 1. Create a class called ArrayHelpers. Create a main method which you will use to test the methods you develop.
  • 2. 2. Inside this class, create (and test) the following seven methods. You must write all of the methods yourself, and not use built-in array methods to help you. (a) public static void printArrayQuantities(String arr) Displays all the unique elements of arr, along with a quantity of each element. You may assume the array is sorted. (b) public static String getRandomElement(String arr) Returns a random element from the array arr. (c) public static String getRandomArray(int size, String stockElements) Generates and returns a String array of length size. The Strings in the array should be selected randomly from the array stockElements (use getRandomElement(stockElements) to do this). It’s okay if an element appears multiple times! Think of stockElements as a list of all the possible Strings that might appear in your random array. (d) public static void sort(String arr) Sorts the array arr using any sorting algorithm you prefer. Do not use a built-in sorting method. You must state in your comments which algorithm you are using. Sort by alphabetical order and ignore case. (e) public static int binarySearch(String arr, String key) Performs binary search on the array arr. Returns position of key, if found, or returns -low - 1 if not found. Do not use a built-in search method. Ignore case in your search. (f) public static String insert(String arr, String item, int pos) Generates and returns a new String array, which consists of the original array arr with the String item inserted at position pos. Note that the new array will have a greater length than the original array. (g) public static String remove(String arr, int pos)
  • 3. Generates and returns a new String array, which consists of the original array arr, with the String at position pos having been removed. Note that the new array will have a smaller length than the original array. 3. Note: It may be tempting to use a resizable structure that is not an array, however, the purpose of this assignment is to practice using arrays, so you may not use a different built-in data structure. 4. When all the methods in ArrayHelpers are working properly, delete the main method (including the method header). ArrayHelpers can no longer be run by itself, but the methods inside can be invoked from other classes (in the same directory or package). 2 Assignment 8: 2 Collection CPSC 1150-005/006, Spring 2017 Instructor: A. Goldberg Langara College The main program: MyCollection Write a program called MyCollection that creates a random collection of your type of item, and then repeatedly displays a menu to the user, allowing them to perform some actions to your collection. The collection should remain sorted (alphabetically) at all times. You will need to use methods from ArrayHelpers. Do not copy-paste the method definitions into your new program! Instead, you must invoke the methods directly from ArrayHelpers. Your program should be modular (made up of strongly cohesive and independent methods). You should use the top-down design process. A program with everything in the main method will not receive any design marks. 2.1 Specifications Start-up: Generate a random collection of 10 items, then sort that collection. The items should be selected from a larger stock list that you prepared earlier.
  • 4. Menu: The option numbers should be as follows (but you can customize the labels for your own collection): Select an action, or enter 0 to exit. 1. Display 2. Search When an option is selected, perform that action, then display the menu again. Inputs other than the possible options should not be accepted. The user should be prompted again until a valid input is selected. You may add extra options that provide extra functionality if you like! Display: Displays the entire collection (should appear in alphabetical order). Do not display duplicates separately. Instead, display a quantity for each item. Should also indicate the total size of the collection. Search: Ask the user to input an item to search for. • If the item is found, ask if the user would like to remove that item. If they say yes, ask if the user would like to remove just one, or all copies of that item. If they say yes to any kind of removal, confirm before removing the item. After removing, display the quantity of items removed. • If the item is not found, notify the user, and ask if the user would like to add that item to their collection. If they say yes, insert the item in the correct position. Validation: It should not be possible for a user to crash the program. Validate all inputs, and prompt again if an input is not understood. 3 Assignment 8: 2.2 Collection CPSC 1150-005/006, Spring 2017 Instructor: A. Goldberg Langara College Sample output Note: I am aware that some of my
  • 5. “rocks” are actually minerals. Welcome to your rock collection! Select an option, or enter 0 to exit. 1. Display all rocks 2. Search for a specific rock 1 You have 10 rocks. feldspathic gneiss 2 limestone 2 magnetite 1 pyrite 1 quartz 1 schist 3 Select an option, or enter 0 to exit. 1. Display all rocks 2. Search for a specific rock 2 Enter a rock to search for: limestone Found limestone. Would you like to remove: 1. Just one 2. All 0. Do not remove any 1 Are you sure? y/n y Okay, 1 limestone removed. Select an option, or enter 0 to exit. 1. Display all rocks 2. Search for a specific rock 2 Enter a rock to search for: granite Did not find granite. Would you like to add a granite rock to your collection? y/n y Okay, 1 granite added. 4 Assignment 8: Collection CPSC 1150-005/006,
  • 6. Spring 2017 Instructor: A. Goldberg Langara College Select an option, or enter 0 to exit. 1. Display all rocks 2. Search for a specific rock 1 You have 10 rocks. feldspathic gneiss 2 granite 1 limestone 1 magnetite 1 pyrite 1 quartz 1 schist 3 Select an option, or enter 0 to exit. 1. Display all rocks 2. Search for a specific rock 0 Goodbye! Submission Recall that submission instructions are in the Lab Guide. Your group is required to submit one .zip folder (in one person’s D2L dropbox) containing the modular, internally documented with javadoc, and properly styled source code files • ArrayHelpers.java (should not have a main method) • MyCollection.java External documentation is not necessary. The files should contain both partners’ names in the headers. Make sure both partners save copies of the finished code to their personal H: drive. 5 ************************************************
  • 7. Spring 2017 Instructor: A. Goldberg Langara College Select an option, or enter 0 to exit. 1. Display all rocks 2. Search for a specific rock 1 You have 10 rocks. feldspathic gneiss 2 granite 1 limestone 1 magnetite 1 pyrite 1 quartz 1 schist 3 Select an option, or enter 0 to exit. 1. Display all rocks 2. Search for a specific rock 0 Goodbye! Submission Recall that submission instructions are in the Lab Guide. Your group is required to submit one .zip folder (in one person’s D2L dropbox) containing the modular, internally documented with javadoc, and properly styled source code files • ArrayHelpers.java (should not have a main method) • MyCollection.java External documentation is not necessary. The files should contain both partners’ names in the headers. Make sure both partners save copies of the finished code to their personal H: drive. 5 ************************************************