Hello, I need help with my object-orientated programming assignment in Java. Any comments in the code would be appreciat

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Hello, I need help with my object-orientated programming assignment in Java. Any comments in the code would be appreciat

Post by answerhappygod »

Hello, I need help with my object-orientated programming
assignment in Java. Any comments in the code would be appreciated.
Thank you!
Create a file IntegerList.java which contains a class
representing a list of integers. The following public methods
should be included in the class
- IntegerList(int size)—creates a new list of size elements.
Elements are initialized to 0.
-void randomize()—fills the list with random integers between
1 and 100, inclusive.
-void print()—prints the array elements and indices
- int search(int target)—looks for value target in the list using a
linear (also called sequential) search algorithm. Returns the index
where it first appears if it is found, -1
otherwise.
-void selectionSort()—sorts the lists into descending order
using the selection sort algorithm
File IntegerListTest.java contains a Java program that provides
menu-driven testing for the IntegerList class. Copy the file to
your directory, and compile and run IntegerListTest to see how it
works. For example, create a list, print it, and search for an
element in the list. Does it return the correct index? Now look for
an element that is not in the list. Now sort the list and print it
to verify that it is in sorted order.
your output should be similar to this:
Menu
====
0: Quit
1: Create a new list (** do this first!! **)
2: Sort the list using selection sort
3: Find an element in the list using sequential search
4: Print the list
5: Sort the list in decreasing order
Enter your choice:
//
****************************************************************

// IntegerListTest.java
//
// Provide a menu-driven tester for the IntegerList class.
//
//
****************************************************************
import java.util.Scanner;
public class IntegerListTest
{
static IntegerList list = new IntegerList(10);
static Scanner scan = new Scanner (System.in);
//---------------------------------------------------------------

// Create a list, then repeatedly print the menu and
do what the
// user asks until they quit

//---------------------------------------------------------------

public static void main(String[] args)
{
printMenu();
int choice = scan.nextInt();
while (choice != 0)
{
dispatch(choice);
printMenu();
choice =
scan.nextInt();
}
}
//-------------------------------------------------------
// Do what the menu item calls for

//-------------------------------------------------------
public static void dispatch(int choice)
{
int loc;
switch(choice)
{
case 0:

System.out.println("Bye!");
break;
case 1:
System.out.println("How big
should the list be?");
int size =
scan.nextInt();
list = new
IntegerList(size);
list.randomize();
break;
case 2:
list.selectionSort();
break;
case 3:
System.out.print("Enter the
value to look for: ");
loc =
list.search(scan.nextInt());
if (loc != -1)

System.out.println("Found at location " + loc);
else

System.out.println("Not in list");
break;
case 4:
list.print();
break;
case 5:
list.sortDecreasing();
break;
default:
System.out.println("Sorry,
invalid choice");
}
}
//-------------------------------------------------------
// Print the user's choices

//-------------------------------------------------------
public static void printMenu()
{
System.out.println("\n Menu
");
System.out.println(" ====");
System.out.println("0: Quit");
System.out.println("1: Create a new list (** do
this first!! **)");
System.out.println("2: Sort the list using
selection sort");
System.out.println("3: Find an element in the
list using sequential search");
System.out.println("4: Print the list");
System.out.println("5: Sort the list in
decreasing order");
System.out.print("\nEnter your choice: ");
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply