0

Here is the link to my homework assignment.

http://courses.cs.purdue.edu/cs18000:fall13:hw13

I would prefer an explanation as opposed to the code that would actually answer the question so I can learn. The code I have right now is this.

public class Sorter {

    double[] x = { 42.0, 3.5, Math.PI, 12.2, -47 };

    double[] y = { 0, 0, 0, 0, 0};

    public void copyOf() {

        for (int i = 0; i < x.length; i++)

            x[i] = y[i];

    }

    public void sort() {

        for (int a = y.length; a >= 0; a -= 1) {

            if (y[a] < y[0]) {

                int b = 0;

                y[0] = b;

                y[a] = y[0];

                y[a] = b;

            }

            if (y[a] < y[1]) {

                int b = 0;

                y[1] = b;

                y[a] = y[1];

                y[a] = b;
            }

            if (y[a] < y[2]) {

                int b = 0;

                y[2] = b;

                y[a] = y[2];

                y[a] = b;

            }

            if (y[a] < y[3]) {

                int b = 0;

                y[3] = b;

                y[a] = y[3];

                y[a] = b;

            }

            if (y[a] < y[4]) {

                int b = 0;

                y[4] = b;

                y[a] = y[4];

                y[a] = b;

            }

        }

    }

}
PM 77-1
  • 12,933
  • 21
  • 68
  • 111
  • 2
    why do you have so many line breaks – tckmn Sep 23 '13 at 02:15
  • What kind of explanation are you looking for? – PM 77-1 Sep 23 '13 at 02:17
  • Have you learned `nested loops` yet? – PM 77-1 Sep 23 '13 at 02:17
  • I have not learned nested loops yet and I am having a hard time understanding what exactly I am supposed to do with static double[] sortArray(double[] input) Also, I am not sure if I declared my methods correctly. – user2805545 Sep 23 '13 at 02:31
  • @user2805545 You are making it far harder than it needs to be by not reading the assignment and doing what it says. Specifically, re-read your class notes on java.util.Arrays before going any further with implementation. – Patricia Shanahan Sep 23 '13 at 04:19

1 Answers1

3

The next step is to read the assignment. Then read it again. Then do what it says.

It tells you to create a method with a specific name etc. Do so.

It also tells you to "Use the java.util.Arrays class as described in the course notes. You'll need methods copyOf, sort, and (for testing) toString (see below).". Read about Arrays in your class notes, and optionally also in the API documentation. Then think about how to use it to complete the assignment.

============================================================

Looking at your code, it may be that you are, wrongly, interpreting "You'll need methods ..." as though it said "You should write methods ...". It is calling your attention to methods in java.util.Arrays.

Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75
  • 1
    I agree completely. I would even go so far as to say delete everything you have and go back to line 1 of your assignment. Take it line by line: 1. Write a class called `Sorter` 2. Write a method `static double[] sortArray(double[] input)` that... – Rossiar Sep 23 '13 at 08:59