javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I'm still working on that problem. I can't figure it out, would it be possible to give me a similar example, or even would you know where can I look for a tutorial on the subject.:)

Well I will repeat myself. In the calcSubstitutionScore you create new List: List<Integer> subScore = new ArrayList<Integer>() that has no elements inside. And then you are trying to access it, so naturally this: subScore.get(tmaMarks) will not work since it has no elements.
Shouldn't you be using the private subScore List after you enter some values to it, instead of creating a new one with no values?

Secondly, did the average method had an argument or you added it. Because I believe that it should calculate the average value of one the lists declared in the class, but again I don't know what it is supposed to do.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

btw when you say ** I need to add to the treeset the entire diploma** u just mean I change it from

this.diploma.add(name.getName());
to
this.diploma.add(name);

right??

Yes, in that way the TreeSet will have the enire Diploma inside it, not just the its name.

Also you need to change the casting when you get the object from the TreeSet. Don't worry you will get the exceptions that will tell you where. Remember the TreeSet and ArrayList now have type diploma.


Also I have noticed 3 more mistakes. Once you have corrected those you will be ready to go. Just do some tests

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
while(line != null) {
            line = reader.readLine();
                       //int W = Integer.parseInt(line.substring(0,1));
                       //int xVal = Integer.parseInt(tokens[0]);
                      //int xVal = Integer.parseInt(tokens[1]);
                       // addPoints(W);
                       // yPts[].addPoints(W);
            int x = Integer.parseInt(line.nextToken());
            int y = Integer.parseInt(line.nextToken());
            xPts[cur] = x;  // these are created as public arrays earlier.
            yPts[cur] = y;
            cur++;
         }

"line" is a String. Where did you get the nexToken thing? Have you looked the example with spilt method?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try this site with tutorials:
http://www.w3schools.com/

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

OK there is your problem at the Uni class:

public void addDiploma(Diploma name){
	String message;
	//check if the entry exists
		this.diploma.add(name.getName());
}

You are supposed to add diplomas at the TreeSet, not their names. The diploma has more than just a name, it has Modules. So when you add the "diploma" object to the TreeSet, you add everything the diploma has(name and modules)
So when you create the ArrayList and get an element from it you get the entire diploma with name and everything.
With the way you had it you were adding the only the name which is a String: this.diploma.add(name.getName()); But when you were getting the elements you were casting it to Diploma.
You cannot take the name and create a new Diploma because you will loose any modules that the Diploma had. You need to add to the TreeSet the entire Diploma.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I took the code and I don't see any errors apart from this at the Student class:

public void printDetails() {
		String output=toString();
		Iterator allModules=this.allModules.iterator();
		while(allModules.hasNext()){

// WHAT IS THE AirlineFlight1 ? 			
output=output+((AirlineFlight1)(allModules.next())).toString();
		}
		
		JOptionPane.showMessageDialog(null,output,"Student Module Details",JOptionPane.INFORMATION_MESSAGE);
		
	}

Also when you call the getName() you don't need to cast it to String because the method already returns a String.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

post the Student class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In your calcSubstitutionScore method you create new lists. You don't use the ones with the scores

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Again you cannot access the elements of a list without checking their size. When you are calling this:
subScore.get()
you need to make sure that the argument is between 0 and size()
According to the error your list is empty

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One of your variables is a List, so natuarally you cannot add ("+") a list to an integer

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can read the input from the console using the Scanner class and store that into variables. Then use these variables at your query:

String street = "myStreet";
String query = "SELECT vendorid, vendname FROM vendors where street = '" + street + "'";
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Even if the database is updated you also need to update the comboBox as well by removing the book selected if the deletion was successful.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well for reading a file I use BufferedReader:

String fileName="C:/folder1/file.txt"
BufferedReader reader = new BufferedReader( new FileReader(fileName) );
String line = reader.readLine();
while(line!=null) {
   System.out.println(line);

    line = reader.readLine();
}

First you need to read the first line which happens outside the loop.
Then in order to enter the loop and continue, what you read should be not null. At the end of the loop after you have finished with all the calculations you read the next. Again you check to see if it is not null in order to continue. At the end of each loop you read the next line, so when you go at the begining you need to check if it is null or not in order to continue.
When you have reached the End Of the File the reader.readLine(); will return null so the while loop will exit.

Now after you have read the line here is an example on how to proceed

String line = "2 3";
String [] tokens = line.split(" ");
//tokens[0] has value "2"
//tokens[1] has value "3"

addPoints(Integer.parseInt(tokens[0]), Integer.parseInt(tokens[1]));

