SlideShare ist ein Scribd-Unternehmen logo
1 von 11
CSE 110 - ASSIGNMENT # 7
Due: Wednesday April 13 by 10:00PM
Maximum Points: 20 pts
What This Assignment Is About:
Arrays (chapter 6)
Your programming assignments require individual work and
effort to be of any benefit. Every student must work
independently on his or her assignments. This means that every
student must ensure that neither a soft copy nor a
hard copy of their work gets into the hands of another student.
Sharing your assignments with others in any way is
NOT permitted.
Violations of the University Academic Integrity policy will not
be ignored.
The university academic integrity policy is found at
http://www.asu.edu/studentlife/judicial/integrity.html
Assignments Documentation:
At the beginning of each programming assignment you must
have a comment block with the following
information:
/*------------------------------------------------------------------------
-
// AUTHOR: your name
// FILENAME: title of the source file
// SPECIFICATION: description of the program
// YOUR Lab Letter and Name of the TA for your Closed lab
// FOR: CSE 110- homework #- days and time of your class
// TIME SPENT: how long it took you to complete the
assignment
//----------------------------------------------------------------------*/
Part 1: Written exercises (7 pts)
Note: The answers to the following questions should be typed in
the block of comments in the Assignemnt7.java
file. Please make sure they're commented out (green). Type
them neatly and make them easy to read for the graders.
You will not receive any partial points for an incorrect answer.
1. Which of the following are valid array declarations? Explain
your answers. (2 pts)
a. char[] charArray = new char[26];
b. int[] words = new words[10];
c. char[] charArray = "Computer Science";
d. double[3] nums = {3.5, 35.1, 32.0};
http://www.asu.edu/studentlife/judicial/integrity.html
Turki Saad Alshehri
Turki Saad Alshehri
Turki Saad Alshehri
Turki Saad Alshehri
http://www.eas.asu.edu/~csedept/
2. Consider the following method (5 pts)
public static int mystery(int[] list)
{ int x =0;
for (int i=1; i< list.length; i++)
{ int y = list[i] -list[0];
if (y > x)
x =y;
}
return x;
}
What value does the method return when passed each of the
following arrays?
a. {5}
b. {3, 12}
c. {4, 2, 10, 8}
d. {1, 9, 3, 5, 7}
e. {8, 2, 10, 4, 10, 9}
Part 2: Programming (13 points):
Your assignment is to create a class called NumberCollection in
a file called NumberCollection.java. (there is no
main method in this class). A class NumberCollection has two
private data members:
1. an array of integers. The variable name for the array of
integers is numberArray. (Declare the array as a
private data member, no need to reserve space at the time of
declaration)
2. a count (integer) as instance variables. The variable count
keeps track how many integers are stored in the
array.
Note: You need to distinguish the array size (capacity) and
"count" that keeps track of numbers added to this
array so far.
The class NumberCollection must include the following
constructor and methods. (If your class does not contain
any of the following methods, points will be deducted.)
Method Description of the Method
public NumberCollection(int arraySize)
It constructs a NumberCollection object with an array
capacity specified by the integer parameter "arraySize",
i.e., you will now be reserving space for the private
integer array declared above. Hint: Do not re-declare
the array.
private int indexOf(int searchingNum)
It returns the index of the number specified by the
parameter is located. If the number is not found, it
returns -1. It is a service (helper) method.
public boolean addNumber(int numberToAdd)
The method checks if the integer specified by the
parameter exists in the array (This can be done using the
indexOf method to see if it returns -1 or not) and also
checks if the array has not reached its capacity. If both
are satisfied, the number is added to the array at the
smallest available index. If the array reached its
capacity, double its size by calling the method
doubleArrayCapacity() and add the number. If the
number is added successfully, then the method returns
true. If the number already exists in the array, the new
Save the NumberCollection class in a file called
NumberCollection.java and use the following program stored
in Assignment7.java, which has the main method to create new
NumberCollection objects and to test your
class. You do NOT need to modify Assignment7.java.
The program will ask a user to enter a size for the array. Then it
will show the following menu to a user:
Command Options
-----------------------------------
a: add an integer in the array
b: remove an integer from the array
c: display the array
d: compute and display the range
e: compute and display the average
?: display the menu again
q: quit
Then it will ask a user to enter one of the above commands.
Based on the user's choice, the program needs to
perform corresponding operation. This will be done by using a
method you define in the NumberCollection class.
The program will terminate when a user enters 'q'.
Sample Output: (the inputs entered by a user are shown in red)
Please enter a size for the array.
5
Command Options
-----------------------------------
a: add an integer in the array
b: remove an integer from the array
number will not be added, and the method returns false.
public boolean remove(int numberToRemove)
The method checks if the integer specified by the
parameter exists in the array (This can be done using the
indexOf method to see if it returns -1 or not) and if it
does, it removes the number and then it shifts all the
integers to the left and returns true.
Otherwise, it returns false.
private void doubleArrayCapacity()
It is a service (helper) method and doubles the capacity
of the numberArray. Please see the example in page 353,
the method increaseSize() as a reference.
public int findRange()
It finds the range of values in the array. The range is
defined as 1 more than the difference between the
maximum and minimum in the array.
Hint: Create two helper/service (private) methods for
finding the maximum and minimum.
public int computeAvg()
It computes and returns the average of numbers stored in
the numberArray so far (at the time when this method is
called.) If the array is empty, return 0.
public String toString( )
Returns a String containing a list of numbers stored in
the numberArray. An example of such string can be:
{3, 6, -1, 3, 23, -50, 43}
The string should start with a '{' and end with a '}'.
Assignment7.java
c: display the array
d: compute the range
e: compute and display the average
?: display the menu again
q: quit this program
Please enter a command or type ?
a
Please enter an integer to add.
1
1 successfully added.
Please enter a command or type ?
a
Please enter an integer to add.
2
2 successfully added.
Please enter a command or type ?
a
Please enter an integer to add.
3
3 successfully added.
Please enter a command or type ?
a
Please enter an integer to add.
4
4 successfully added.
Please enter a command or type ?
a
Please enter an integer to add.
6
6 successfully added.
Please enter a command or type ?
c
{1, 2, 3, 4, 6}
Please enter a command or type ?
d
The range is:6
Please enter a command or type ?
f
The average is: 3.2
Please enter a command or type ?
r
Invalid input!
Please enter a command or type ?
b
Please enter an integer to remove.
3
3 successfully removed.
Please enter a command or type ?
c
{1, 2, 4, 6}
Please enter a command or type ?
b
Please enter an integer to remove.
40
40 is not in the array. 40 was not removed.
Please enter a command or type ?
c
{1, 2, 4, 6}
Please enter a command or type ?
a
Please enter an integer to add.
10
10 successfully added.
Please enter a command or type ?
a
Please enter an integer to add.
12
12 successfully added.
Please enter a command or type ?
a
Please enter an integer to add.
14
14 successfully added.
Please enter a command or type ?
c
{1, 2, 4, 6, 10, 12, 14}
Please enter a command or type ?
q
Helpful hints for doing this assignment:
· work on it in steps – write one method, test it with a test
driver and make sure it works before going
on to the next method
· always make sure your code compiles before you add
another method
· your methods should be able to be called in any order
Submit your homework by following the instructions below:
*****************************************************
****************************
Go to the course web site (my.asu.edu), and then click on the
on-line Submission tab.
Submit all two files: Assignment7.java, and
NumberCollection.java on-line. Make
sure to choose HW7 from drop-down box.
Important Note: You may resubmit as many times as you like
until the deadline, but we will
only mark your last submission.
NO LATE ASSIGNMENTS WILL BE ACCEPTED
http://my.asu.edu/

