Question

Can someone compile this and name the it A4MA5331550.java and compile to make .class file. Will...

Can someone compile this and name the it A4MA5331550.java and compile to make .class file. Will need to name . class file A4MA5331550 also when done put both files in a zipped folder named A4MA5331550 and email the folder to [email protected]

here is the program:

import java.util.Scanner;

/**
* 09/17/2017
* Dakota Mammedaty
* MA5331550
* Bubble sorted
*/
public class MA5331550 {
public static void main(String[] args) throws IOException {
Sort st =new Sort();
st.getData();
System.out.println("=================Sorting Algorithms=================");
System.out.println("1. Bubble Sort");
System.out.println("2. Selection Sort");
System.out.println("3. Insertion Sort");
System.out.println("Enter your choice");
Scanner scan = new Scanner(System.in);
int choice = scan.nextInt();
if(choice == 1)
st.bubble();
else if(choice == 2)
st.select();
else if(choice ==3)
st.insert();
st.print();
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Sort.java

import java.util.Scanner;

public class Sort {

//Declaring variables
int size;
int arr[];

//Zero argumented constructor
public Sort() {}

//This method will display the elements in the array after sorting
public void print() {
System.out.println("Displaying the Numbers :");
for (int i = 0; i < size; i++) {
System.out.print(arr[i] + " ");
}
}

/* This method will sort the elements in the
* array using bubble sort algorithm
*/
public void bubble() {
//This Logic will Sort the Array of elements in Ascending order
int temp;
for (int i = 0; i < arr.length; i++) {
for (int j = 1; j < (arr.length - i); j++) {
if (arr[j - 1] > arr[j]) {
temp = arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = temp;
}
}
}


}

/* This method will sort the elements in the
* array using selection sort algorithm
*/
public void select() {
int small;
for (int i = 0; i < arr.length; i++) {
int m = i;
for (int j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[m])
m = j;
}
small = arr[m];
arr[m] = arr[i];
arr[i] = small;
}


}

/* This method will sort the elements in the
* array using insert sort algorithm
*/
public void insert() {
for (int m = 1; m < arr.length; m++) {
int val = arr[m];
int n = m - 1;
while ((n > -1) && (arr[n] > val)) {
arr[n + 1] = arr[n];
n--;
}
arr[n + 1] = val;
}


}

public void getData() {

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
System.out.print("How many no of Elements you want to enter :");
size = sc.nextInt();

arr = new int[size];

for (int i = 0; i < size; i++) {

System.out.print("Enter number#" + (i + 1) + ":");
arr[i] = sc.nextInt();
}

}

}

______________________

MA5331550.java

import java.io.IOException;
import java.util.Scanner;

/**
* 09/17/2017 Dakota Mammedaty MA5331550 Bubble sorted
*/
public class MA5331550 {
public static void main(String[] args) throws IOException {

//Creating the Sort class Objects
Sort st = new Sort();

//Calling the method which will get the inputs from the user
st.getData();

//Displaying the menu
System.out.println("=================Sorting Algorithms=================");
System.out.println("1. Bubble Sort");
System.out.println("2. Selection Sort");
System.out.println("3. Insertion Sort");
System.out.println("Enter your choice");

//getting the choice entered by the user
Scanner scan = new Scanner(System.in);
int choice = scan.nextInt();

//Based on the user choice the corresponding block of code will executed
if (choice == 1)
//calling the method on the Sort class
st.bubble();
else if (choice == 2)
//calling the method on the Sort class
st.select();
else if (choice == 3)
//calling the method on the Sort class
st.insert();

/* calling the method on the Sort class
* to display the numbers after sorting
*/
st.print();
}
}

________________________

Output:

How many no of Elements you want to enter :10
Enter number#1:34
Enter number#2:56
Enter number#3:11
Enter number#4:9
Enter number#5:8
Enter number#6:3
Enter number#7:59
Enter number#8:90
Enter number#9:81
Enter number#10:17
=================Sorting Algorithms=================
1. Bubble Sort
2. Selection Sort
3. Insertion Sort
Enter your choice
1
Displaying the Numbers :
3 8 9 11 17 34 56 59 81 90

_____________Could you rate me well.Plz .Thank You

Add a comment
Know the answer?
Add Answer to:
Can someone compile this and name the it A4MA5331550.java and compile to make .class file. Will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • the code needs to be modifed. require a output for the code Java Program to Implement...

    the code needs to be modifed. require a output for the code Java Program to Implement Insertion Sort import java.util.Scanner; /Class InsertionSort * public class Insertion Sort { /Insertion Sort function */ public static void sort( int arr) int N- arr.length; int i, j, temp; for (i-1; i< N; i++) j-i temp arrli; while (j> 0 && temp < arrli-1) arrli]-arrli-1]; j-j-1; } arrlj] temp; /Main method * public static void main(String [] args) { Scanner scan new Scanner( System.in...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements...

    The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements both the selection sort and the insertion sort algorithms for sorting any array of Comparable objects in ascending order. In this exercise, you will use the Sorting class to sort several different types of objects. 1. The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to...

  • 1. Import file ReadingData.zip into NetBeans. Also, please download the input.txt file and store it into...

    1. Import file ReadingData.zip into NetBeans. Also, please download the input.txt file and store it into an appropriate folder in your drive. a) Go through the codes then run the file and write the output with screenshot (please make sure that you change the location of the file) (20 points) b) Write additional Java code that will show the average of all numbers in input.txt file (10 points) import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.io.*; 1- * @author mdkabir...

  • Complete the following Java program by writing the missing methods. public class 02 { public static...

    Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()

  • import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y,...

    import java.util.Scanner; public class SCAN { public static void main(String[ ] args) { int x, y, z; double average; Scanner scan = new Scanner(System.in); System.out.println("Enter an integer value"); x = scan.nextInt( ); System.out.println("Enter another integer value"); y = scan.nextInt( ); System.out.println("Enter a third integer value"); z = scan.nextInt( ); average = (x + y + z) / 3; System.out.println("The result of my calculation is " + average); } } What is output if x = 0, y = 1 and...

  • Help check why the exception exist do some change but be sure to use the printwriter...

    Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...

  • Modify the program that you wrote for the last exercise in a file named Baseball9.java that...

    Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...

  • use the same code. but the code needs some modifications. so use this same code and...

    use the same code. but the code needs some modifications. so use this same code and modify it and provide a output Java Program to Implement Merge Sort import java.util.Scanner Class MergeSort public class MergeSort Merge Sort function / public static yoid sortfintfl a, int low, int high) int N-high-low; if (N1) return; int mid- low +N/2; Il recursively sort sort(a, low, mid); sort(a, mid, high); I/ merge two sorted subarrays int] temp new int[N]; int i- low, j-mid; for...

  • How can I make this program sort strings that are in a text file and not...

    How can I make this program sort strings that are in a text file and not have the user type them in? I need this done by 5:00 AM EST tommorow please. import java.util.*; public class MergeDemo { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.print("How many lines to be sorted:"); int size=input.nextInt(); String[] lines=new String[size]; lines[0]=input.nextLine(); System.out.println("please enter lines..."); for(int i=0;i { lines[i]=input.nextLine(); } System.out.println(); System.out.println("Lines Before Sorting:"); System.out.println(Arrays.toString(lines)); mergeSort(lines); System.out.println(); System.out.println("Lines after Sorting:"); System.out.println(Arrays.toString(lines)); } public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT