SlideShare a Scribd company logo
1 of 7
Download to read offline
**Complete skeleton**
import java.util.ArrayList;
public class MyGenerics{
//Declarations
//****************************************************************************
//No-argument constructor:
//****************************************************************************
public MyGenerics (){
}//end of constructor
//****************************************************************************
//max: Receives a generic one-dimensional array and returns the maximum
// value in the array.
//****************************************************************************
public > E max(E[] list){
return null;
}//end of max
//****************************************************************************
//max: Receives a generic two-dimensional array and returns the maximum
// value in the array.
//****************************************************************************
public > E max(E[][] list) {
return null;
}
//****************************************************************************
//largest: Receives a generic arrayList and returns the maximum
// value in the array.
//****************************************************************************
public > E largest(ArrayList list) {
return null;
}
//****************************************************************************
//binarySearch: Receives a generic one-dimensional array and a generic key
// and returns the location of the key (positive) or
// a negative location if not found.
//****************************************************************************
public > int binarySearch(E[] list, E key) {
int low = 0;
int high = list.length - 1;
return binarySearch (list, key, low, high);
}
public > int binarySearch(E[] list, E key, int low, int high) {
return -99; // update
}
//****************************************************************************
//sort: Receives a generic arrayList and returns nothing.
//****************************************************************************
public > void sort(ArrayList list) {
}
//****************************************************************************
//sort: Receives a generic one-dimensional array and returns nothing.
//****************************************************************************
public > void sort(E[] list) {
}
//****************************************************************************
//displayOneDList: Receives a generic one-dimensional array and displays its contents
//****************************************************************************
public void displayOneDList(E[] list, String listName){
}
//****************************************************************************
//displayTwoDList: Receives a generic two-dimensional array & a string name
// and displays its contents
//****************************************************************************
public void displayTwoDList(E[][] list, String listName){
}
//****************************************************************************
//displayArrayList: Receives a generic arraylist & a string name
// and displays its contents
//****************************************************************************
public void displayArrayList(ArrayList list, String listName){
}
}//end of class
-------------------------end of skeleton--------------
1. Use recursion in implementing the binarySearch method
2. Use Generics in implementing different methods
3. Use the attached driver. Do not modify the driver and do not submit the driver
4. Make sure that your program is well documented, readable, and the output is well labeled and
aligned
Sample output:
List Name: Integer One D Array
4 7 2 20 30 22
List Name: Double One D Array
4.0 7.5 2.3 20.7 30.1 22.8
List Name: String One D Array
Tony Paige Denzel Travis Austin Thomas Demetrius
List Name: Character One D Array
W D A C I F B
List Name: Integer Two D Array
1 1 60 5
2 20 40 5
3 100 300 15 27
List Name: string Two D Array
1 Quitman Valdosta Atlanta Macon
2 Gainesville Tallahassee Jacksonville
List Name: A String arraylist
Tony Paige Denzel
Largest value is one-d integer list is: 30
Largest value is one-d double list is: 30.1
Largest value is one-d string list is: Travis
Largest value is one-d character list is: W
Largest value is two-d integer list is: 300
Largest value is two-d string list is: Valdosta
Largest value is an arrayList is: Tony
List Name: Integer One D Array
2 4 7 20 22 30
List Name: Double One D Array
2.3 4.0 7.5 20.7 22.8 30.1
List Name: String One D Array
Austin Demetrius Denzel Paige Travis Thomas Tony
List Name: Character One D Array
A B C D F I W
List Name: A String arraylist
Damieona Denzel Paige Tony
The location of value 20 in intList is: 3
The location of value 77 in intList is: -7
The location of value 'C' in charList is: 2
The location of value "Austin" in stringList is: 0
-------------------------------Tester Code--------------------------------------------
import java.util.*;
public class MyGenerics_Tester{
//Declrations
public static void main (String [] args){
//Declarations
Integer [] intList = {4, 7, 2, 20, 30, 22};
Double [] doubleList = {4.0, 7.5, 2.3, 20.7, 30.1, 22.8};
String [] stringList = {"Tony","Paige","Denzel","Travis","Austin","Thomas",
"Demetrius"};
Character[] charList = {'W','D','A','C','I','F','B'};
Integer [][] intTwoDList = {{1, 60, 5},
{20, 40, 5},
{100, 300, 15, 27}};
String [][] stringTwoDList = {{"Quitman", "Valdosta","Atlanta", "Macon"},
{"Gainesville","Tallahassee","Jacksonville"}};
ArrayList aList = new ArrayList<>();
aList.add("Tony");
aList.add("Paige");
aList.add("Denzel");
//Create an object
MyGenerics object = new MyGenerics();
//Display different lists
object.displayOneDList(intList,"Integer One D Array");
object.displayOneDList(doubleList,"Double One D Array");
object.displayOneDList(stringList,"String One D Array");
object.displayOneDList(charList,"Character One D Array");
object.displayTwoDList(intTwoDList,"Integer Two D Array");
object.displayTwoDList(stringTwoDList,"string Two D Array");
object.displayArrayList(aList,"A String arraylist");
//display largest in list
System.out.println ("tLargest value is one-d integer list is: t" + object.max(intList));
System.out.println ("tLargest value is one-d double list is: t" + object.max(doubleList));
System.out.println ("tLargest value is one-d string list is: t" + object.max(stringList));
System.out.println ("tLargest value is one-d character list is: t" + object.max(charList));
System.out.println ("tLargest value is two-d integer list is: t" + object.max(intTwoDList));
System.out.println ("tLargest value is two-d string list is: t" + object.max(stringTwoDList));
System.out.println ("tLargest value is an arrayList is: t" + object.largest(aList));
//Sorting
object.sort(intList);
object.sort(doubleList);
object.sort(stringList);
object.sort(charList);
object.sort(aList);
//Dispaly sorted lists
object.displayOneDList(intList,"Integer One D Array");
object.displayOneDList(doubleList,"Double One D Array");
object.displayOneDList(stringList,"String One D Array");
object.displayOneDList(charList,"Character One D Array");
object.displayArrayList(aList,"A String arraylist");
//BinarySearch
System.out.println ("tThe location of value 20 in intList is: t" +
object.binarySearch(intList,20));
System.out.println ("tThe location of value 77 in intList is: t" +
object.binarySearch(intList,77));
System.out.println ("tThe location of value 'C' in charList is: t" +
object.binarySearch(charList,'C'));
System.out.println ("tThe location of value "Austin" in stringList is: t" +
object.binarySearch(stringList,"Austin"));
}
}
Solution
#include
#include
#define size 10
int binsearch(int[], int, int, int);
int main() {
int num, i, key, position;
int low, high, list[size];
printf(" Enter the total number of elements");
scanf("%d", &num);
printf(" Enter the elements of list :");
for (i = 0; i < num; i++) {
scanf("%d", &list[i]);
}
low = 0;
high = num - 1;
printf(" Enter element to be searched : ");
scanf("%d", &key);
position = binsearch(list, key, low, high);
if (position != -1) {
printf(" Number present at %d", (position + 1));
} else
printf(" The number is not present in the list");
return (0);
}
// Binary Search function
int binsearch(int a[], int x, int low, int high) {
int mid;
if (low > high)
return -1;
mid = (low + high) / 2;
if (x == a[mid]) {
return (mid);
} else if (x < a[mid]) {
binsearch(a, x, low, mid - 1);
} else {
binsearch(a, x, mid + 1, high);
}
}