Weitere ähnliche Inhalte

Ähnlich wie CSE 110 - ASSIGNMENT # 7 Due Wednesday April 13 by .docx

object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lecturesMSohaib24
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Codemotion
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in Carshpreetkaur07
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writingUmme habiba
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2Rajendran
 
Data structures cs301 power point slides lecture 01
Data structures   cs301 power point slides lecture 01Data structures   cs301 power point slides lecture 01
Data structures cs301 power point slides lecture 01shaziabibi5
 
CS301-lec01.ppt
CS301-lec01.pptCS301-lec01.ppt
CS301-lec01.pptomair31
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 

Ähnlich wie CSE 110 - ASSIGNMENT # 7 Due Wednesday April 13 by .docx (20)

object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
Arrays
ArraysArrays
Arrays
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 
LectureNotes-05-DSA
LectureNotes-05-DSALectureNotes-05-DSA
LectureNotes-05-DSA
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays
ArraysArrays
Arrays
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018Mario Fusco - Lazy Java - Codemotion Milan 2018
Mario Fusco - Lazy Java - Codemotion Milan 2018
 
Lazy java
Lazy javaLazy java
Lazy java
 
Lazy Java
Lazy JavaLazy Java
Lazy Java
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
Ch08
Ch08Ch08
Ch08
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Data structures cs301 power point slides lecture 01
Data structures   cs301 power point slides lecture 01Data structures   cs301 power point slides lecture 01
Data structures cs301 power point slides lecture 01
 
