Integer Sorter
Author |
Message |
SapphireBlue
|
Posted: Tue Apr 12, 2011 1:53 pm Post subject: Integer Sorter |
|
|
Hello.
I am doing an assignment called Sort Method. In this, i have to have IntegerSorter implement Sorter. This class sorts out numbers from less to greatest. So, far I am having a lot of errors. Can someone give me a hand on this? Thanks.
//Margaret
//Computer Science
import java.awt;
public class IntegerSorter implements Sorter{
public static void main(String[] args) {
//First, we will create an array.
arrayList [] = new Array [] {4,2,14,9,5,7,1,10};
//Second, in this part, we will make this program print out the orginal. So, for example: 4,2,14,9,5,7,1,10. The program will output 4,2,14,9,5,7,1,10 in ascending order.
System.out.println ("Original question: \n ");
for (int order = 0; order < array.List; order++)
System.out.println (" " + List[order]);
// Thirdly, we want to sort this out.
Arrays.sort (List);
//print out in ascending order
System.out.println ("Sorted Answer: \n ");
for(int order = 0; order < array.length ; order++)
System.out.print(" " + List[order]);
//long System.currentTime Millis()
public void sort_method1 (int [] list){
}
}
}
Description: |
|
Download |
Filename: |
Sorter.java |
Filesize: |
804 Bytes |
Downloaded: |
363 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
SapphireBlue
|
Posted: Tue Apr 12, 2011 11:53 pm Post subject: Re: Integer Sorter |
|
|
Here are the errors I have encountered
6 errors found:
File: C:\Documents and Settings\Owner\Desktop\Margaret's My Documents\Computers\drjava\Matrix\Matrix\IntegerSorter.java [line: 4]
Error: Only a type can be imported. java.awt resolves to a package
File: C:\Documents and Settings\Owner\Desktop\Margaret's My Documents\Computers\drjava\Matrix\Matrix\IntegerSorter.java [line: 6]
Error: The type IntegerSorter must implement the inherited abstract method Sorter.setList(int[])
File: C:\Documents and Settings\Owner\Desktop\Margaret's My Documents\Computers\drjava\Matrix\Matrix\IntegerSorter.java [line: 6]
Error: The type IntegerSorter must implement the inherited abstract method Sorter.sort(int)
File: C:\Documents and Settings\Owner\Desktop\Margaret's My Documents\Computers\drjava\Matrix\Matrix\IntegerSorter.java [line: 9]
Error: Syntax error on token "]", VariableDeclaratorId expected after this token
File: C:\Documents and Settings\Owner\Desktop\Margaret's My Documents\Computers\drjava\Matrix\Matrix\IntegerSorter.java [line: 26]
Error: Syntax error on token "(", ; expected
File: C:\Documents and Settings\Owner\Desktop\Margaret's My Documents\Computers\drjava\Matrix\Matrix\IntegerSorter.java [line: 26]
Error: Syntax error on token ")", ; expected
|
|
|
|
|
|
Tony
|
Posted: Wed Apr 13, 2011 12:03 am Post subject: RE:Integer Sorter |
|
|
The first 3 errors are straight-forward in a way that they are what they say they are. Read the error message and fix what it says.
4th and afterwards has to do with the fact that is not how a variable is created / initialized to an array. That throws the parser off for everything that follows. There is also no "Array" class in Java.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
DemonWasp
|
Posted: Wed Apr 13, 2011 12:50 am Post subject: RE:Integer Sorter |
|
|
Actually, Tony, there are two things in Java named Array, java.lang.reflect.Array, and java.sql.Array . You're still right about his declaration being off.
Errors by number:
1. You're importing "java.awt", you probably meant "java.awt.*".
2. You have said "IntegerSorter implements Sorter", but then failed to implement the "setList ( int[] )" method. You will need to do so.
3. See #2.
4-6. Read the documentation / training on how to declare and instantiate an array of ints in Java, because that line is pretty wrong.
|
|
|
|
|
|
Tony
|
Posted: Wed Apr 13, 2011 1:11 am Post subject: RE:Integer Sorter |
|
|
java.sql.Array appears to be an interface; java.lang.reflect.Array does not have constructors, so one can't have new java.lang.reflect.Array(); but good point, there are things in Java called "Array".
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
SapphireBlue
|
Posted: Wed Apr 13, 2011 1:44 pm Post subject: RE:Integer Sorter |
|
|
Hello.
I managed to correct some of the errors you had told me. However, as I add more info, I'm getting 5 errors.
Here are the errors:
File: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java [line: 26]
Error: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java:26: illegal start of expression
File: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java [line: 26]
Error: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java:26: illegal start of expression
File: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java [line: 26]
Error: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java:26: ';' expected
File: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java [line: 26]
Error: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java:26: ';' expected
File: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java [line: 34]
Error: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java:34: reached end of file while parsing
Also, here is my code so far:
//Margaret
//Computer Science
import java.awt.*;
public class IntegerSorter implements Sorter{
public static void main(String[] args) {
//First, we will create an array.
arrayList [8] = new Array [] {4, 2, 14, 9, 5, 7, 1, 10};
//Second, in this part, we will make this program print out the orginal. So, for example: 4,2,14,9,5,7,1,10. The program will output 4,2,14,9,5,7,1,10 in ascending order.
System.out.println ("Original question: \n ");
for (int order = 0; order < array.List; order++)
System.out.println (" " + List[order]);
// Thirdly, we want to sort this out.
Arrays.sort (List);
//print out in ascending order
System.out.println ("Sorted Answer: \n ");
for(int order = 0; order < array.length ; order++)
System.out.print(" " + List[order]);
//long System.currentTime Millis()
public void sort_method1 (int [] list){
int x;
for (int x = 0; x < array.length; x++){
for (inr y = 0; y < array.length; y++){
}
}
}
}
|
|
|
|
|
|
Tony
|
Posted: Wed Apr 13, 2011 2:03 pm Post subject: RE:Integer Sorter |
|
|
One of the most important skills in Computer Science / programming, that I feel is not emphasized in classes, is the ability to read and understand errors. It takes practice and most of it comes from experience. There are two critical pieces of information here: the line number and what the compiler was expecting to find there.
Quote:
File: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java [line: 26]
Error: H:\Computers\Java\dr.java\Work\Integer Sorter\IntegerSorter.java:26: illegal start of expression
This particular error is tricky, because the line 26 is not even an expression. Because the compiler is expecting to find an expression there, this hints us that maybe there's something missing in the lines just before this point.
Extra hint: proper indentation will be a huge help.
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
SapphireBlue
|
Posted: Wed Apr 13, 2011 2:19 pm Post subject: Re: Integer Sorter |
|
|
Hello Tony.
Thank you for your advice. I'll try to see if I could fix it. I also indent however, when I paste the information, it will show me it unindented. How do I approach this problem in your view?
- Margaret
|
|
|
|
|
|
Tony
|
Posted: Wed Apr 13, 2011 2:27 pm Post subject: RE:Integer Sorter |
|
|
using [ code ] tags [/ code ] (sans spaces) will preserve the indentation information.
code: |
for(;;){
System.out.println("infinite loop!");
}
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
btiffin
|
|
|
|
|
|
|