$25
What is this Lab about ?
This program is for practicing Array Insertion, Deletion and Swapping. You will need to implement a class Lab9 and a simple program to insert, delete and swap values from an integer array.
Getting Started
1. Create a class called Lab9. Use the same setup for setting up your class and main method as you did for the previous assignments. Be sure to name your file Lab9.java.
2. Remove the comments and insert correct expression according to the instructions.
When declaring a variable, you usually want to initialize it.
Use whitespace to make your program more readable.
Use comments after ending brace of classes, methods, and blocks to identify to which block it belongs.
Use Proper Indentation, 4 spaces or tabs.
Now lets begin with the assignment. You will find the instruction in line.
// import all and anything you need
//-->
public class Lab9
{
//Declare the main method
//-->
{
Scanner in = new Scanner(System.in);
Print "Create an Array of 10 Integers."
// --> Create an array of size 10 int[] ints = ??
Print "Insert 8 integers into the Array."
for (??; ?? ; ??) { ints[??] = ??
}
//Display The Array Values Print "Values in array are: " for (int i =0; i < ? What Size ? ; ??) {
??
}
//Insert another integer at a new location Print "Enter which location you want to insert:" int loc = ??
Print "Enter which value you want to insert:" int value = ??
//Change the values in the array such that it
//Moves the values to a new location creating space for
//the new element.
for (int i = ??; ?? ; ??){
??
}
//Insert the value in the new location ints[loc-1]=value;
//Display The Array Values Print "Values in array are: " for (int i =0; i < ? What Size ? ; ??) {
??
}
//Delete an integer at a given location Print "Enter which location you want to delete:" loc = ??
//Change the values in the array such that it
//Moves the values to a new location deleting the
//value at the given location for (int i = ??; ?? ; ??){
??
}
//Display The Array Values Print "Values in array are: " for (int i =0; i < ? What Size ? ; ??) {
??
}
//Swap values from 2 locations Print "Enter first swap location:" int first = ??
Print "Enter second swap location:" int second = ??
//Swap values at location first and second
//Do note actual array location are 1 less
//Swap can be done in 3 steps
//Step 1
//Step 2
//Step 3
//Display The Array Values
Print "Values in array are: " for (int i =0; i < ? What Size ? ; ??) {
??
}
} }
Thats it for the file called Lab9.java.
Do look at the Sample Output below to know how your program execution should look like.
Sample Output
Create an Array of 10 Integers.
Insert 8 integers into the Array.
1
2
3
4
5
6
7
8
Values in array are: 1,2,3,4,5,6,7,8, Enter which location you want to insert:
2
Enter which value you want to insert:
100
Values in array are: 1,100,2,3,4,5,6,7,8, Enter which location you want to delete: 6
Values in array are: 1,100,2,3,4,6,7,8, Enter first swap location:
2
Enter second swap location:7
Values in array are: 1,7,2,3,4,5,100,8,