More Related Content

Similar to Complete skeletonimport java.util.ArrayList; public class My.pdf

In Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdfIn Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdf
Stewart29UReesa
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
stopgolook
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
malavshah9013
 
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docxlab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
DIPESH30
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
aksahnan
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
 
For this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdfFor this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdf
alokindustries1
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
adityaenterprise32
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
arpitcomputronics
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
curwenmichaela
 
Write a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdfWrite a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdf
hardjasonoco14599
 

Similar to Complete skeletonimport java.util.ArrayList; public class My.pdf (20)

Array operators
Array operatorsArray operators
Array operators
 
In Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdfIn Java- Create a Graduate class derived from Student- A graduate has.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdf
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
 
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docxlab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)Generic Types in Java (for ArtClub @ArtBrains Software)
Generic Types in Java (for ArtClub @ArtBrains Software)
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
For this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdfFor this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Modify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdfModify this code to change the underlying data structure to .pdf
Modify this code to change the underlying data structure to .pdf
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Write a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdfWrite a function which return a list of all of the n element subset .pdf
Write a function which return a list of all of the n element subset .pdf
 
Chapter03
Chapter03Chapter03
Chapter03
 

More from arhamnighty

Besides using the certificates, suggest alternate method to avoid th.pdf
Besides using the certificates, suggest alternate method to avoid th.pdfBesides using the certificates, suggest alternate method to avoid th.pdf
Besides using the certificates, suggest alternate method to avoid th.pdf
arhamnighty
 
