SlideShare a Scribd company logo
Question 1: MiniList collection [20 marks]
In this question you are going to produce a simplified collection type called MyMiniList.
MyMiniList will work in a similar way to ArrayList. Internally, it will use an array, you will have to
reorganise and grow the array as the MiniList is updated through use of its methods. Inside the
template is an interface called MiniList.
MyMiniList must implement this interface and be implemented with a single generic type.
Also included in the template is a simple set of tests for you to verify your implementation against.
You will receive the following marks for correctly implementing each of the interfaces methods and
a constructor.
Your class will need two instance variables, 1 for the current size of the list (an int) and an array of
generic type T to store the elements of the list call this objectStore.
i) public MyMiniList() [2 marks] Initialise the array of elements, this is a little tricky as Java
Generics doesnt support arrays. There are a couple of approaches you can use. This is the
easiest and is moderately type safe, however, IntelliJ will give you some warnings: objectStore =
(T[]) new Object[10]; Initially, set the size of this array to be 10. Also set your size variable to be 0.
ii) public void add(T element) [3 marks] Elements are added to the end of the objectStore array if
the array has space. If the array doesnt have space you will need to create a new array twice the
size now required, copy in the existing elements and replace the existing objectStore with this new
array. System.arrayCopy is useful to achieve this but there are other methods you could use. You
can then add in the new element and update the size variable.
iii) public T get(int index) [2 marks] Check that the index given is with the required bounds. You
can use the built in method Objects.checkIndex to do this (no imports required). If the index is
valid return the item at the index
iv) public int getIndex(T element) [2 marks] Search through the list for the first occurrence of the
element given as an argument. If found return its index. Otherwise return -1.
v) public void set(int index, T element); [2 marks] Check if the index is valid. If so set the value at
the index to be the element given in the second parameter. public int size(); [1 mark] Return the
size of the list. (Make sure you return the size of list not the size of the underlying array)
vi) public T remove(int index); [4 marks] Check if a valid index has been given. If so remove the
element and return it. You will need to move down the end of the array after the removal point so
there is no gap and adjust your size property accordingly.
vii) public boolean remove(T element); [4 marks] Search the list for the first instance of the
element and remove it. Again you will need to shift the array down to fill the gap left. TIP: you
might be able to use the previous method to help you.
viii) public void clear(); [1 mark] Empty the list and reset the size to 0.

More Related Content

PDF
For this lab you will complete the class MyArrayList by implementing.pdf
PDF
A popular implementation of List is ArrayList- Look up how to instanti.pdf
PDF
Everything needs to be according to the instructions- thank you! SUPPO.pdf
PDF
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
DOCX
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
DOC
Advanced core java
PDF
Implementation The starter code includes List.java. You should not c.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Advanced core java
Implementation The starter code includes List.java. You should not c.pdf

Similar to Question 1 MiniList collection 20 marks In this question .pdf (20)

PPTX
Java Foundations: Lists, ArrayList<T>
PPTX
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
PDF
STAGE 2 The Methods 65 points Implement all the methods t.pdf
PPTX
Arrays and Strings engineering education
PDF
I need help with this code working Create another project and add yo.pdf
PDF
Java collections
DOCX
Collections framework
PDF
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
PPT
lec6.ppt
PPTX
ArrayList class and useful methods.pptx
DOCX
ArrayList.docx
PDF
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
PPT
Engineering lecture ppt by venay magen
PPT
A2003822018_21789_17_2018_09. ArrayList.ppt
PDF
Aj unit2 notesjavadatastructures
DOCX
This class maintains a list of 4 integers. This list .docx
PPTX
Java collections
PPT
PDF
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
PPTX
arraylist in java a comparison of the array and arraylist
Java Foundations: Lists, ArrayList<T>
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
STAGE 2 The Methods 65 points Implement all the methods t.pdf
Arrays and Strings engineering education
I need help with this code working Create another project and add yo.pdf
Java collections
Collections framework
Note- Can someone help me with the public boolean isEmpty()- public bo.pdf
lec6.ppt
ArrayList class and useful methods.pptx
ArrayList.docx
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
Engineering lecture ppt by venay magen
A2003822018_21789_17_2018_09. ArrayList.ppt
Aj unit2 notesjavadatastructures
This class maintains a list of 4 integers. This list .docx
Java collections
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
arraylist in java a comparison of the array and arraylist

More from abhisheksharmasre (20)

