forked from aneez9n/Basic-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sortedinsertionpractice.java
150 lines (119 loc) · 4.02 KB
/
Sortedinsertionpractice.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sortedinsertionpractice;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
*
* @author eapple
*/
public class Sortedinsertionpractice
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// TODO code application logic here
Scanner input = new Scanner(System. in);
System.out.println("enter size of your array : ");
int size = input.nextInt();
MyArray objectarray = new MyArray(size);
boolean run = true ;
int operation=0;
while(operation!=7)
{
System.out.println(" \n HELLO AGAIN \n");
System.out.println("press 1 to fill the array with elements ");
System.out.println("press 2 to find an element in the array ");
System.out.println("press 3 to delete an element from the array ");
System.out.println("press 4 to modify the array ");
System.out.println("press 5 to show the array ");
System.out.println("press 6 to insert to the array ");
System.out.println("press 7 to EXIT the Operations ");
try
{
System.out.println("WHAT OPERATION DO YOU WANT TO DO? ");
operation = input.nextInt();
}
catch (InputMismatchException e)
{
input.next(); //remove the leftover garbage
//from the input buffer
System.out.println("Invalid Entry Please enter only from 1 to 6.");
}
if(operation==1)
{
objectarray.FillSortedArray();
}
if(operation==2)
{
if(objectarray.fillindex ==-1)
{
System.out.println(" Array is empty yet ! ");
run = false;
}
else
{
objectarray.FindElement();
}
}
if(operation==3)
{
if(objectarray.fillindex==-1)
{
System.out.println(" Array is empty yet ! ");
run = false;
}
else
{
objectarray.DeleteElement();
}
}
if(operation==4)
{
if(objectarray.fillindex==-1)
{
System.out.println(" Array is empty yet ! ");
run = false;
}
else
{
objectarray.Modify();
}
}
if(operation==5)
{
if(objectarray.fillindex==-1)
{
System.out.println(" Array is empty yet ! ");
run = false;
}
else
{
objectarray.display();
}
}
if(operation==6)
{
if(objectarray.fillindex==-1)
{
System.out.println(" Array is empty yet ! ");
run = false;
}
else
{
objectarray.insert();
}
}
if(operation==7)
{
System.out.println("Thanks for Using Array Application ");
break;
}
}
}
}