Which of the following receptors is most likely to exhibit tonic adap.pdf
Which of the following receptors is most likely to exhibit tonic adap.pdfWhich of the following receptors is most likely to exhibit tonic adap.pdf
Which of the following receptors is most likely to exhibit tonic adap.pdf
arhamnighty
 
Using the phylogenetic tree shown, state the basal taxon Using the p.pdf
Using the phylogenetic tree shown, state the basal taxon  Using the p.pdfUsing the phylogenetic tree shown, state the basal taxon  Using the p.pdf
Using the phylogenetic tree shown, state the basal taxon Using the p.pdf
arhamnighty
 
Based on the data provided through the U.S. Department of the Treasu.pdf
Based on the data provided through the U.S. Department of the Treasu.pdfBased on the data provided through the U.S. Department of the Treasu.pdf
Based on the data provided through the U.S. Department of the Treasu.pdf
arhamnighty
 
Trace the major historical developments of hospitals in the United S.pdf
Trace the major historical developments of hospitals in the United S.pdfTrace the major historical developments of hospitals in the United S.pdf
Trace the major historical developments of hospitals in the United S.pdf
arhamnighty
 

More from arhamnighty (20)

Besides using the certificates, suggest alternate method to avoid th.pdf
Besides using the certificates, suggest alternate method to avoid th.pdfBesides using the certificates, suggest alternate method to avoid th.pdf
Besides using the certificates, suggest alternate method to avoid th.pdf
 