As for question about entering parameters, if you run the program like this:

java MainClass C:/folder1/file.txt

Then inside the main, the args array will have size 1 and the args[0] will have the input you gave:

public static void main(String[] args) {
		String file = args[0];
                System.out.println(file);
	}

Of course all the necessary checks should be made. Example:

public static void main(String[] args) {
    String …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all the Uni class has a TreeSet that takes type "Diploma". So when you do this:

ArrayList keys=new ArrayList(this.theUni.diploma);

The keys has Diploma inside it. So you don't need to do this:

diploma1=(String)keys.get(choice-1);
tempDiploma=new Diploma(diploma1);

This would be simpler:

Diploma dipl = (Diploma)keys.get(choice-1);

With the above you get the diploma that is inside the ArrayList, you don't create a new one. Which brings me to what think is the problem. Now I don't know where are you having your problem but this is what I think:

You declare this: Diploma tempDiploma; as global at the begining of your class. You don't use that anywhere it is just a diploma.
So when you do this: tempDiploma=new Diploma(diploma1); it has no meaning

The same goes for the Diploma theDiploma=new Diploma(); I don't know what you are trying to accomplish but if you want to add the new module to the diploma selected:

studentManagementMenu() {
....
}

Then you need to add it to this diploma: Diploma dipl = (Diploma)keys.get(choice-1); So you should have the studentMenu() takes as argument a Diploma and pass as argument the diploma selected. Then pass as argument the same diploma to the addModule() method


If this is not your problem give more details of what you are trying to accomplish and which part of your code doesn't work.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It will take me sometime to look the code, but I have some suggestions which I will post later, when I have the time.
And I did look at the code and I think I know what you should change.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post a screenshot of your server running?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well this is what I got with mixed numbers:

[1, 2, 3, 4]
[4, 3, 2, 1]
Enter the value you want to search for
4
The value you searched for is at index -5

It should have returned '3'.

After searching the API for collections
found that the method you are using :
int binarySearch(List<? extends Comparable<? super T>> list, T key)
requires a list that implements the "comparable" interface. so when I tried this I got an error: int where = Collections.binarySearch(Arrays.asList(a), searchValue); Because Arrays.asList(a) returns an Object list that doesn't implement the Comparable.
But there is another method you could use if it is not a limitation:
int binarySearch(List<? extends T> list,
T key,
Comparator<? super T> c)

Instead of implementing the Comparator, the API says that if you enter null: A null value indicates that the elements' natural ordering should be used. So it will use the comparator of the Integer class.
so try this:

Object[] a = mylist.toArray();
		Arrays.sort(a);
		System.out.println(Arrays.asList(a));
		//not working because mylist is not sorted in ascending order
		//must make sorted list the parameter for the Collections.binarySearch
		System.out.println(mylist);
		System.out.println("Enter the value you want to search for");
		int searchValue = scan.nextInt();


		//int where = Collections.binarySearch(mylist, searchValue);

		int where = Collections.binarySearch(Arrays.asList(a), searchValue, null);


		System.out.println("The value you searched for is at index " + where);
Grn Xtrm commented: Big help. Thanks. +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

can you show me the code

I still don't believe this!

Apparently you can't take a hint so I will redirect you to the following page which will answer all your questions and save all of us a great deal of time.
Click here

If your tone was different I would have given some hints as I did with others that had less demanding tone and more of "I want to learn but I don't know how to start"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

why you say it doesn't work. I have run it like this:

Enter the number of values to be added to the list
4
Input the values
4
3
2
1
[1, 2, 3, 4]
[4, 3, 2, 1]

As you can see the array 'a' is sorted ([1, 2, 3, 4]) , whereas the 'myList' is not [4, 3, 2, 1].
what were you expecting?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your GC has nothing to do with it. Here is a small example that will help you understand what you are doing:

Person p = new Person();
p.setName("My Name");
System.out.println(p.getName()); // will print My Name

p = new Person();
System.out.println(p.getName()); // will print null

You successfully create the lecture but when you go back that instance is out of scopt if you "close" the class, so it's gone. Do you have any ArrayLists or Vectors to store what you have created?
I mean you need to save somewhere what you have created.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ok, after coding it I will send it to your professor directly , let me know his email address.

SNIP

I don't believe he fell for that!

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Something else that came to mind:
Use the split method like this: String[] str = stringRead.split(" "); This will get you all the 'words' including the ":".
So loop throught the array until you find the ":".
You will know that, what is before the ":" and after should be at the same line.
When you find another ":". Print the previous token at a new line:

for (int i=0;i<str.length-1;i++) {
  if (str[i+1].equals(":")) {
      // the str[i] needs to go to a new line. change line
  }
   // print the str[i]
}

Make sure you make a good use of: System.out.println(); System.out.print("");

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Instead of PrintWriter use:
BufferedWriter.
When you write to the file, it overrides what it is written:

FileWriter fileWriter = new FileWriter("fileName"); //better check the API for this
BufferedWriter writer = new BufferedWriter(fileWriter);

writer.write("line");
writer.newLine(); 

// or writer.write("line\n");

writer.close();
// again check the API because I don't remember if FileWriter needs to be closed
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The static variable should be Date. Check the API. And you will give it value at the constructor. The second Date object that you will create at the constructor will be local. You will only use it to get the "now" Date and calculate the difference. Then you will give its value to the static global Date.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well I have finished the first part of my code.
The reason I had this question ~s.o.s~ was that I wanted to create a dynamic XML parser.

I have 1 method that takes as argument an Object and generates an XML file. The program uses reflection to get the names and return types of all the public get methods of the object and after invoking them it writes the file. Recursive was considered in case the get methods return a more complex object.

And I have another method that does the opposite. Takes as argument a Node interface and after "reading" the method names (public set methods), return types and values it invokes the set methods of the objects described at the tags to return an Object type. Again recursive was considered.

I know that this was a waste of time since there are a lot of tools that do that, but the main reason why I thought of doing that was beacause I think it's fun and most important educational.
I have never worked with the java.lang.reflect nor the org.w3c.dom packages so I wanted gain some experience.

My methods accept objects whose get,set methods return primitives, java.lang.* objects and other objects that have again the same get, set method signatures.

I will now try to add Arrays [] and List at the get, set methods

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Thanks, it worked.

I was searching the Integer class, but I must have missed that part:

static Class<Integer> TYPE
The Class instance representing the primitive type int.

Although I will use your suggestion, I was expecting for something more dynamic:

....
// code to get the type

String type="int";
Class.forName(type);

I don't know if the above can be done, which is why I started this thread

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just a quick question.
No rush to answer, it is not important, I might discover it later myself, but just in case someone knows it:

I have been trying to create a Method object using this method:
Class.getMethod(String name, Class<?>... parameterTypes)

like this:

obj.getClass().getMethod(methodName, Class.forName(methodType))

My problem is that the method takes as argument an int:

public void setA(int a) { ... }

So when I call this:
Class.forName("int") I get an exception:
java.lang.ClassNotFoundException: int

But when I call it like this:
Class.forName("java.lang.Integer") I get an exception:
java.lang.NoSuchMethodException: pack.ClassR.setA(java.lang.Integer)

Is there a way to fix this other than changing the signature of the method?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also there is another error in the code:

StringTokenizer st = new StringTokenizer(buffer," ");
          token = st.countTokens();
if (st.hasMoreTokens()) {
.......               
                source[i][0] = (st.nextToken());
                source[i][1] = (st.nextToken());     
               .......
            }

With the 'if' you check if there are more tokens but NOT if there are 2 tokens. Then you call the nextToken twice without checking there are any more tokens.
Meaning the if the line has only one token:

# 2 tokens
aaaaaa bbbbbb
# ONE token
ccccccccc

At the line with the "ccccccccc" you will get an exception because you call the nextToken twice but there is only 1 token.

Better use this:

StringTokenizer st = new StringTokenizer(buffer," ");
          token = st.countTokens();
if (token==2) {
.......               
                source[i][0] = (st.nextToken());
                source[i][1] = (st.nextToken());     
               .......
            }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try this one....
Regards
.................

Congratualtions,
The oldest thread reviving I have ever seen. Not to mention all the forum rules that you've just broken. (We do not give away free homework and we use code tags)
Last post by server_crash was May 8th, 2005 14:16.
What were you thinking? :)

