the run does not like what i want and all the statment correct ??
what the quastion want :
(i) Task1: Complete the code, so your program will support insert, delete, and search. After you finish, make another copy of this program using unordered array to insert a new record at the end, sequential search.
(ii) Task2: Implement a function called payRangeQuery that takes two double parameters low and high and print all records of employees whose pay is between low and high. The payRangeQuery function should be implemented as a public method in the RecordDB class.
(iii) Task3: Write a search function that is similar to the currently implemented search function, except that the new search function returns an integer. If the given SSN is found, then the function returns a non-negative integer that is the index of the slot in which the SSN was found. If the given SSN is not found, then the function should return a negative integer, whose magnitude (absolute value) is the index of the slot in which the SSN would have been found, had it been in the array. For example, if the social security numbers in the array are: 10, 20, 30, 40 and we were looking for 22, and then the function should return -2 because if 22 were present in the array it would be in slot 2.
(iv) Task4: Re-implement the “insert” and “delete” functions so that they call the new search function. You would have noticed that both insert and delete currently perform a linear scan of the array; insert does it in order to find a slot to insert the new record in and delete does it in order to find the record with the given SSN. Having implemented the new search function, it is possible to simplify and speed-up both insert and delete by making appropriate calls to the new “search” function.
This is class RecordDB >>>>>>>>>
PHP Code:
/*
import java.util.*;
public class RecordDB {
private static int maxRecords = 200;
private int numRecords = 0;
private Record recordList[] = new Record[maxRecords];
//--------------------------------------------------------------------------------
//Inserts a record into the ordered array in a sorted fashion.
//Parameter rec: The record to be inserted.
public void insert (Record rec) {
// Check for overflow; if overflow, then don't insert
if (numRecords == maxRecords-1){
return; }
else{
int o;
for(o=0;o<numRecords;o++){
if(recordList[o].SSN>rec.SSN){
break;
}
//Find the position to insert in, by scanning the array left-to-right
// until a large SSN is located
// Then, Shift all records one space down
for(int j=numRecords-1;j>=o;j--){
recordList[j+1]=recordList[j]; //shifting
}
// Then, Insert the new record
recordList[o]=rec;
numRecords++; // Finally, Increment current number of employees in the list
} //end for first
} //end else
// Print All records
printAll();
int v= search0(rec.SSN);// task 4
for(int i=0;i<numRecords;i++){
if (i==v){
int p;
for( p=numRecords;p==i;p--){
recordList[p]=recordList[p+1];}
recordList[p]=rec[i];
}
else {
int positive= v*-1;
if (i==positive){
int p;
for( p=numRecords;p==i;p--){
recordList[p]=recordList[p+1];}
recordList[p]=rec[i];
}
}
}
}// end insert
//--------------------------------------------------------------------------------- //Deletes a record from the list based on the key (SSN).
// Performs a linear scan of the array of records until
//a record is found with the given SSN
//Parameter SSN
public void delete (int newSSN) {
//Check for underflow; if underflow, then don't delete
if (numRecords==0){
return;
}
// Scan the array searching for the record containing newSSN
int c;
for(c=0;c<numRecords;c++){
if(recordList[c].SSN == newSSN){
break;
}
}
for(int j=numRecords-1;j>=c;j--){
recordList[c]=recordList[c+1]; // Then, Shift all records that are beyond slot i to the left by one slot
}
numRecords--; // Finally, Decrement current number of employees in the list
// Print All records
printAll();
int v= search0(newSSN);// task 4
for(int i=0;i<numRecords;i++){
if (i==v){
for(int u=i;u<numRecords;u--){
recordList[u]=recordList[u+1];}
}
else {
int positive= v*-1;
if (i==positive){
for(int u=i;u<numRecords;u--){
recordList[u]=recordList[u+1];}
}
else return;
}
}
}
//--------------------------------------------------------------------------------
//Search for the record with the given SSN, Parameter newSSN
public Record search (int newSSN) {
// Print All records
printAll();
// Complete this Binary Search algorithm
int first=0, last=numRecords-1, mid=0;
boolean sure =false;
while (!sure && first<=last){
mid=(first+last)/2;
if(recordList[mid].SSN== newSSN ){
sure=true;
}
else{
if( newSSN < recordList[mid].SSN){
last=mid-1;
}
else first=mid+1;
}
}
if(sure)
return recordList[mid];
else
return null;
} // end of search function
//------------------TASK 2-------------------------------------------------------------
public void payRangeQuery(double low,double high){
for(int r=0; low < recordList[r].pay && recordList[r].pay< high ;r++){
System.out.println(""+r+" "+recordList[r].SSN+
" "+recordList[r].name+" " +recordList[r].pay);
}
}
//-------------------------------------------------------------------------------
public int search0 (int newSSN) {
// Print All records
printAll();
// Complete this Binary Search algorithm
int first=0, last=numRecords-1, mid=0;
boolean sure =false;
while (!sure && first<=last){
mid=(first+last)/2;
if(recordList[mid].SSN== newSSN ){
sure=true;
}
else{
if( newSSN < recordList[mid].SSN){
last=mid-1;
}
else first=mid+1;
}
}
if(sure)
return mid;
else{
int q;
for( q=0; q<numRecords;q++){
if(recordList[q].SSN > recordList[q+1].SSN ){
break;
}
}
return -q;
}// end else
} // ehd search function in task 3;
//-------------------------------------------------------------------------------
//Prints the list of records to the standard output;
private void printAll() {
System.out.println("---------------------------------");
System.out.println("i SSN Name pay");
for (int i=0; i<numRecords; i++) {
System.out.println(""+i+" "+recordList[i].SSN+
" "+recordList[i].name+" " +recordList[i].pay);
}
}
}
-----------------------------------------------------------------
This is class Record
PHP Code:
public class Record {
// data members
public int SSN; // Primary Key
public String name;
public double pay;
// The constructor for this class
Record (int newSSN, String newName, double newPay) {
SSN = newSSN;
name = newName;
pay = newPay;
} // end of constructor
public int getSSN(){
return SSN;
}
public String getName(){
return name;
}
public double getPay(){
return pay;
}
int compareTo(Record record) {
throw new UnsupportedOperationException("Not yet implemented");
}
}
-----------------------------------------------------------------------------
The main
PHP Code:
public class company {
public static void main(String[] args) {
RecordDB recDB = new RecordDB();
recDB.insert(new Record(3, "John", 500));
recDB.insert(new Record(22, "Mike", 2500));
recDB.insert(new Record(13, "Mark", 1760));
recDB.insert(new Record(19, "Bob", 500));
recDB.insert(new Record(7, "Cathy", 500));
Record r = recDB.search(22);
if(r == null)
System.out.println("Not found");
else
System.out.println("Found");
r = recDB.search(34);
if(r == null)
System.out.println("Not found");
else
System.out.println("Found");
recDB.delete(19);
recDB.delete(7);
recDB.delete(3);
recDB.delete(13);
recDB.delete(21);
recDB.delete(22);
recDB.delete(3);
}
}