X mun( oomiB9@@e SolutionAnswerThe image represents the.pdf
X mun( oomiB9@@e SolutionAnswerThe image represents the.pdfX mun( oomiB9@@e SolutionAnswerThe image represents the.pdf
X mun( oomiB9@@e SolutionAnswerThe image represents the.pdf
 
Which of these is not a way for a cell to obtain nutrients and other.pdf
Which of these is not a way for a cell to obtain nutrients and other.pdfWhich of these is not a way for a cell to obtain nutrients and other.pdf
Which of these is not a way for a cell to obtain nutrients and other.pdf
 
Which of the following receptors is most likely to exhibit tonic adap.pdf
Which of the following receptors is most likely to exhibit tonic adap.pdfWhich of the following receptors is most likely to exhibit tonic adap.pdf
Which of the following receptors is most likely to exhibit tonic adap.pdf
 
Which of the following is not a contribution of Robert Koch and his .pdf
Which of the following is not a contribution of Robert Koch and his .pdfWhich of the following is not a contribution of Robert Koch and his .pdf
Which of the following is not a contribution of Robert Koch and his .pdf
 
When RNA from a specific strain of TMV is mixed with coat protein fro.pdf
When RNA from a specific strain of TMV is mixed with coat protein fro.pdfWhen RNA from a specific strain of TMV is mixed with coat protein fro.pdf
When RNA from a specific strain of TMV is mixed with coat protein fro.pdf
 
What are the sources of Ductility for structures What is more du.pdf
What are the sources of Ductility for structures What is more du.pdfWhat are the sources of Ductility for structures What is more du.pdf
What are the sources of Ductility for structures What is more du.pdf
 
What are some examples of self love in Pride and PrejudiceSolut.pdf
What are some examples of self love in Pride and PrejudiceSolut.pdfWhat are some examples of self love in Pride and PrejudiceSolut.pdf
What are some examples of self love in Pride and PrejudiceSolut.pdf
 
Using the phylogenetic tree shown, state the basal taxon Using the p.pdf
Using the phylogenetic tree shown, state the basal taxon  Using the p.pdfUsing the phylogenetic tree shown, state the basal taxon  Using the p.pdf
Using the phylogenetic tree shown, state the basal taxon Using the p.pdf
 
Use attached Table A-2 for Normal Distribution to find the critical .pdf
Use attached Table A-2 for Normal Distribution to find the critical .pdfUse attached Table A-2 for Normal Distribution to find the critical .pdf
Use attached Table A-2 for Normal Distribution to find the critical .pdf
 
Based on the data provided through the U.S. Department of the Treasu.pdf
Based on the data provided through the U.S. Department of the Treasu.pdfBased on the data provided through the U.S. Department of the Treasu.pdf
Based on the data provided through the U.S. Department of the Treasu.pdf
 
Trace the major historical developments of hospitals in the United S.pdf
Trace the major historical developments of hospitals in the United S.pdfTrace the major historical developments of hospitals in the United S.pdf
Trace the major historical developments of hospitals in the United S.pdf
 
The role of Ca2+ in the control of muscle contraction is to1. caus.pdf
The role of Ca2+ in the control of muscle contraction is to1. caus.pdfThe role of Ca2+ in the control of muscle contraction is to1. caus.pdf
The role of Ca2+ in the control of muscle contraction is to1. caus.pdf
 
The following data. recorded in days, represent the length of time to.pdf
The following data. recorded in days, represent the length of time to.pdfThe following data. recorded in days, represent the length of time to.pdf
The following data. recorded in days, represent the length of time to.pdf
 
Suppose that A and B are in DSPACE(n). Prove that the following lang.pdf
Suppose that A and B are in DSPACE(n). Prove that the following lang.pdfSuppose that A and B are in DSPACE(n). Prove that the following lang.pdf
Suppose that A and B are in DSPACE(n). Prove that the following lang.pdf
 
Some new protocols such as Internet Protocol (IP) version 6 are not .pdf
Some new protocols such as Internet Protocol (IP) version 6 are not .pdfSome new protocols such as Internet Protocol (IP) version 6 are not .pdf
Some new protocols such as Internet Protocol (IP) version 6 are not .pdf
 
Selection of favorite fruits and responses of orange, grape, apple, .pdf
Selection of favorite fruits and responses of orange, grape, apple, .pdfSelection of favorite fruits and responses of orange, grape, apple, .pdf
Selection of favorite fruits and responses of orange, grape, apple, .pdf
 
RNA and DNA differRNA and DNA differE-All of these are correct..pdf
RNA and DNA differRNA and DNA differE-All of these are correct..pdfRNA and DNA differRNA and DNA differE-All of these are correct..pdf
RNA and DNA differRNA and DNA differE-All of these are correct..pdf
 
Propose a pathway(s) to explain how the ectoderm and the notochord b.pdf
Propose a pathway(s) to explain how the ectoderm and the notochord b.pdfPropose a pathway(s) to explain how the ectoderm and the notochord b.pdf
Propose a pathway(s) to explain how the ectoderm and the notochord b.pdf
 
Potassium has one electron in its outer shell. Which of the followin.pdf
Potassium has one electron in its outer shell. Which of the followin.pdfPotassium has one electron in its outer shell. Which of the followin.pdf
Potassium has one electron in its outer shell. Which of the followin.pdf
 

Recently uploaded

Recently uploaded (20)

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
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
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.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
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
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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)
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.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...
 
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 Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

Complete skeletonimport java.util.ArrayList; public class My.pdf

  • 1. **Complete skeleton** import java.util.ArrayList; public class MyGenerics{ //Declarations //**************************************************************************** //No-argument constructor: //**************************************************************************** public MyGenerics (){ }//end of constructor //**************************************************************************** //max: Receives a generic one-dimensional array and returns the maximum // value in the array. //**************************************************************************** public > E max(E[] list){ return null; }//end of max //**************************************************************************** //max: Receives a generic two-dimensional array and returns the maximum // value in the array. //**************************************************************************** public > E max(E[][] list) { return null; } //**************************************************************************** //largest: Receives a generic arrayList and returns the maximum // value in the array. //**************************************************************************** public > E largest(ArrayList list) { return null;
  • 2. } //**************************************************************************** //binarySearch: Receives a generic one-dimensional array and a generic key // and returns the location of the key (positive) or // a negative location if not found. //**************************************************************************** public > int binarySearch(E[] list, E key) { int low = 0; int high = list.length - 1; return binarySearch (list, key, low, high); } public > int binarySearch(E[] list, E key, int low, int high) { return -99; // update } //**************************************************************************** //sort: Receives a generic arrayList and returns nothing. //**************************************************************************** public > void sort(ArrayList list) { } //**************************************************************************** //sort: Receives a generic one-dimensional array and returns nothing. //**************************************************************************** public > void sort(E[] list) { } //**************************************************************************** //displayOneDList: Receives a generic one-dimensional array and displays its contents //**************************************************************************** public void displayOneDList(E[] list, String listName){ }
  • 3. //**************************************************************************** //displayTwoDList: Receives a generic two-dimensional array & a string name // and displays its contents //**************************************************************************** public void displayTwoDList(E[][] list, String listName){ } //**************************************************************************** //displayArrayList: Receives a generic arraylist & a string name // and displays its contents //**************************************************************************** public void displayArrayList(ArrayList list, String listName){ } }//end of class -------------------------end of skeleton-------------- 1. Use recursion in implementing the binarySearch method 2. Use Generics in implementing different methods 3. Use the attached driver. Do not modify the driver and do not submit the driver 4. Make sure that your program is well documented, readable, and the output is well labeled and aligned Sample output: List Name: Integer One D Array 4 7 2 20 30 22 List Name: Double One D Array 4.0 7.5 2.3 20.7 30.1 22.8 List Name: String One D Array Tony Paige Denzel Travis Austin Thomas Demetrius List Name: Character One D Array W D A C I F B List Name: Integer Two D Array 1 1 60 5 2 20 40 5
  • 4. 3 100 300 15 27 List Name: string Two D Array 1 Quitman Valdosta Atlanta Macon 2 Gainesville Tallahassee Jacksonville List Name: A String arraylist Tony Paige Denzel Largest value is one-d integer list is: 30 Largest value is one-d double list is: 30.1 Largest value is one-d string list is: Travis Largest value is one-d character list is: W Largest value is two-d integer list is: 300 Largest value is two-d string list is: Valdosta Largest value is an arrayList is: Tony List Name: Integer One D Array 2 4 7 20 22 30 List Name: Double One D Array 2.3 4.0 7.5 20.7 22.8 30.1 List Name: String One D Array Austin Demetrius Denzel Paige Travis Thomas Tony List Name: Character One D Array A B C D F I W List Name: A String arraylist Damieona Denzel Paige Tony The location of value 20 in intList is: 3 The location of value 77 in intList is: -7 The location of value 'C' in charList is: 2 The location of value "Austin" in stringList is: 0 -------------------------------Tester Code-------------------------------------------- import java.util.*; public class MyGenerics_Tester{ //Declrations public static void main (String [] args){ //Declarations Integer [] intList = {4, 7, 2, 20, 30, 22}; Double [] doubleList = {4.0, 7.5, 2.3, 20.7, 30.1, 22.8};
  • 5. String [] stringList = {"Tony","Paige","Denzel","Travis","Austin","Thomas", "Demetrius"}; Character[] charList = {'W','D','A','C','I','F','B'}; Integer [][] intTwoDList = {{1, 60, 5}, {20, 40, 5}, {100, 300, 15, 27}}; String [][] stringTwoDList = {{"Quitman", "Valdosta","Atlanta", "Macon"}, {"Gainesville","Tallahassee","Jacksonville"}}; ArrayList aList = new ArrayList<>(); aList.add("Tony"); aList.add("Paige"); aList.add("Denzel"); //Create an object MyGenerics object = new MyGenerics(); //Display different lists object.displayOneDList(intList,"Integer One D Array"); object.displayOneDList(doubleList,"Double One D Array"); object.displayOneDList(stringList,"String One D Array"); object.displayOneDList(charList,"Character One D Array"); object.displayTwoDList(intTwoDList,"Integer Two D Array"); object.displayTwoDList(stringTwoDList,"string Two D Array"); object.displayArrayList(aList,"A String arraylist"); //display largest in list System.out.println ("tLargest value is one-d integer list is: t" + object.max(intList)); System.out.println ("tLargest value is one-d double list is: t" + object.max(doubleList)); System.out.println ("tLargest value is one-d string list is: t" + object.max(stringList)); System.out.println ("tLargest value is one-d character list is: t" + object.max(charList)); System.out.println ("tLargest value is two-d integer list is: t" + object.max(intTwoDList)); System.out.println ("tLargest value is two-d string list is: t" + object.max(stringTwoDList)); System.out.println ("tLargest value is an arrayList is: t" + object.largest(aList)); //Sorting
  • 6. object.sort(intList); object.sort(doubleList); object.sort(stringList); object.sort(charList); object.sort(aList); //Dispaly sorted lists object.displayOneDList(intList,"Integer One D Array"); object.displayOneDList(doubleList,"Double One D Array"); object.displayOneDList(stringList,"String One D Array"); object.displayOneDList(charList,"Character One D Array"); object.displayArrayList(aList,"A String arraylist"); //BinarySearch System.out.println ("tThe location of value 20 in intList is: t" + object.binarySearch(intList,20)); System.out.println ("tThe location of value 77 in intList is: t" + object.binarySearch(intList,77)); System.out.println ("tThe location of value 'C' in charList is: t" + object.binarySearch(charList,'C')); System.out.println ("tThe location of value "Austin" in stringList is: t" + object.binarySearch(stringList,"Austin")); } } Solution #include #include #define size 10 int binsearch(int[], int, int, int); int main() { int num, i, key, position; int low, high, list[size]; printf(" Enter the total number of elements"); scanf("%d", &num);
  • 7. printf(" Enter the elements of list :"); for (i = 0; i < num; i++) { scanf("%d", &list[i]); } low = 0; high = num - 1; printf(" Enter element to be searched : "); scanf("%d", &key); position = binsearch(list, key, low, high); if (position != -1) { printf(" Number present at %d", (position + 1)); } else printf(" The number is not present in the list"); return (0); } // Binary Search function int binsearch(int a[], int x, int low, int high) { int mid; if (low > high) return -1; mid = (low + high) / 2; if (x == a[mid]) { return (mid); } else if (x < a[mid]) { binsearch(a, x, low, mid - 1); } else { binsearch(a, x, mid + 1, high); } }