Salem commented: Just another noob who's discovered their first programming "fact" and is rushing madly around looking for someone to tell like it's the most important thing in the world. +29
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all this: if (buffer.equals(null)) is totaly wrong. Not because it won't compile but because
If buffer is null you cannot call any methods. You will get a NullPointerException


The best way to check if something is null is the simplest: if (buffer==null) For all the other cases use .equals()

Also as for your code I prefer this simple solution:

String buffer = br.readLine();
int i=0;
while (buffer!=null){
  buffer = buffer.trim();
  if  ( (buffer.length!=0) && (buffer.charAt(0)!='#') ) {
       
          StringTokenizer st = new StringTokenizer(buffer," ");
          token = st.countTokens();

             if (st.hasMoreTokens()) {
                if (i==source.length) break;

                source[i][0] = (st.nextToken());
                source[i][1] = (st.nextToken());     
                i++; 
            }
  }
  buffer = br.readLine();
}

With your way you have 2 loops (while and for) but you use only ONE. At the end of the for, you read the next line and you continue with the for, so the while is not needed. BUT since increase the 'i' index in the for and the coninue, the array 'source' will have some elements missing.
Example, you will have source[0] have some value but as you increase the 'i' when you go to put again value, the next time might be source[3]. So those that are between will have null value.

With the above way, after the while has finished the 'i' will hold the number of lines actually put in the array. If only 4 lines much the requirements you will have values for:
source[0], source[1], source[2], source[3] and the rest …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After reading your problem, I have a question: Have you ever workd with static variables? Try this example:

class Test {
   private static int count = 0;
   
   public Test() {
        count++;
   }

   public String toString() {
       if (count==1) {
              return "This my first time";
      } else {
           return "I was instatiated: "+count+" times";
      }
   }

   public static void main(String [] args) {
       Test t1 = new Test();
       System.out.println(t1);

       Test t2 = new Test();
       System.out.println(t2);

       Test t3 = new Test();
       System.out.println(t3);
   }
}

You will have to do the same but instead of count you will have a Date object and an int variable (for counting the seconds).
At the constructor you will create locally a new Date, calculate the difference and store that, to the variable you have for storing the difference. Then replace the value of the static Date object with the one that you created locally.
The tricky part is knowing when was first time the class was created in order to print the right message

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The following class might be useful:
java.util.Date represents dates. Its toString() method returns the date and time in human readable form: getTime() returns a long representing the date in milliseconds, so that
(d1.getTime() - d2.getTime())/1000L
will be the time in seconds between dates d1 and d2. Finally, new Date() will return the current date and time.

This is just an explanation of what the Date class can do. What do you want, the toString method of the class TimedInstantiation do?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I will pay $5!

I know that there is an economic crisis all over the world but thank God, we are not that desperate. :icon_cheesygrin:
In my country, with the taxes and the insurance, I would have only $2.9 left!!! :'(

Salem commented: OP pays you $5, flunks and works at burgerworld. You support the OP again by spending $2.9 at burgerworld. +29
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I will pay the first person to finish this task via paypal!!!
I will pay $5!

Only $5 !! You have to be insane.

Firstly, the amount in insulting. In this forum there are many professional programmers that get paid much much more. Why should they bother to fix your problem? Not to mention that even if someone else would do this the amount is nothing near to what is necessary to tempt someone to do this. If you think this worths only $5 do it yourself

AND SECOND and most important. This is a forum for people to learn. We do not give away free code. And when I say "free", I don't mean code that people pay with money, but with effort.
Those who want help have showed with their questions and their efforts that they deserve it. And you will see that we have given code to many people, which was very close to the actual solution of their assignment, only because their attempts were genuine and they were as close as they could get.
This despicable offer of money is insulating to ALL the members of this forum that use their spare time to teach others and offer solutions free of charge because they want to, not because they are paid.
What you suggested can only be interpreted as a miserable attempt to bribe the members of this forum to betray their ideals and the other members of this forum.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry for the double post. Internet connection problems

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you have read from one file, store it in variables and use those to create the query.

Then read the other file with the data and for each line, generate the query with the values, and pass it as parameter to a method that executes it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you have read from one file, store it in variables and use those to create the query.

Then read the other file with the data and for each line, generate the query with the values, and pass it as parameter to a method that executes it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