CS301-lec01.ppt
CS301-lec01.pptCS301-lec01.ppt
CS301-lec01.ppt
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 

Mehr von aryan532920

According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxAccording to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxaryan532920
 
According to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxAccording to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxaryan532920
 
According to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxAccording to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxaryan532920
 
According to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxAccording to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxaryan532920
 
According to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxAccording to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxaryan532920
 
According to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxAccording to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxaryan532920
 
According to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxAccording to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxaryan532920
 
According to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxAccording to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxaryan532920
 
According to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxAccording to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxaryan532920
 
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxAccording to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxaryan532920
 
According to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxAccording to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxaryan532920
 
According to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxAccording to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxaryan532920
 
According to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxAccording to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxaryan532920
 
According to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxAccording to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxaryan532920
 
According to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxAccording to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxaryan532920
 
According to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxAccording to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxaryan532920
 
According to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxAccording to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxaryan532920
 
According to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxAccording to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxaryan532920
 
According to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxAccording to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxaryan532920
 
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxAccording to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxaryan532920
 

Mehr von aryan532920 (20)

According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docxAccording to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
According to the NASW Code of Ethics section 6.04 (NASW, 2008), .docx
 
According to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docxAccording to the text, crime has been part of the human condition si.docx
According to the text, crime has been part of the human condition si.docx
 
According to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docxAccording to Ronald Story and Bruce Laurie, The dozen years between.docx
According to Ronald Story and Bruce Laurie, The dozen years between.docx
 
According to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docxAccording to Kirk (2016), most of your time will be spent work with .docx
According to Kirk (2016), most of your time will be spent work with .docx
 
According to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docxAccording to the Council on Social Work Education, Competency 5 Eng.docx
According to the Council on Social Work Education, Competency 5 Eng.docx
 
According to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docxAccording to Kirk (2016), most of our time will be spent working.docx
According to Kirk (2016), most of our time will be spent working.docx
 
According to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docxAccording to Kirk (2016), most of your time will be spent working wi.docx
According to Kirk (2016), most of your time will be spent working wi.docx
 
According to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docxAccording to Davenport (2014) the organizational value of healthcare.docx
According to Davenport (2014) the organizational value of healthcare.docx
 
According to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docxAccording to the authors, privacy and security go hand in hand; .docx
According to the authors, privacy and security go hand in hand; .docx
 
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docxAccording to Gilbert and Troitzsch (2005), Foundations of Simula.docx
According to Gilbert and Troitzsch (2005), Foundations of Simula.docx
 
According to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docxAccording to Klein (2016), using ethical absolutism and ethical .docx
According to Klein (2016), using ethical absolutism and ethical .docx
 
According to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docxAccording to Franks and Smallwood (2013), information has become.docx
According to Franks and Smallwood (2013), information has become.docx
 
According to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docxAccording to the Council on Social Work Education, Competency 5.docx
According to the Council on Social Work Education, Competency 5.docx
 
According to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docxAccording to the authors, privacy and security go hand in hand; and .docx
According to the authors, privacy and security go hand in hand; and .docx
 
According to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docxAccording to recent surveys, China, India, and the Philippines are t.docx
According to recent surveys, China, India, and the Philippines are t.docx
 
According to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docxAccording to the authors, countries that lag behind the rest of the .docx
According to the authors, countries that lag behind the rest of the .docx
 
According to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docxAccording to Peskin et al. (2013) in our course reader, Studies on .docx
According to Peskin et al. (2013) in our course reader, Studies on .docx
 
According to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docxAccording to Franks and Smallwood (2013), information has become the.docx
According to Franks and Smallwood (2013), information has become the.docx
 
According to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docxAccording to Ang (2011), how is Social Media management differen.docx
According to Ang (2011), how is Social Media management differen.docx
 
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docxAccording to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
According to (Alsaidi & Kausar (2018), It is expected that by 2020,.docx
 

Kürzlich hochgeladen

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 

Kürzlich hochgeladen (20)

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

CSE 110 - ASSIGNMENT # 7 Due Wednesday April 13 by .docx

  • 1. CSE 110 - ASSIGNMENT # 7 Due: Wednesday April 13 by 10:00PM Maximum Points: 20 pts What This Assignment Is About: Arrays (chapter 6) Your programming assignments require individual work and effort to be of any benefit. Every student must work independently on his or her assignments. This means that every student must ensure that neither a soft copy nor a hard copy of their work gets into the hands of another student. Sharing your assignments with others in any way is NOT permitted. Violations of the University Academic Integrity policy will not be ignored. The university academic integrity policy is found at http://www.asu.edu/studentlife/judicial/integrity.html Assignments Documentation: At the beginning of each programming assignment you must have a comment block with the following information: /*------------------------------------------------------------------------ -
  • 2. // AUTHOR: your name // FILENAME: title of the source file // SPECIFICATION: description of the program // YOUR Lab Letter and Name of the TA for your Closed lab // FOR: CSE 110- homework #- days and time of your class // TIME SPENT: how long it took you to complete the assignment //----------------------------------------------------------------------*/ Part 1: Written exercises (7 pts) Note: The answers to the following questions should be typed in the block of comments in the Assignemnt7.java file. Please make sure they're commented out (green). Type them neatly and make them easy to read for the graders. You will not receive any partial points for an incorrect answer. 1. Which of the following are valid array declarations? Explain your answers. (2 pts) a. char[] charArray = new char[26]; b. int[] words = new words[10]; c. char[] charArray = "Computer Science"; d. double[3] nums = {3.5, 35.1, 32.0}; http://www.asu.edu/studentlife/judicial/integrity.html Turki Saad Alshehri
  • 3. Turki Saad Alshehri Turki Saad Alshehri Turki Saad Alshehri http://www.eas.asu.edu/~csedept/ 2. Consider the following method (5 pts) public static int mystery(int[] list) { int x =0; for (int i=1; i< list.length; i++) { int y = list[i] -list[0]; if (y > x) x =y; } return x; } What value does the method return when passed each of the following arrays? a. {5} b. {3, 12} c. {4, 2, 10, 8} d. {1, 9, 3, 5, 7} e. {8, 2, 10, 4, 10, 9} Part 2: Programming (13 points): Your assignment is to create a class called NumberCollection in a file called NumberCollection.java. (there is no
  • 4. main method in this class). A class NumberCollection has two private data members: 1. an array of integers. The variable name for the array of integers is numberArray. (Declare the array as a private data member, no need to reserve space at the time of declaration) 2. a count (integer) as instance variables. The variable count keeps track how many integers are stored in the array. Note: You need to distinguish the array size (capacity) and "count" that keeps track of numbers added to this array so far. The class NumberCollection must include the following constructor and methods. (If your class does not contain any of the following methods, points will be deducted.) Method Description of the Method public NumberCollection(int arraySize) It constructs a NumberCollection object with an array capacity specified by the integer parameter "arraySize", i.e., you will now be reserving space for the private integer array declared above. Hint: Do not re-declare the array. private int indexOf(int searchingNum) It returns the index of the number specified by the parameter is located. If the number is not found, it returns -1. It is a service (helper) method. public boolean addNumber(int numberToAdd)
  • 5. The method checks if the integer specified by the parameter exists in the array (This can be done using the indexOf method to see if it returns -1 or not) and also checks if the array has not reached its capacity. If both are satisfied, the number is added to the array at the smallest available index. If the array reached its capacity, double its size by calling the method doubleArrayCapacity() and add the number. If the number is added successfully, then the method returns true. If the number already exists in the array, the new Save the NumberCollection class in a file called NumberCollection.java and use the following program stored in Assignment7.java, which has the main method to create new NumberCollection objects and to test your class. You do NOT need to modify Assignment7.java. The program will ask a user to enter a size for the array. Then it will show the following menu to a user: Command Options ----------------------------------- a: add an integer in the array b: remove an integer from the array c: display the array d: compute and display the range e: compute and display the average ?: display the menu again q: quit Then it will ask a user to enter one of the above commands. Based on the user's choice, the program needs to
  • 6. perform corresponding operation. This will be done by using a method you define in the NumberCollection class. The program will terminate when a user enters 'q'. Sample Output: (the inputs entered by a user are shown in red) Please enter a size for the array. 5 Command Options ----------------------------------- a: add an integer in the array b: remove an integer from the array number will not be added, and the method returns false. public boolean remove(int numberToRemove) The method checks if the integer specified by the parameter exists in the array (This can be done using the indexOf method to see if it returns -1 or not) and if it does, it removes the number and then it shifts all the integers to the left and returns true. Otherwise, it returns false. private void doubleArrayCapacity() It is a service (helper) method and doubles the capacity of the numberArray. Please see the example in page 353, the method increaseSize() as a reference. public int findRange() It finds the range of values in the array. The range is defined as 1 more than the difference between the maximum and minimum in the array. Hint: Create two helper/service (private) methods for
  • 7. finding the maximum and minimum. public int computeAvg() It computes and returns the average of numbers stored in the numberArray so far (at the time when this method is called.) If the array is empty, return 0. public String toString( ) Returns a String containing a list of numbers stored in the numberArray. An example of such string can be: {3, 6, -1, 3, 23, -50, 43} The string should start with a '{' and end with a '}'. Assignment7.java c: display the array d: compute the range e: compute and display the average ?: display the menu again q: quit this program Please enter a command or type ? a Please enter an integer to add. 1 1 successfully added. Please enter a command or type ? a
  • 8. Please enter an integer to add. 2 2 successfully added. Please enter a command or type ? a Please enter an integer to add. 3 3 successfully added. Please enter a command or type ? a Please enter an integer to add. 4 4 successfully added. Please enter a command or type ? a Please enter an integer to add. 6 6 successfully added. Please enter a command or type ? c {1, 2, 3, 4, 6} Please enter a command or type ? d
  • 9. The range is:6 Please enter a command or type ? f The average is: 3.2 Please enter a command or type ? r Invalid input! Please enter a command or type ? b Please enter an integer to remove. 3 3 successfully removed. Please enter a command or type ? c {1, 2, 4, 6} Please enter a command or type ? b Please enter an integer to remove. 40 40 is not in the array. 40 was not removed. Please enter a command or type ? c {1, 2, 4, 6}
  • 10. Please enter a command or type ? a Please enter an integer to add. 10 10 successfully added. Please enter a command or type ? a Please enter an integer to add. 12 12 successfully added. Please enter a command or type ? a Please enter an integer to add. 14 14 successfully added. Please enter a command or type ? c {1, 2, 4, 6, 10, 12, 14} Please enter a command or type ? q Helpful hints for doing this assignment: · work on it in steps – write one method, test it with a test
  • 11. driver and make sure it works before going on to the next method · always make sure your code compiles before you add another method · your methods should be able to be called in any order Submit your homework by following the instructions below: ***************************************************** **************************** Go to the course web site (my.asu.edu), and then click on the on-line Submission tab. Submit all two files: Assignment7.java, and NumberCollection.java on-line. Make sure to choose HW7 from drop-down box. Important Note: You may resubmit as many times as you like until the deadline, but we will only mark your last submission. NO LATE ASSIGNMENTS WILL BE ACCEPTED http://my.asu.edu/