Hey:)

I am creating a project in java,but have been sick for the passed 3 weeks, so I am a bit stuck on how some of the code should look,and where it should be
the details are that I am required to develope an application that will allow the user to manage their downloads, the bit I am stuck on is the user should be able to add delete, order and search the array of objects

this is what I have done so far,r any pointers in the right direction would be great or links where I would find examples would be great too

thanks in advance:))))

there is a lot of code here but I am pasting it 3 parts so people can see that i have put work in,

//class file
import javax.swing;
public class DownLoadManager
{
	public static String albumTitle;
	public static String albumName;
	public static String albumArtist;
	public static String albumWebSite;
	public static double albumPrice;
	
	
	DownLoadManager(String aTitle, String anAlbum, String anArtist, String aSite, double aPrice)
	{
		albumTitle = aTitle;
		albumName = anAlbum;
		albumArtist = anArtist;
		albumWebsite = aSite;
		albumPrice = aPrice;
		
	}
	public String getTitle()
	{
		return title;
	}
	public String getAlbumName()
	{
		return albumName;
	}
	public String getAlbumArtist()
	{
		return albumArtist;
	}
	public String getAlbumWebSite()
	{
		return albumWebSite;
	}
	Public double getAlbumPrice()
	{
		return albumPrice;
	}
}



//main method
import java.util.Scanner;
public class MyDownload
{
	public class main(String [] args)
	{
		String results ="";
		{
			MyDownload [] MyDownloads = new DownLoad[4];
        myDownLoads[0] = new DownLoad("Confessions on a dance Floor", "Madonna", "Hung Up");
        myDownLoads[1] = new DownLoad("The legend of the Fall Offs", "Busta Rhymes", "The big Bang");
        myDownloads[2] = new DownLoad("Audioslave", "Audioslave", "Gasoline");
        myDownloads[3] = new DownLoad("Sevas Tra","'Sacrilege", "Otep");
        
        
        Scanner keyboard = new Scanner(System.in);
        System.out.println("1. Order Download by album title - ascending sequence");
        System.out.println("2. Order Download  by album artist - ascending sequence");
        System.out.println("3. Order Download  by album - ascending sequence");
        System.out.println("4. Order Download  by price - descending sequence");
        System.out.print(" Enter selection 1, 2, 3, 4.\t\t");
        int selection = Integer.parseInt(keyboard.nextLine());
        if (selection == 1)
        {
            bubbleSortOnAlbumTitleAscendingSequence(myDownLoads);
            displayDownLoads(myDownLoads);
        }
        else if (selection == 2)
        {
            bubbleSortOnAlbumArtistAscendingSequence(myDownLoads);
            displayDownLoads(myDownLoads);
        }
        else if (selection == 3)
        {
            bubbleSortOnAlbumAescendingSequence(myDownloads);
            displayDownloads(myDownloads);
        }
        else if (selection == 4)
        {
	        bubbleSortOnPriceDescendingSequence(myDownloads);
            displayDownloads(myDownloads);
	        }
        else
          System.out.print("Invalid selection");
      }
      public static void bubbleSortOnAlbumTitleAscendingSequence(Download[] downloads)
      {
          int pass, comparison;
          Download temp;
          for (pass=1; pass <= (downloads.length-1); pass++)
          {
              for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
              {
                  if (downloads[comparison-1].getAlbumTitle().compareTo(downloads[comparison].getAlbumTitle())>0)
                  {
                      temp = downloads[comparison-1];
                      downloads[comparison-1] = downloads[comparison];
                      downloads[comparison] = temp;
                  }
              }
          }
      }
      public static void bubbleSortOnAlbumArtistAscendingSequence(Download[] downloads)
      {
	      int pass, comparison;
          Download temp;
          for (pass=1; pass <= (downloads.length-1); pass++)
          {
              for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
              {
                  if (downloads[comparison-1].getAlbumArtist().compareTo(downloads[comparison].getAlbumArtist())>0)
                  {
                      temp = downloads[comparison-1];
                      downloads[comparison-1] = downloads[comparison];
                      downloads[comparison] = temp;
                  }
              }
          }
      }
      public static void bubbleSortOnAlbumAscendingSequence(Download[] downloads)
      {
	      int pass, comparison;
          Download temp;
          for (pass=1; pass <= (downloads.length-1); pass++)
          {
              for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
              {
                  if (downloads[comparison-1].getAlbum().compareTo(downloads[comparison].getAlbum())>0)
                  {
                      temp = downloads[comparison-1];
                      downloads[comparison-1] = downloads[comparison];
                      downloads[comparison] = temp;
                  }
              }
          }
      }
      public static void bubbleSortOnPriceDescendingSequence(Download[] downloads)
      {
	      int pass, comparison;
          Download temp;
          for (pass=1; pass <= (downloads.length-1); pass++)
          {
              for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
              {
                  if (downloads[comparison-1].getPrice().compareTo(downloads[comparison].getPrice())>0)
                  {
                      temp = downloads[comparison-1];
                      downloads[comparison-1] = downloads[comparison];
                      downloads[comparison] = temp;
                  }
              }
          }
      }
      public static void displayDownloads(MyDownload[] downloads)
      {
          for (int i = 0; i < downloads.length; i++)
            System.out.println(downloads[i].getAlbumTitle() + "\n" +
                               downloads[i].getAlbumArtist() + "\n" +
                               downloads[i].getAlbum() + "\n" +
                               downloads[i].getPrice());            
  }
}

//reading a file into an array of objects
import javax.swing.JOptionPane;
import java.io*;

public class ArrayFromFile
{
	public static void main(String [] args throw IOException
	{
		FileReader aFileReader = new FileReader("downloadManager.txt");
		BufferedReader aBufferedReader = new BufferedReader(aFileReader);
		
		String lineFromFile;
		int lineCount = 0;
		
		while ( ( lineFromFile = aBufferedReader.readLine()) != null)
		{
			lineCount++]
		}
		aBufferedReader.close();
		aFileReader.close();
		
		DownLoadManager[] myDownloads = new DownLoad[lineCount];
		String[] fileDetailes;
		String aTitle;
		String aName;
		String anArtist;
		String aSite;
		double aPrice;
		
		aFileReader = new FileReader("downloadManager.txt");
	    aBufferedReader = new BufferedReader(aFileReader);
	    
	    while ( ( lineFromFile = aBufferedReader.readLine()) != null)
	    {
		    fileDetailes = lineFromFile.Split(",");
		    aTitle = fileDetailes[0]);
		    aName = fileDetails[1]);
		    anArtist = fileDetails[2]);
		    aSite = fileDetails[3]);
		    aPrice = Double.parseDouble(fileDetails[4]);
		    
		    myDownLoads[count] = new DownLoad(aTitle,  aName, anArtist, aSite, aPrice);
		    count++;
	    }
	    aBufferedReader.close();
	    aFileReader.close();
	    
	    for (int i = 0; i <count;i++)
	    {
		    System.out.println(myDownLoads[i].getAlbumTitle() + " " + myDownLoads[i].getAlbumArtist() + " " + myDownLoads[i].getAlbumName() + " " + myDownLoads[i].getAlbumPrice());
	    }
    }
}