can you do a System.out.println of the values:
id and fullName before you set them at the lifeinsured object?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
VALUES ('" + id + "','" + fullName

I don't see a missing quote. Are you sure this is the code you tried to run?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Search for code examples on how to read files (Scanner, BufferedReader). Write some test classes that just print the data of the files
Search for code examples on how to run queries. Write some test classes that execute simple.
Use the above to read the data, construct the queries and execute them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The problem is where you create your query not where you read the value and call the set method:
Assuming this:

public void setId(String id) {
   this.id = id;
}

>>> query = . . . . + "'" + id +"', "

I think you forgot to add the single quote at the query.
Post the relevant code where you generate the query

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes, read it in as a String and print it out. ?

Actually what smsamrc is asking is to print at the console something like this:

To have 2 as base and 3 to be smaller and to the upper right corner of 2.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Pass the information from one frame to the other before you call the "show" method.
Remember you can have the TextFields of the second frame public or with set methods in order to set their values from the first frame

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
String [] array = new String[5]; // array is not null but array[0], ... are null
//array variable is an array and should be treated like one.

// instatiating the elements of the array:
array[0] = "aa";
array[1] = "bb";

System.out.println("Array: "+array);
for (int i=0;i<array.length;i++) {
   System.out.println("Elements: "+array[i]);
}

//array[0] is a String and should be treated like a String

When you are creating any array this is one of the ways:
SomeObject [] array = new SomeObject[N];

With this
array[0] = new SomeObject(); you are creating a SomeObject instance. Remember array[0] IS a SomeObject.
array is an array.

Also if you still don't understand run my example.

And these things that you wrote will get you in trouble:

sfdstrg
hhytrujytjttrtry

If you don't understand something, repost with better explanation

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think using javascript. I don't have time to look it up but if you search at w3schools, you will find a complete reference of DHTML in order to do what you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The first error is easy. You cannot compare String using this: "<". For Strings you need to use this function:

if (  txt_pay.getItem().compareTo(txt_amount.getItem())<0  )
{
   jOptionPane1.showMessageDialog(this, "please enter the right amount");
}

And when you do this:

if (txt_pay.getItem().isEmpty())

The method isEmpty() needs to return a boolean value.

Also in java the 'null' value is this null

if (txt_pay.getItem() == null) // 2 '=' symbols when comparing

Also use this '==' when comparing a String with a null value like above, but if you want to compare 2 Strings that have value use this:

if ( !txt_pay.getText().equals("")  )

Also this converts a String into a numer

String s1  = "22.22";
double d = Double.parseDouble(s1);

String s2  = "13";
int i = Integer.parseInt(s2);
jam7cacci commented: fantastic! he's a great help +3
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Here is a suggestion I wanted to give you from the start but after seeing your implementation I thought it would be better to follow your approach since you have already written code for it:

class SinglePolynimial {
  public int power = 0;
  public double factor = 0;

  public SinglePolynimial(double factor, int power) {
     this.power = power;
     this.factor = factor;
  }

  public SinglePolynimial() {
  }

  public void mult(SinglePolynimial single) {
      power = power + single.power;
      factor = factor * single.factor;
  }

 public static SinglePolynimial mult(SinglePolynimial a, SinglePolynimial b) {
      int power = a.power + b.power;
      double factor = a.factor * b.factor;
      return new SinglePolynimial(factor, power);
  }
}

3.1x^5:
new SinglePolynimial(3.1, 5);

So this polynimial: 3x^2 + 4x + 5
will be ONE Vector with elements SinglePolynimial objects, each elements for each part of the polynimial: 3x^2 + 4x + 5

So you will have 2 Vectors, multiply each element of one vector with each element of the other vector using the methods of the objects and store them somewhere, (maybe a third vector).

Then you can itereate the elements of the new vector, and those that have the same power, add them.
Or you can do the add in the same with the multiplication.
But be carefull to add only those that have the same power.
Maybe you can add these methods to the class as well:

public static SinglePolynimial add(SinglePolynimial a, SinglePolynimial b) {
      if (a.power!=b.power) {
          return …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Actually the code that does the sorting is wrong and it would be easier to use objects to store the videos and do the sorting once you hear why your code is wrong.

The 2 array are not indepedent, the 1st element of the title array is linked with the 1st element of the rating array:
title: {"Terminator", "Vendetta"}
rating: {5, 4}

"Terminator" got a 5 and "Vendetta" got a 4. But when you sort them the arrays will look like this:
title: {"Terminator", "Vendetta"}
rating: {4, 5}

So "Terminator" will end up with a 4

If you are to sort them your way, you will need 2 methods to do the sorting.
One will sort based on title but when you swap the elements of the title array you will need to swap the elements of the rating array based on the title.
And the other method will sort based on the rating and again when you swap the elements of one array, equivalant swapping must take place for the other array

If you have array of objects and do the sorting by rating, you will do something like this:

videos[i].getRating() < videos[i + 1].getRating()

And the swapping will swap the object which has the rating AND the title that is linked with that rating

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I spoke with the instructor and he said he wants the two arrays in the code. (I told him what i thought about the 1 array, but he killed that idea)

Probably the instructor means that in 1 array will have the list with the videos, and at the other array you will have the sorted one

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

A small tutorial with examples about objects in arrays

Video video = new Video(); // ONE instance of Video

Video [] videos = new Video[5]; // this is an array

// videos is an array and should be treated as an array

// videos[0] is a Video but it is null because you haven't initialize it

videos[0] = new Video();
videos[0].setTitle("Some Title");

So your method will take as argument an array of Videos, you will iterate, get the title from each video and do the sorting