Results 1 to 2 of 2

Thread: Sorting Issue

  1. #1
    learning.java is offline Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0

    Default Sorting Issue

    Below I have a "Show" & "Driver" class. In my main method of driver, I create an array of shows. I print them out in toString in the Show class.

    Here is my problem: I want to sort these arrays, and print them out in order. I want to sort them by the each "shows" time argument (second to last argument) from lowest to highest.

    Any help would be great, thanks.


    Java Code:
    public class Show {
    
    	public String band;
    	public String stage;
    	public int day;
    	public double time;
    	public int rank;
    	
    	public Show(String band, String stage, int day, double time, int rank )
    	{
    		this.band = band;
    		this.stage = stage;
    		this.day = day;
    		this.time = time;
    		this.rank = rank;		
    	}
    	/**
    	 * @return the band
    	 */
    	public String getBand()
    	{
    		return band;
    	}
    	/**
    	 * @param band the band to set
    	 */
    	public void setBand(String band) 
    	{
    		this.band = band;
    	}
    	
    	/**
    	 * @return the stage
    	 */
    	public String getStage() 
    	{
    		return stage;
    	}
    	/**
    	 * @param stage the stage to set
    	 */
    	public void setStage(String stage) 
    	{
    		this.stage = stage;
    	}
    	/**
    	 * @return the day
    	 */
    	public int getDay() 
    	{
    		return day;
    	}
    	/**
    	 * @param day the day to set
    	 */
    	public void setDay(int day) 
    	{
    		this.day = day;
    	}
    	/**
    	 * @return the time
    	 */
    	public double getTime() 
    	{
    		return time;
    	}
    	/**
    	 * @param time the time to set
    	 */
    	public void setTime(double time) 
    	{
    		this.time = time;
    	}
    	/**
    	 * @return the level
    	 */
    	public int getLevel()
    	{
    		return rank;
    	}
    	/**
    	 * @param level the level to set
    	 */
    	
    	public void setRank(int rank) 
    	{
    		this.rank = rank;
    	}
    	
    	public String toString()
    	{
    		String string = time + ": " + band  + " at the " + stage + " stage.";
    		
    		return string;
    	}
    }




    Driver



    Java Code:
    public class Driver
    {
    	public Driver() 
    	{
    		
    	}
    
    	/**
    	 * @param args
    	 */
    	
    	public static void main(String[] args)
    	
    	{
    			Show [] shows = 		
    			{				
    					
    				 new Show("Srillex", "Womp", 1, 4.00, 2),
    				 new Show("Bon Iver","chill", 1, 1.00, 1),
    				 new Show("Miley", "Bud Light", 1, 1.00, 0),
    				 new Show("Juicy-J", "Bud Light", 1, 3.00, 0),
    				 new Show("Mumford & Sons", "Chill", 1, 9.00, 1),
    				 new Show("Dave Matthews Band", "chill", 1, 6.30, 1),
    				 new Show("Lil Wayne", "YOLO", 1, 4.00, 1),
    				 new Show("Tupac", "YOLO", 1, 1.00, 1),
    				 new Show("Biggie Smalls", "YOLO", 1, 7.00, 2),
    				 new Show("Blink-182", "womp", 1, 8.00, 3)
    			};
    		// band, stage , day. time, rank
    			
    		System.out.println("This is your line up: ");
    	
    			for(int i = 0; i < shows.length; i++)
    			{ 
    				//Arrays.sort(party);
    				System.out.println(shows[i]);
    				
    			}
    		}
    	}

  2. #2
    learning.java is offline Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Sorting ArrayList special issue
    By garnaout in forum New To Java
    Replies: 3
    Last Post: 06-12-2012, 06:59 AM
  2. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 03:33 AM
  3. Sorting Array Issue
    By larson1118 in forum New To Java
    Replies: 2
    Last Post: 04-21-2011, 05:31 PM
  4. little help with sorting
    By drgnfire25 in forum New To Java
    Replies: 3
    Last Post: 01-15-2011, 09:23 PM
  5. Help in sorting
    By nn12 in forum New To Java
    Replies: 3
    Last Post: 01-08-2011, 06:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •