SlideShare a Scribd company logo
1 of 8
Page 1 of 2 Updated on: 2020-01-23
CPS 151/Spring 2020 In-class Assignment 1
Textbook reference: See discussion of how to insert (add) and
remove (delete) an item in a partially filled
array while maintaining order of existing items (subsections
6.3.6, 6.3.7). The concept of a partially filled array
is discussed in subsection 6.1.3.
The program is supposed to:
a) allocate storage for an array of integers of a size specified by
the user
b) fill the array partially with increasing values (number of
values chosen by the user)
c) check that the item at a user specified index position can be
removed, maintaining order of other elements
d) check that a new item can be added at a user specified index
position, also maintaining order of other
elements.
Study the startup code and complete the program.
You need to complete the validity checks for index position
specified by the user. Note that only existing items
may be removed, but a new item could be added right after the
existing items in the list.
Sample output from startup code
Page 2 of 2 Updated on: 2020-01-23
Sample Output (successful insert/delete)
Sample output with invalid delete/insert positions
final static Scanner cin = new Scanner(System.in);
static int currentSize; // number of values actually in the
intList
static int[] intList; // reference to the partially filled array
storage
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
out.println("CPS 151 ICA 1 by
_________________________");
setup();
printList(intList, "nOriginal List");
checkDeletion();
checkInsertion();
printList(intList, "nFinal List");
out.println("nGoodbye");
} // end main
private static void checkDeletion() {
// Checking deletion
int position = getInt("nPosition to delete from: ");
// check validity of position
if (2 + 2 == 5) {
shiftUp(position);
currentSize--;
printList(intList, "nList after deletion");
} else {
out.println("Invalid delete position, no changes made");
} // end if
} // end method
private static void checkInsertion() {
// Checking insertion
int value = getInt("nValue to insert: ");
int position = getInt("At what position? ");
// check validity of position
if (2 + 2 == 5) {
shiftDown(position);
intList[position] = value;
currentSize++;
printList(intList, "nList after insertion");
} else {
out.println("Invalid insert position, no changes made");
} // end if
} // end method
// fills array with increasing values
private static void fillArrayInc(final int startValue, final int
howMany) {
// Validity check
if (howMany < 1 || howMany > intList.length) {
terminate("fillArrayInc: illegal argument, howMany = "
+ howMany);
}
for (int k = 0; k < howMany; k++) {
intList[k] = startValue + k;
}
currentSize = howMany;
} //end setSequenced
// prints partially filled array with a legend
private static void printList(final int[] arr, final String
legend) {
out.println(legend);
for (int k = 0; k < currentSize; k++) {
out.print(" " + arr[k]);
}
out.println();
} // end printList
// move items from pos+1:currentSize-1 one position up
(lower subscripts)
private static void shiftUp(int pos) {
// Write the code
} // end shiftUp
// move items from pos:currentSize-1 one position down
(higher subscripts)
private static void shiftDown(int pos) {
// Write the code
} // end shiftDown
private static void setup() {
int maxSize, initSize;
maxSize = getInt("Enter the maximum size: ");
intList = new int[maxSize];
initSize = getInt("Enter the starting size: ");
if (initSize > maxSize) {
terminate("starting size cannot be greater than
maximum size");
}
fillArrayInc(100, initSize);
} // end method
private static int getInt(String prompt) {
out.print(prompt);
return cin.nextInt();
} // end method
private static void terminate(String message) {
out.println("Error: " + message);
exit(0);
} // end terminate

More Related Content

Similar to Page 1 of 2 Updated on 2020-01-23 CPS 151Spring 2020 .docx

public class DoubleArraySeq implements Cloneable {    Priva.pdf
public class DoubleArraySeq implements Cloneable {     Priva.pdfpublic class DoubleArraySeq implements Cloneable {     Priva.pdf
public class DoubleArraySeq implements Cloneable {    Priva.pdfannaimobiles
 
Why following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdfWhy following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdfgopalk44
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfkostikjaylonshaewe47
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docxbriancrawford30935
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfNicholasflqStewartl
 
Create a Dynamic Array container with this user interface Ge.pdf
Create a Dynamic Array container with this user interface  Ge.pdfCreate a Dynamic Array container with this user interface  Ge.pdf
Create a Dynamic Array container with this user interface Ge.pdfsktambifortune
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.comDavisMurphyB81
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxdickonsondorris
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to HooksSoluto
 
Should be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdfShould be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdffashionscollect
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdfalmaniaeyewear
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com donaldzs157
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfdeepaksatrker
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
this file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfthis file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfflashfashioncasualwe
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
 

Similar to Page 1 of 2 Updated on 2020-01-23 CPS 151Spring 2020 .docx (20)

public class DoubleArraySeq implements Cloneable {    Priva.pdf
public class DoubleArraySeq implements Cloneable {     Priva.pdfpublic class DoubleArraySeq implements Cloneable {     Priva.pdf
public class DoubleArraySeq implements Cloneable {    Priva.pdf
 
Why following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdfWhy following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdf
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
project2.classpathproject2.project project2 .docx
project2.classpathproject2.project  project2 .docxproject2.classpathproject2.project  project2 .docx
project2.classpathproject2.project project2 .docx
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdf
 
Create a Dynamic Array container with this user interface Ge.pdf
Create a Dynamic Array container with this user interface  Ge.pdfCreate a Dynamic Array container with this user interface  Ge.pdf
Create a Dynamic Array container with this user interface Ge.pdf
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docx
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
Should be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdfShould be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdf
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdf
 
New text document
New text documentNew text document
New text document
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
 
this file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdfthis file has a complete array-based MultiSet, but not the code need.pdf
this file has a complete array-based MultiSet, but not the code need.pdf
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
 

More from karlhennesey

Resources Assigned readings, ERRs, the Internet,and other resources.docx
Resources Assigned readings, ERRs, the Internet,and other resources.docxResources Assigned readings, ERRs, the Internet,and other resources.docx
Resources Assigned readings, ERRs, the Internet,and other resources.docxkarlhennesey
 
Resource Review Documenting the Face of America Roy Stryker and.docx
Resource Review Documenting the Face of America Roy Stryker and.docxResource Review Documenting the Face of America Roy Stryker and.docx
Resource Review Documenting the Face of America Roy Stryker and.docxkarlhennesey
 
Resource Review Thelma Golden--How Art Gives Shape to Cultural C.docx
Resource Review Thelma Golden--How Art Gives Shape to Cultural C.docxResource Review Thelma Golden--How Art Gives Shape to Cultural C.docx
Resource Review Thelma Golden--How Art Gives Shape to Cultural C.docxkarlhennesey
 
Resource Review Representational Cityscape, and Ch. 3 of Oxfo.docx
Resource Review Representational Cityscape, and Ch. 3 of Oxfo.docxResource Review Representational Cityscape, and Ch. 3 of Oxfo.docx
Resource Review Representational Cityscape, and Ch. 3 of Oxfo.docxkarlhennesey
 
Resource Part 2 of Terrorism TodayYou work on a national se.docx
Resource Part 2 of Terrorism TodayYou work on a national se.docxResource Part 2 of Terrorism TodayYou work on a national se.docx
Resource Part 2 of Terrorism TodayYou work on a national se.docxkarlhennesey
 
Resources Appendix A, The Home Depot, Inc. Annual Report in Fun.docx
Resources Appendix A, The Home Depot, Inc. Annual Report in Fun.docxResources Appendix A, The Home Depot, Inc. Annual Report in Fun.docx
Resources Appendix A, The Home Depot, Inc. Annual Report in Fun.docxkarlhennesey
 
Resources Annotated Bibliography document. Research five websites t.docx
Resources Annotated Bibliography document. Research five websites t.docxResources Annotated Bibliography document. Research five websites t.docx
Resources Annotated Bibliography document. Research five websites t.docxkarlhennesey
 
Resources American History, Primary Source Investigator;Cente.docx
Resources American History, Primary Source Investigator;Cente.docxResources American History, Primary Source Investigator;Cente.docx
Resources American History, Primary Source Investigator;Cente.docxkarlhennesey
 
Resource University of Phoenix Material Data SetDownload the.docx
Resource University of Phoenix Material Data SetDownload the.docxResource University of Phoenix Material Data SetDownload the.docx
Resource University of Phoenix Material Data SetDownload the.docxkarlhennesey
 
Resource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docx
Resource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docxResource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docx
Resource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docxkarlhennesey
 
Resource Films on DemandCrime and Punishment”Experiment Res.docx
Resource Films on DemandCrime and Punishment”Experiment Res.docxResource Films on DemandCrime and Punishment”Experiment Res.docx
Resource Films on DemandCrime and Punishment”Experiment Res.docxkarlhennesey
 
Resource Managing Environmental Issues Simulation(or research a.docx
Resource Managing Environmental Issues Simulation(or research a.docxResource Managing Environmental Issues Simulation(or research a.docx
Resource Managing Environmental Issues Simulation(or research a.docxkarlhennesey
 
Resource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docx
Resource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docxResource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docx
Resource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docxkarlhennesey
 
Resource Ch. 9 of Introduction to Business Complete the table in .docx
Resource Ch. 9 of Introduction to Business Complete the table in .docxResource Ch. 9 of Introduction to Business Complete the table in .docx
Resource Ch. 9 of Introduction to Business Complete the table in .docxkarlhennesey
 
Resource Ch. 3 of ManagementIdentify a time in your life wh.docx
Resource Ch. 3 of ManagementIdentify a time in your life wh.docxResource Ch. 3 of ManagementIdentify a time in your life wh.docx
Resource Ch. 3 of ManagementIdentify a time in your life wh.docxkarlhennesey
 
Resource Significant Health Care Event Paper Grading Criteria.docx
Resource Significant Health Care Event Paper Grading Criteria.docxResource Significant Health Care Event Paper Grading Criteria.docx
Resource Significant Health Care Event Paper Grading Criteria.docxkarlhennesey
 
Resource Ch. 3 of Financial AccountingComplete Exercises E3.docx
Resource Ch. 3 of Financial AccountingComplete Exercises E3.docxResource Ch. 3 of Financial AccountingComplete Exercises E3.docx
Resource Ch. 3 of Financial AccountingComplete Exercises E3.docxkarlhennesey
 
Resource University of Phoenix Material Appendix AIdentify.docx
Resource University of Phoenix Material Appendix AIdentify.docxResource University of Phoenix Material Appendix AIdentify.docx
Resource University of Phoenix Material Appendix AIdentify.docxkarlhennesey
 
Resource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docx
Resource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docxResource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docx
Resource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docxkarlhennesey
 
Resource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docx
Resource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docxResource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docx
Resource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docxkarlhennesey
 

More from karlhennesey (20)

Resources Assigned readings, ERRs, the Internet,and other resources.docx
Resources Assigned readings, ERRs, the Internet,and other resources.docxResources Assigned readings, ERRs, the Internet,and other resources.docx
Resources Assigned readings, ERRs, the Internet,and other resources.docx
 
Resource Review Documenting the Face of America Roy Stryker and.docx
Resource Review Documenting the Face of America Roy Stryker and.docxResource Review Documenting the Face of America Roy Stryker and.docx
Resource Review Documenting the Face of America Roy Stryker and.docx
 
Resource Review Thelma Golden--How Art Gives Shape to Cultural C.docx
Resource Review Thelma Golden--How Art Gives Shape to Cultural C.docxResource Review Thelma Golden--How Art Gives Shape to Cultural C.docx
Resource Review Thelma Golden--How Art Gives Shape to Cultural C.docx
 
Resource Review Representational Cityscape, and Ch. 3 of Oxfo.docx
Resource Review Representational Cityscape, and Ch. 3 of Oxfo.docxResource Review Representational Cityscape, and Ch. 3 of Oxfo.docx
Resource Review Representational Cityscape, and Ch. 3 of Oxfo.docx
 
Resource Part 2 of Terrorism TodayYou work on a national se.docx
Resource Part 2 of Terrorism TodayYou work on a national se.docxResource Part 2 of Terrorism TodayYou work on a national se.docx
Resource Part 2 of Terrorism TodayYou work on a national se.docx
 
Resources Appendix A, The Home Depot, Inc. Annual Report in Fun.docx
Resources Appendix A, The Home Depot, Inc. Annual Report in Fun.docxResources Appendix A, The Home Depot, Inc. Annual Report in Fun.docx
Resources Appendix A, The Home Depot, Inc. Annual Report in Fun.docx
 
Resources Annotated Bibliography document. Research five websites t.docx
Resources Annotated Bibliography document. Research five websites t.docxResources Annotated Bibliography document. Research five websites t.docx
Resources Annotated Bibliography document. Research five websites t.docx
 
Resources American History, Primary Source Investigator;Cente.docx
Resources American History, Primary Source Investigator;Cente.docxResources American History, Primary Source Investigator;Cente.docx
Resources American History, Primary Source Investigator;Cente.docx
 
Resource University of Phoenix Material Data SetDownload the.docx
Resource University of Phoenix Material Data SetDownload the.docxResource University of Phoenix Material Data SetDownload the.docx
Resource University of Phoenix Material Data SetDownload the.docx
 
Resource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docx
Resource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docxResource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docx
Resource Ch. 6 & 7 of Financial AccountingComplete Brief Ex.docx
 
Resource Films on DemandCrime and Punishment”Experiment Res.docx
Resource Films on DemandCrime and Punishment”Experiment Res.docxResource Films on DemandCrime and Punishment”Experiment Res.docx
Resource Films on DemandCrime and Punishment”Experiment Res.docx
 
Resource Managing Environmental Issues Simulation(or research a.docx
Resource Managing Environmental Issues Simulation(or research a.docxResource Managing Environmental Issues Simulation(or research a.docx
Resource Managing Environmental Issues Simulation(or research a.docx
 
Resource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docx
Resource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docxResource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docx
Resource Ch. 9 of Introduction to Business Create a 5-to-7 slide .docx
 
Resource Ch. 9 of Introduction to Business Complete the table in .docx
Resource Ch. 9 of Introduction to Business Complete the table in .docxResource Ch. 9 of Introduction to Business Complete the table in .docx
Resource Ch. 9 of Introduction to Business Complete the table in .docx
 
Resource Ch. 3 of ManagementIdentify a time in your life wh.docx
Resource Ch. 3 of ManagementIdentify a time in your life wh.docxResource Ch. 3 of ManagementIdentify a time in your life wh.docx
Resource Ch. 3 of ManagementIdentify a time in your life wh.docx
 
Resource Significant Health Care Event Paper Grading Criteria.docx
Resource Significant Health Care Event Paper Grading Criteria.docxResource Significant Health Care Event Paper Grading Criteria.docx
Resource Significant Health Care Event Paper Grading Criteria.docx
 
Resource Ch. 3 of Financial AccountingComplete Exercises E3.docx
Resource Ch. 3 of Financial AccountingComplete Exercises E3.docxResource Ch. 3 of Financial AccountingComplete Exercises E3.docx
Resource Ch. 3 of Financial AccountingComplete Exercises E3.docx
 
Resource University of Phoenix Material Appendix AIdentify.docx
Resource University of Phoenix Material Appendix AIdentify.docxResource University of Phoenix Material Appendix AIdentify.docx
Resource University of Phoenix Material Appendix AIdentify.docx
 
Resource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docx
Resource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docxResource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docx
Resource The Threat of Bioterrorism VideoWrite a 700 to 850-w.docx
 
Resource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docx
Resource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docxResource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docx
Resource Ch. 14 of Introduction to Psychology Create an 8 to 12 s.docx
 

Recently uploaded

OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 

Recently uploaded (20)

Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 

Page 1 of 2 Updated on 2020-01-23 CPS 151Spring 2020 .docx

  • 1. Page 1 of 2 Updated on: 2020-01-23 CPS 151/Spring 2020 In-class Assignment 1 Textbook reference: See discussion of how to insert (add) and remove (delete) an item in a partially filled array while maintaining order of existing items (subsections 6.3.6, 6.3.7). The concept of a partially filled array is discussed in subsection 6.1.3. The program is supposed to: a) allocate storage for an array of integers of a size specified by the user b) fill the array partially with increasing values (number of values chosen by the user) c) check that the item at a user specified index position can be removed, maintaining order of other elements d) check that a new item can be added at a user specified index position, also maintaining order of other elements.
  • 2. Study the startup code and complete the program. You need to complete the validity checks for index position specified by the user. Note that only existing items may be removed, but a new item could be added right after the existing items in the list. Sample output from startup code Page 2 of 2 Updated on: 2020-01-23 Sample Output (successful insert/delete) Sample output with invalid delete/insert positions final static Scanner cin = new Scanner(System.in); static int currentSize; // number of values actually in the intList static int[] intList; // reference to the partially filled array storage
  • 3. /** * @param args the command line arguments */ public static void main(String[] args) { out.println("CPS 151 ICA 1 by _________________________"); setup(); printList(intList, "nOriginal List"); checkDeletion(); checkInsertion(); printList(intList, "nFinal List"); out.println("nGoodbye"); } // end main private static void checkDeletion() { // Checking deletion int position = getInt("nPosition to delete from: ");
  • 4. // check validity of position if (2 + 2 == 5) { shiftUp(position); currentSize--; printList(intList, "nList after deletion"); } else { out.println("Invalid delete position, no changes made"); } // end if } // end method private static void checkInsertion() { // Checking insertion int value = getInt("nValue to insert: "); int position = getInt("At what position? "); // check validity of position if (2 + 2 == 5) { shiftDown(position);
  • 5. intList[position] = value; currentSize++; printList(intList, "nList after insertion"); } else { out.println("Invalid insert position, no changes made"); } // end if } // end method // fills array with increasing values private static void fillArrayInc(final int startValue, final int howMany) { // Validity check if (howMany < 1 || howMany > intList.length) { terminate("fillArrayInc: illegal argument, howMany = " + howMany); } for (int k = 0; k < howMany; k++) { intList[k] = startValue + k;
  • 6. } currentSize = howMany; } //end setSequenced // prints partially filled array with a legend private static void printList(final int[] arr, final String legend) { out.println(legend); for (int k = 0; k < currentSize; k++) { out.print(" " + arr[k]); } out.println(); } // end printList // move items from pos+1:currentSize-1 one position up (lower subscripts) private static void shiftUp(int pos) { // Write the code
  • 7. } // end shiftUp // move items from pos:currentSize-1 one position down (higher subscripts) private static void shiftDown(int pos) { // Write the code } // end shiftDown private static void setup() { int maxSize, initSize; maxSize = getInt("Enter the maximum size: "); intList = new int[maxSize]; initSize = getInt("Enter the starting size: "); if (initSize > maxSize) { terminate("starting size cannot be greater than maximum size"); } fillArrayInc(100, initSize);
  • 8. } // end method private static int getInt(String prompt) { out.print(prompt); return cin.nextInt(); } // end method private static void terminate(String message) { out.println("Error: " + message); exit(0); } // end terminate