Edited 6 Years Ago by Nick Evan: Added code-tags

That much code is not fun to read, even less fun when it isnt in code tags :)

//class file
import javax.swing;
public class DownLoadManager
{
public static String albumTitle;
public static String albumName;
public static String albumArtist;
public static String albumWebSite;
public static double albumPrice;


DownLoadManager(String aTitle, String anAlbum, String anArtist, String aSite, double aPrice)
{
albumTitle = aTitle;
albumName = anAlbum;
albumArtist = anArtist;
albumWebsite = aSite;
albumPrice = aPrice;

}
public String getTitle()
{
return title;
}
public String getAlbumName()
{
return albumName;
}
public String getAlbumArtist()
{
return albumArtist;
}
public String getAlbumWebSite()
{
return albumWebSite;
}
Public double getAlbumPrice()
{
return albumPrice;
}
}



//main method
import java.util.Scanner;
public class MyDownload
{
public class main(String [] args)
{
String results ="";
{
MyDownload [] MyDownloads = new DownLoad[4];
myDownLoads[0] = new DownLoad("Confessions on a dance Floor", "Madonna", "Hung Up");
myDownLoads[1] = new DownLoad("The legend of the Fall Offs", "Busta Rhymes", "The big Bang");
myDownloads[2] = new DownLoad("Audioslave", "Audioslave", "Gasoline");
myDownloads[3] = new DownLoad("Sevas Tra","'Sacrilege", "Otep");


Scanner keyboard = new Scanner(System.in);
System.out.println("1. Order Download by album title - ascending sequence");
System.out.println("2. Order Download by album artist - ascending sequence");
System.out.println("3. Order Download by album - ascending sequence");
System.out.println("4. Order Download by price - descending sequence");
System.out.print(" Enter selection 1, 2, 3, 4.\t\t");
int selection = Integer.parseInt(keyboard.nextLine());
if (selection == 1)
{
bubbleSortOnAlbumTitleAscendingSequence(myDownLoads);
displayDownLoads(myDownLoads);
}
else if (selection == 2)
{
bubbleSortOnAlbumArtistAscendingSequence(myDownLoads);
displayDownLoads(myDownLoads);
}
else if (selection == 3)
{
bubbleSortOnAlbumAescendingSequence(myDownloads);
displayDownloads(myDownloads);
}
else if (selection == 4)
{
bubbleSortOnPriceDescendingSequence(myDownloads);
displayDownloads(myDownloads);
}
else
System.out.print("Invalid selection");
}
public static void bubbleSortOnAlbumTitleAscendingSequence(Download[] downloads)
{
int pass, comparison;
Download temp;
for (pass=1; pass <= (downloads.length-1); pass++)
{
for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
{
if (downloads[comparison-1].getAlbumTitle().compareTo(downloads[comparison].getAlbumTitle())>0)
{
temp = downloads[comparison-1];
downloads[comparison-1] = downloads[comparison];
downloads[comparison] = temp;
}
}
}
}
public static void bubbleSortOnAlbumArtistAscendingSequence(Download[] downloads)
{
int pass, comparison;
Download temp;
for (pass=1; pass <= (downloads.length-1); pass++)
{
for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
{
if (downloads[comparison-1].getAlbumArtist().compareTo(downloads[comparison].getAlbumArtist())>0)
{
temp = downloads[comparison-1];
downloads[comparison-1] = downloads[comparison];
downloads[comparison] = temp;
}
}
}
}
public static void bubbleSortOnAlbumAscendingSequence(Download[] downloads)
{
int pass, comparison;
Download temp;
for (pass=1; pass <= (downloads.length-1); pass++)
{
for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
{
if (downloads[comparison-1].getAlbum().compareTo(downloads[comparison].getAlbum())>0)
{
temp = downloads[comparison-1];
downloads[comparison-1] = downloads[comparison];
downloads[comparison] = temp;
}
}
}
}
public static void bubbleSortOnPriceDescendingSequence(Download[] downloads)
{
int pass, comparison;
Download temp;
for (pass=1; pass <= (downloads.length-1); pass++)
{
for (comparison = 1; comparison <= (downloads.length-pass); comparison++)
{
if (downloads[comparison-1].getPrice().compareTo(downloads[comparison].getPrice())>0)
{
temp = downloads[comparison-1];
downloads[comparison-1] = downloads[comparison];
downloads[comparison] = temp;
}
}
}
}
public static void displayDownloads(MyDownload[] downloads)
{
for (int i = 0; i < downloads.length; i++)
System.out.println(downloads[i].getAlbumTitle() + "\n" +
downloads[i].getAlbumArtist() + "\n" +
downloads[i].getAlbum() + "\n" +
downloads[i].getPrice());
}
}

//reading a file into an array of objects
import javax.swing.JOptionPane;
import java.io*;

public class ArrayFromFile
{
public static void main(String [] args throw IOException
{
FileReader aFileReader = new FileReader("downloadManager.txt");
BufferedReader aBufferedReader = new BufferedReader(aFileReader);

String lineFromFile;
int lineCount = 0;

while ( ( lineFromFile = aBufferedReader.readLine()) != null)
{
lineCount++]
}
aBufferedReader.close();
aFileReader.close();

DownLoadManager[] myDownloads = new DownLoad[lineCount];
String[] fileDetailes;
String aTitle;
String aName;
String anArtist;
String aSite;
double aPrice;

aFileReader = new FileReader("downloadManager.txt");
aBufferedReader = new BufferedReader(aFileReader);

while ( ( lineFromFile = aBufferedReader.readLine()) != null)
{
fileDetailes = lineFromFile.Split(",");
aTitle = fileDetailes[0]);
aName = fileDetails[1]);
anArtist = fileDetails[2]);
aSite = fileDetails[3]);
aPrice = Double.parseDouble(fileDetails[4]);

myDownLoads[count] = new DownLoad(aTitle, aName, anArtist, aSite, aPrice);
count++;
}
aBufferedReader.close();
aFileReader.close();

for (int i = 0; i <count;i++)
{
System.out.println(myDownLoads[i].getAlbumTitle() + " " + myDownLoads[i].getAlbumArtist() + " " + myDownLoads[i].getAlbumName() + " " + myDownLoads[i].getAlbumPrice());
}
}
}

Getting it to a state that it would even compile would help. You have all of your type declarations mangled up.

Did you write any of this code to begin with? If I were to guess, you're in the process of trying to rename variables and modify someone else's code and you don't understand it.

well you would be wrong, I am going by notes that I have form online
I have been off college for three weeks and missed the first smester because of brain surgery,so I dont know anyone this smester to coppy from, but thanks for you enlighting reply..it was great.

So you randomly decided to rename some of your own classes from code you wrote that was working just fine previously and you don't understand variable declaration well enough to use the new class names where needed? Seems a little odd to me, but hey, what do I know.

As I already said - getting it to a point it will compile is a good place to start. Then you can approach adding/removing from the array.

I see more static methods than main, I usually just discard the code (maybe reusing snippets here and there to put into other methods).

This question has already been answered. Start a new discussion instead.