This is java In this homework you are to create your project
This is java
In this homework, you are to create your project. You get to decide what is interesting to you. To complete this assignment, you are first to create an outline that describes what you would like to accomplish. Try to be as specific as you can be. Add as much functionality as you would like. As long as you complete the following requirements below, you will have successfully fulfilled the requirements of this homework.
1. Print out a short description of what your project is
2. Create a UML diagram of your overall project
3. Use of static methods where necessary
4. Read in information from a file
5. Make it graphical with a frame and panel
6. Make sure you use loops, conditionals, logical operators and basic operators
7. Ensure that you have proper class structure
8. Allow users to add new items – depending on your application. If it does not allow for this, please explain why.
9. Use an array to store information
10. Use an ArrayList to store information
11. Keep track of all errors including: a. Syntax b. Run-time c. Logical d. Write down what the error is, and how you correct it. e. Keep your error file in a separate file and add to it over the lifetime of the project
12. Use good code structure, variable naming and commenting
Solution
Let us take an example of selection sort algorithm . Here is the program which takes integer or strings as input and sorts the values. This will include static methods, loops, user inputs and good code structure and naming.
1. Sorting.java
public class Sorting {
//-----------------------------------------------------------------
// Sorts the specified array of objects using the selection
// sort algorithm.
//-----------------------------------------------------------------
public static void selectionSort (Comparable[] list)
{
int min;
Comparable temp;
for (int index = 0; index < list.length-1; index++)
{
min = index;
for (int scan = index+1; scan < list.length; scan++)
if (list[scan].compareTo(list[min]) < 0)
min = scan;
// Swap the values
temp = list[min];
list[min] = list[index];
list[index] = temp;
}
}
}
2. Numbers.java
import java.util.Scanner;
public class Numbers {
//---------------------------------------------
// Reads in an array of integers, sorts them,
// then prints them in sorted order.
//---------------------------------------------
public static void main (String[] args)
{
Sorting sorting = new Sorting();
Comparable[] intList;
int size;
Scanner scan = new Scanner(System.in);
System.out.print (\"\ How many integers do you want to sort? \");
size = scan.nextInt();
intList = new Comparable[size];
System.out.println (\"\ Enter the numbers...\");
for (int i = 0; i < size; i++)
intList[i] = scan.nextInt();
sorting.selectionSort(intList) ;
System.out.println (\"\ Your numbers in sorted order...\");
for (int i = 0; i < size; i++)
System.out.print(intList[i] + \" \");
System.out.println ();
}
}
3.
import java.util.Scanner;
public class Strings {
//---------------------------------------------
// Reads in an array of strings, sorts them,
// then prints them in sorted order.
//---------------------------------------------
public static void main (String[] args)
{
Sorting sorting = new Sorting();
Comparable[] stringList;
int size;
Scanner scan = new Scanner(System.in);
System.out.print (\"\ How many strings do you want to sort? \");
size = scan.nextInt();
stringList = new Comparable[size];
System.out.println (\"\ Enter the strings...\");
for (int i = 0; i < size; i++)
stringList[i] = scan.next();
sorting.selectionSort(stringList) ;
System.out.println (\"\ Your numbers in sorted order...\");
for (int i = 0; i < size; i++)
System.out.print(stringList[i] + \" \");
System.out.println ();
}
}


