The purpose of this lab is to manipulate an array of integers. The assignment is to write a program that: 1. Declares an array of integers of size equal to constant int SIZE = 10. 2. Implements the following methods: A method that displays a menu. The menu should be displayed after each completed menu selection. A method that prompts the user to initialize the array. The entire array does not need to be initialized. The user may enter only as many (or as few) values as they would like in the array. The user will enter a negative value to indicate no more to be added. Hint: This implies that the number of elements in the array does not necessarily have to be the same as the maximum size of the array. A method that displays the contents of the array. Only elements currently contained in the array should be horizontally displayed. A method that displays the minimum, maximum, sum and average of all the elements currently contained in the array. A method that accepts a number and determines how many times (if any) that number appears as an element in the array. A method that allows the user to add a number to the end of the array. A method that allows you to insert a specified number at a specified index within the currently filled portion of the array. Hint: In order to accomplish this, the method must first check to see if there is room in the array to accept a new number. If the array is currently full (e.g. number of elements equals the maximum size of the array) then the user has to first delete an element from the array. Think carefully about what an insert into the array implies. The physical size of the array cannot change, therefore what must happen if a value is to be inserted somewhere in the middle of the array without losing any of the existing elements. A method that removes an element at a specified index in the array. Hint: As with the insert method, the physical size of the array cannot change, therefore how could we simulate an element of the array being deleted? CSCI 125 Array Manipulation Prof. Kadri Page 2 of 4 Sample run: Menu only displayed once here. Your program should display the menu after each completed menu selection. 1. Initialize Array 2. Display Array 3. Add element to the end 4. Add an element at a specific index 5. Remove an element at specific index 6. Show min, max, sum and average 7. Search 8. Exit 1. Initialize Array Enter integer values to fill the array -ve value to stop: 1 2 3 4 5 6 8 -9 2. Display Array 1 2 3 4 5 6 8 6. Show min, max, sum and average Min=1 Max=8 Sum=29 Average=4.14 7. Search Enter number to search for: 2 2 occurs 1 time. 5. Remove an element at specific index Enter index between 0 and 6 7 Invalid index Enter index between 0 and 6 1 2. Display Array 1 3 4 5 6 8 4. Add an element at a specific index Enter index between 0 and 5 6 Invalid index Enter index between 0 and 5 3 Enter number to insert 9 CSCI 125 Array Manipulation Prof. Kadri Page 3 of 4 2. Display Array 1 3 4 9 5 6 8 1. Initialize Array Enter integer values to fill the array -ve value to stop: 1 2 3 4 5 6 7 8 9 10 11 -9 Array is full. One or more numbers could not be inserted 2. Display Array 1 2 3 4 5 6 7 8 9 10 3. Add element to the end Array is full. 8. Exit Goodby import java.util.Scanner; public class ArrayMenu { static int count; static Scanner kb = new Scanner(System.in); public static void main() { int item=0; int[] numArray=new int[100]; count=0; while (item !=8) { menu(); item=kb.nextInt(); if (item==1) initializeArray(numArray); else if (item==2) printArray(numArray); } System.out.println("Goodby!"); } public static void menu() { System.out.println("1. Initialize Array"); System.out.println("2. Display Array"); System.out.println("3. Add element to the end"); System.out.println("4. Add an element at a specific index"); System.out.println("5. Remove an element at specific index"); System.out.println("6. Show min, max, sum and average"); System.out.println("7. Search"); System.out.println("8. Exit"); System.out.print(": "); } public static void initializeArray(int[] arr) { count=0; int num; System.out.print("Enter integer values to fill the array -vevalue to stop: "); do { num = kb.nextInt(); if (num >=0) { arr[count]=num; count++; } } while (num > 0); } public static void printArray(int[] arr) { for (int i=0; i< count; i++) System.out.print(arr[i]+" "); System.out.println(); } }
CODING LANGAUGE JAVA
In: Computer Science
In java What program would you write to solve the following problems and why does it work? Please also comment on other students’ code at least three times. 1) Implement MyArrayStack (constructor, push, pop, peek and isEmpty), and MyLinkedQueue with both next and previous pointers (constructor, enqueuer/offer, dequeuer/poll, peek and isEmpty), and write the following two program to test them. You must use MyArrayList or MyLinkedList for the implementation. 2) For stack testing, write a program to check if a string has matching parenthesis such as “(())”, but not “)(“. 3) For stack testing, use it to “Evaluating Expressions” using the algorithm given in the class.
What program would you write to solve the following problems and why does it work? Please also comment on other students’ code at least three times. 1) Add support for exponent ~ for the problem in the previous discussion question. 2) An animal shelter, which holds only dogs and cats, operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog, and dequeueCat. You may use the myLinkedlist data structure you created in previous discussion question. 3) You have an integer and you can flip exactly one bit from a O to a 1. Write code to find the length of the longest sequence of 1 s you could create. EXAMPLE Input: 1775 (or: 11011101111) Output: 8.
In: Computer Science
How can an information management strategy reduce the costs of IT systems and investments?
In: Computer Science
View 2
Seneca Courses Inc.
Product Spreadsheet
All the course books are maintained on the following Product spreadsheet. SCI is currently having difficulty searching for books written by the same author, and would like the new database system to list each author separately. There can be one or many authors for each book, but there is no limit to the number of authors of a book.
PROD ID |
TITLE |
EDITION |
Purchase Cost |
Retail Price |
AUTHOR |
100860 |
DATABASE SYSTEMS: DESIGN AND IMPLEMENTATION |
THIRD EDITION |
$84.98 |
$99.98 |
CARLOS CORONEL, PETER ROB |
100861 |
DATABASE SYSTEMS: DESIGN AND IMPLEMENTATION |
FOURTH EDITION |
$92.82 |
$109.20 |
CARLOS CORONEL, PETER ROB |
100871 |
MODERN RETAILING |
FOURTH EDITION |
$88.36 |
$110.45 |
DANIEL CASTON, JENNY TAPSCOTT |
100890 |
UNDERSTANDING MICROSOFT ACCESS |
NINTH EDITION |
$65.52 |
$72.80 |
PIERRE LEBLAND, ROBERT COBB |
102130 |
ORACLE: INTRODUCTION TO PL/SQL |
$53.24 |
$59.15 |
PHILIP ROBB |
|
200376 |
ORACLE: ADVANCED PL/SQL DEVELOPMENT |
$64.26 |
$71.40 |
PHILIP ROBB, DAN CHEN |
Business Rules:
1. PURCHASE COST the default value is 0.
2. RETAIL PRICE must always have a value.
Normalize the above user view. Document all steps including UNF, 1NF, Dependencies, 2NF, and 3NF and explain or list the primary key and foreign
In: Computer Science
Why is SolarWinds Network Performance Monitoring Tool the best tool?
In: Computer Science
View 3
Seneca Courses Inc.
Employee Forms
All employee information for SCI is maintained on file forms. The following are sample employee information forms:
EMP_ID |
7839 |
EMP_ID |
7654 |
|||
EMP_NAME |
JOHN CHIU |
EMP_NAME |
ANDRE MARTIN |
|||
SOC_INS |
123-234-345 |
SOC_INS |
678-345-123 |
|||
POSITION |
MANAGER |
POSITION |
SALES |
|||
SUPERVISOR |
SUPERVISOR |
JOHN CHIU |
||||
HIREDATE |
November 13, 1999 |
HIREDATE |
September 24, 1999 |
EMP_ID |
7434 |
EMP_ID |
7435 |
|||
EMP_NAME |
PARVEZ RAI |
EMP_NAME |
DANIEL CHOY |
|||
SOC_INS |
234-123-432 |
SOC_INS |
345-312-234 |
|||
POSITION |
SALES |
POSITION |
CLERK |
|||
SUPERVISOR |
JOHN CHIU |
SUPERVISOR |
||||
HIREDATE |
June 24, 1980 |
HIREDATE |
August 4, 1998 |
Business Rules:
1. SOC_INS must always be different for each employee.
2. EMP_NAME must always have a value.
Normalize the above user view. Document all steps including UNF, 1NF, Dependencies, 2NF, and 3NF and explain or list the primary key and foreign
In: Computer Science
How computer Hardware is protected, Explain Dual-Mode Operation concept for Hardware protection?
In: Computer Science
How do you differentiate layered approach from Micro-kernel approach and Modular approach. Compare their advantages and disadvantages. ?
How could a system be designed to allow a choice of operating systems to boot from? What would the bootstrap program need to do?
In: Computer Science
What revolutionized or was paramount in getting us to where we are today in terms of technology (software, hardware and the intenet); and what's most influencial or life chainging?
In: Computer Science
Question 2
The Model View Controller (MVC) and Tier architecture are two of
the most widely used web design architectures currently in
use.
a. Explain both concepts to a team of research who want you to
build a website and publish their work
b. Make a case by thoroughly explaining why one of the
architectures in ‘a’ should be chosen over the other
c. Brief the researchers on the dangers of using the internet and
the necessary steps that you would put in place to curtail such
dangers.
In: Computer Science
In C++ language.
void printTreeIO(Tnode *n)(3): recursive function that prints out the data in the tree in order
In: Computer Science
Question 3
As a website developer, you have been contracted to design a
website for a retail shop. Discuss the necessary steps that you
would take:
a. Before
b. During
c. After
Site development.
In: Computer Science
Write a JavaScript script that has subprograms nested three deep and in which each nested subprogram references variables defined in all of its enclosing subprograms
In: Computer Science
Turing Machine and Closure Operations
Show that Turing-decidable languages are closed under the following operations:
union
concatenation
star
In: Computer Science
Turing Machine and Closure Operations
Show that Turing-recognizable languages are closed under the following operations:
union
concatenation
star
Each answer needs only be a short informal description of a Turing Machine (but it must still be sufficiently precise so someone could reconstruct a formal machine if needed).
Also, be careful with non-termination (when appropriate)!
In: Computer Science