PDF
Today Meadowvale Aged Care facility is very short staffed I.pdf
PDF
The US Patent amp Trademark Office spends most of its time.pdf
PDF
Trace the Dining Philosopher problem and write the flow of s.pdf
PDF
The spinner shown above is a fair spinner Event A is define.pdf
PDF
The Movie table has the following columns ID integer pri.pdf
PDF
The figure shows a chromosomal separation taking place What.pdf
PDF
Read the case study below and answer the questions that foll.pdf
PDF
Question 2 Suppose we are given the data X1X2Yx11x12y1x21.pdf
PDF
sadaf has developed a condition called paralytic ileus or p.pdf
PDF
Af if be abint Quentien 18 Quevioni Guantion 29The secon.pdf
PDF
Bayan Mahta Amiri uzun yllara dayanan deneyime sahip bir Se.pdf
PDF
Bir stma paraziti plazmodyum tr bir krmz kan hcresini i.pdf
PDF
Angela is an artist who puts together an exhibit of modern a.pdf
PDF
Describe two detection methods for exoplanets other than the.pdf
PDF
Case Study WGM employs many employees in several departments.pdf
PDF
3 1 point Let PA03PB04PBA01 Find PAB.pdf
PDF
Cul de las siguientes describe MEJOR las caractersticas d.pdf
PDF
1 How to calculate COGS and Ending Inventory using either t.pdf
PDF
PLEASE HELP Refer to the HarrisTodaro migration model As.pdf
PDF
prepare a chart Part 1 Stakeholder Register Choose a proj.pdf
Today Meadowvale Aged Care facility is very short staffed I.pdf
The US Patent amp Trademark Office spends most of its time.pdf
Trace the Dining Philosopher problem and write the flow of s.pdf
The spinner shown above is a fair spinner Event A is define.pdf
The Movie table has the following columns ID integer pri.pdf
The figure shows a chromosomal separation taking place What.pdf
Read the case study below and answer the questions that foll.pdf
Question 2 Suppose we are given the data X1X2Yx11x12y1x21.pdf
sadaf has developed a condition called paralytic ileus or p.pdf
Af if be abint Quentien 18 Quevioni Guantion 29The secon.pdf
Bayan Mahta Amiri uzun yllara dayanan deneyime sahip bir Se.pdf
Bir stma paraziti plazmodyum tr bir krmz kan hcresini i.pdf
Angela is an artist who puts together an exhibit of modern a.pdf
Describe two detection methods for exoplanets other than the.pdf
Case Study WGM employs many employees in several departments.pdf
3 1 point Let PA03PB04PBA01 Find PAB.pdf
Cul de las siguientes describe MEJOR las caractersticas d.pdf
1 How to calculate COGS and Ending Inventory using either t.pdf
PLEASE HELP Refer to the HarrisTodaro migration model As.pdf
prepare a chart Part 1 Stakeholder Register Choose a proj.pdf

Recently uploaded (20)

PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PPTX
20th Century Theater, Methods, History.pptx
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Empowerment Technology for Senior High School Guide
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
Trump Administration's workforce development strategy
PPTX
Introduction to Building Materials
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Chinmaya Tiranga quiz Grand Finale.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
20th Century Theater, Methods, History.pptx
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
Virtual and Augmented Reality in Current Scenario
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Empowerment Technology for Senior High School Guide
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
Trump Administration's workforce development strategy
Introduction to Building Materials
Indian roads congress 037 - 2012 Flexible pavement
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Introduction to pro and eukaryotes and differences.pptx
History, Philosophy and sociology of education (1).pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Unit 4 Computer Architecture Multicore Processor.pptx

Question 1 MiniList collection 20 marks In this question .pdf

  • 1. Question 1: MiniList collection [20 marks] In this question you are going to produce a simplified collection type called MyMiniList. MyMiniList will work in a similar way to ArrayList. Internally, it will use an array, you will have to reorganise and grow the array as the MiniList is updated through use of its methods. Inside the template is an interface called MiniList. MyMiniList must implement this interface and be implemented with a single generic type. Also included in the template is a simple set of tests for you to verify your implementation against. You will receive the following marks for correctly implementing each of the interfaces methods and a constructor. Your class will need two instance variables, 1 for the current size of the list (an int) and an array of generic type T to store the elements of the list call this objectStore. i) public MyMiniList() [2 marks] Initialise the array of elements, this is a little tricky as Java Generics doesnt support arrays. There are a couple of approaches you can use. This is the easiest and is moderately type safe, however, IntelliJ will give you some warnings: objectStore = (T[]) new Object[10]; Initially, set the size of this array to be 10. Also set your size variable to be 0. ii) public void add(T element) [3 marks] Elements are added to the end of the objectStore array if the array has space. If the array doesnt have space you will need to create a new array twice the size now required, copy in the existing elements and replace the existing objectStore with this new array. System.arrayCopy is useful to achieve this but there are other methods you could use. You can then add in the new element and update the size variable. iii) public T get(int index) [2 marks] Check that the index given is with the required bounds. You can use the built in method Objects.checkIndex to do this (no imports required). If the index is valid return the item at the index iv) public int getIndex(T element) [2 marks] Search through the list for the first occurrence of the element given as an argument. If found return its index. Otherwise return -1. v) public void set(int index, T element); [2 marks] Check if the index is valid. If so set the value at the index to be the element given in the second parameter. public int size(); [1 mark] Return the size of the list. (Make sure you return the size of list not the size of the underlying array) vi) public T remove(int index); [4 marks] Check if a valid index has been given. If so remove the element and return it. You will need to move down the end of the array after the removal point so there is no gap and adjust your size property accordingly. vii) public boolean remove(T element); [4 marks] Search the list for the first instance of the element and remove it. Again you will need to shift the array down to fill the gap left. TIP: you might be able to use the previous method to help you. viii) public void clear(); [1 mark] Empty the list and reset the size to 0.