Results 1 to 3 of 3
  1. #1
    cest.lavie16 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default Error: The Type Property Already Defined

    I'm having trouble running this program. Eclipse says "The type Propery is already defined."

    Please help!

    public class Assignment_2
    {
    public static void main(String[] args)
    {
    Property[] prop =
    {
    new Property('C', 100000, 3, 580,"1111 Ocean View, Ventura, CA"),
    new Property('S', 300000, 6, 180, "10 Holly Oak, Littleton, CO"),
    new Property('S', 500000, 5, 111, "28434 Agajanian Road, Santa Clari"
    + "ta, CA"),
    new Property('S', 200000, 7, 200, "2 Lonesome Road, Albany, GA"),
    new Property('R', 1650, 4, 500, "333 Candy Cane Lane, Redding, CA"),
    };

    Property.PrintArray("Properties:", prop);

    Property.ArraySort(prop, "byPrice");

    Property.PrintArray("Properties Sorted by Price:", prop);

    Property.ArraySort(prop, "byNumRooms");

    Property.PrintArray("Properties Sorted by Number of Rooms:", prop);

    Property.ArraySort(prop, "byDaysOnMarket");

    Property.PrintArray("Properties Sorted By Number of Days on Market:"
    , prop);
    }
    }

    class Property
    {
    private char type;
    private int price;
    private int bedrooms;
    private int days_on_market;
    private String address;

    public final static int MIN_LENGTH = 1;
    public final static int MAX_LENGTH = 100;
    public final static int MIN_PRICE = 0;
    public final static int MAX_PRICE = 100000000;
    public final static int MIN_BEDS = 1;
    public final static int MAX_BEDS = 20;
    public final static int MIN_DAYS = 0;
    public final static int MAX_DAYS = 365*5;
    public final static char DEFAULT_TYPE = 'R';
    public final static int DEFAULT_PRICE = 0;
    public final static int DEFAULT_BEDROOMS = 1;
    public final static int DEFAULT_DAYS = 0;
    public final static String DEFAULT_ADDRESS = " unknown ";
    public final static String PRICE = "byPrice";
    public final static String ROOMS = "byNumRooms";
    public final static String DAYS = "byDaysOnMarket";

    public Property(char typ, int cost, int beds, int days, String location)
    {
    type = DEFAULT_TYPE;
    price = DEFAULT_PRICE;
    bedrooms = DEFAULT_BEDROOMS;
    days_on_market = DEFAULT_DAYS;
    address = DEFAULT_ADDRESS;
    if (typ == 'R' || typ == 'C' || typ == 'S')
    type = typ;
    if (cost >= MIN_PRICE && cost <= MAX_PRICE)
    price = cost;
    if (beds >= MIN_BEDS && beds <= MAX_BEDS)
    bedrooms = beds;
    if (days >= MIN_DAYS && days <= MAX_DAYS)
    days_on_market = days;
    if (location.length() > MIN_LENGTH && location.length() <= MAX_LENGTH)
    address = location;
    }

    public static void ArraySort(Property property_list[], String key_field)
    {
    for (int k = 0; k < property_list.length; k++)
    {
    if (key_field == PRICE && !LargestPriceToTop(property_list,
    property_list.length-1-k))
    return;
    else if (key_field == ROOMS && !LargestNumRoomsToTop(
    property_list, property_list.length-1-k))
    return;
    else if (key_field == DAYS && !LongestToTop(property_list,
    property_list.length-1-k))
    return;
    else
    return;
    }
    }

    public static void PrintArray(String title, Property property_list[])
    {
    System.out.println("\n********** " + title + " **********\n");
    for (int k = 0; k < property_list.length; k++)
    System.out.println(property_list[k].Listing());
    System.out.println();
    }

    private static boolean LargestPriceToTop(Property[] property_list, int top)
    {
    boolean changed = false;
    Property propty;

    for (int k = 0; k < top; k++)
    if (property_list[k].price < property_list[k+1].price)
    {
    propty = property_list[k];
    property_list[k] = property_list[k+1];
    property_list[k+1] = propty;
    changed = true;
    }
    return changed;
    }

    private static boolean LargestNumRoomsToTop(Property[] property_list,
    int top)
    {
    boolean changed = false;
    Property propty;

    for (int k = 0; k < top; k++)
    if (property_list[k].bedrooms < property_list[k+1].bedrooms)
    {
    propty = property_list[k];
    property_list[k] = property_list[k+1];
    property_list[k+1] = propty;
    changed = true;
    }
    return changed;
    }

    private static boolean LongestToTop(Property[] property_list, int top)
    {
    boolean changed = false;
    Property propty;

    for (int k = 0; k < top; k++)
    if (property_list[k].days_on_market <
    property_list[k+1].days_on_market)
    {
    propty = property_list[k];
    property_list[k] = property_list[k+1];
    property_list[k+1] = propty;
    changed = true;
    }
    return changed;
    }

    public String ConvertType()
    {
    String return_string = null;

    if (type == 'R')
    return_string = "Rental";
    if (type == 'C')
    return_string = "Condo";
    if (type == 'S')
    return_string = "Single Family Dwelling";

    return return_string;
    }

    public String Listing()
    {
    String ret_string;

    ret_string = "Type: " + ConvertType() + ", Price: $" + price + ", " +
    "Days on Market: " + days_on_market + ", Bedrooms: " + bedrooms + ", "
    + address;

    return ret_string;
    }
    }

  2. #2
    Maximus-EVG is offline Member
    Join Date
    Apr 2011
    Location
    Canada!
    Posts
    30
    Rep Power
    0

    Default

    I just ran it in NetBeans and I get the output:

    Java Code:
    ********** Properties: **********
    
    Type: Condo, Price: $100000, Days on Market: 580, Bedrooms: 3, 1111 Ocean View, Ventura, CA
    Type: Single Family Dwelling, Price: $300000, Days on Market: 180, Bedrooms: 6, 10 Holly Oak, Littleton, CO
    Type: Single Family Dwelling, Price: $500000, Days on Market: 111, Bedrooms: 5, 28434 Agajanian Road, Santa Clarita, CA
    Type: Single Family Dwelling, Price: $200000, Days on Market: 200, Bedrooms: 7, 2 Lonesome Road, Albany, GA
    Type: Rental, Price: $1650, Days on Market: 500, Bedrooms: 4, 333 Candy Cane Lane, Redding, CA
    
    
    ********** Properties Sorted by Price: **********
    
    Type: Single Family Dwelling, Price: $300000, Days on Market: 180, Bedrooms: 6, 10 Holly Oak, Littleton, CO
    Type: Single Family Dwelling, Price: $500000, Days on Market: 111, Bedrooms: 5, 28434 Agajanian Road, Santa Clarita, CA
    Type: Single Family Dwelling, Price: $200000, Days on Market: 200, Bedrooms: 7, 2 Lonesome Road, Albany, GA
    Type: Condo, Price: $100000, Days on Market: 580, Bedrooms: 3, 1111 Ocean View, Ventura, CA
    Type: Rental, Price: $1650, Days on Market: 500, Bedrooms: 4, 333 Candy Cane Lane, Redding, CA
    
    
    ********** Properties Sorted by Number of Rooms: **********
    
    Type: Single Family Dwelling, Price: $300000, Days on Market: 180, Bedrooms: 6, 10 Holly Oak, Littleton, CO
    Type: Single Family Dwelling, Price: $200000, Days on Market: 200, Bedrooms: 7, 2 Lonesome Road, Albany, GA
    Type: Single Family Dwelling, Price: $500000, Days on Market: 111, Bedrooms: 5, 28434 Agajanian Road, Santa Clarita, CA
    Type: Rental, Price: $1650, Days on Market: 500, Bedrooms: 4, 333 Candy Cane Lane, Redding, CA
    Type: Condo, Price: $100000, Days on Market: 580, Bedrooms: 3, 1111 Ocean View, Ventura, CA
    
    
    ********** Properties Sorted By Number of Days on Market: **********
    
    Type: Single Family Dwelling, Price: $200000, Days on Market: 200, Bedrooms: 7, 2 Lonesome Road, Albany, GA
    Type: Single Family Dwelling, Price: $300000, Days on Market: 180, Bedrooms: 6, 10 Holly Oak, Littleton, CO
    Type: Rental, Price: $1650, Days on Market: 500, Bedrooms: 4, 333 Candy Cane Lane, Redding, CA
    [COLOR="Red"]Type: Condo, Price: $100000, Days on Market: 580, Bedrooms: 3, 1111 Ocean View, Ventura, CA[/COLOR]
    Type: Single Family Dwelling, Price: $500000, Days on Market: 111, Bedrooms: 5, 28434 Agajanian Road, Santa Clarita, CA
    Red >> for real?!

  3. #3
    cest.lavie16 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    Rewrote my program. Wondering if you could run in NetBeans for me.

    Thanks,
    Nicole

    public class Assignment_2
    {
    public static void main(String[] args)
    {
    Propertys[] prop =
    {
    new Propertys(Propertys.CND, 100000, 3, 580,"1111 Ocean View, Ventura,"
    + " CA"),
    new Propertys(Propertys.SFD, 300000, 6, 180, "10 Holly Oak, Littleton,"
    + " CO"),
    new Propertys(Propertys.SFD, 500000, 5, 111, "28434 Agajanian Road, Sa"
    + "nta Clarita, CA"),
    new Propertys(Propertys.SFD, 200000, 7, 200, "2 Lonesome Road, Albany,"
    + " GA"),
    new Propertys(Propertys.RNT, 1650, 4, 500, "333 Candy Cane Lane,"
    +" Redding, CA"),
    };

    Propertys.PrintArray("Properties:", prop);

    Propertys.ArraySort(prop, "byPrice");

    Propertys.PrintArray("Properties Sorted by Price:", prop);

    Propertys.ArraySort(prop, "byNumRooms");

    Propertys.PrintArray("Properties Sorted by Number of Rooms:", prop);

    Propertys.ArraySort(prop, "byDaysOnMarket");

    Propertys.PrintArray("Properties Sorted By Number of Days on Market:"
    , prop);
    }
    }

    class Propertys
    {
    private int type;
    private int price;
    private int bedrooms;
    private int days_on_market;
    private String address;

    public final static int RNT = 0;
    public final static int CND = 1;
    public final static int SFD = 2;
    public final static int MAX_ROOMS = 20;
    public final static int MAX_PRICE = 10000000;
    public final static int MAX_ADDY_LENGTH = 500;
    public final static int MAX_DAYS_ON_MARKET = 365 * 5;
    public final static String UNDEFINED = "[ undefined ]";
    public final static String PRICE = "byPrice";
    public final static String ROOMS = "byNumRooms";
    public final static String DAYS = "byDaysOnMarket";

    public Propertys(int typ, int cost, int beds, int days, String location)
    {
    type = SFD;
    price = bedrooms = days_on_market = 0;
    address = UNDEFINED;
    if (typ == RNT || typ == CND || typ == SFD)
    type = typ;
    if (cost > 0 && cost <= MAX_PRICE)
    price = cost;
    if (beds > 0 && beds < MAX_ROOMS)
    bedrooms = beds;
    if (days > 0 && days < MAX_DAYS_ON_MARKET)
    days_on_market = days;
    if (location.length() > 0 && location.length() <
    MAX_ADDY_LENGTH)
    address = location;
    }

    public static void ArraySort(Propertys property_list[], String key_field)
    {
    for (int k = 0; k < property_list.length; k++)
    if (!FloatLargestToTop(property_list,
    property_list.length-1-k, key_field))
    return;
    }

    private static boolean FloatLargestToTop(Propertys[] property_list, int top,
    String key_field)
    {
    boolean changed = false;
    Propertys propty;

    for (int k = 0; k < top; k++)
    if (property_list[k].compareTo(property_list[k+1], key_field) > 0)
    {
    propty = property_list[k];
    property_list[k] = property_list[k+1];
    property_list[k+1] = propty;
    changed = true;
    }
    return changed;
    }

    private int compareTo(Propertys prop, String key_field)
    {
    int number = 0;

    if (key_field == PRICE)
    {
    if (price > prop.price)
    number = -1;
    else if (price < prop.price)
    number = 1;
    else
    number = 0;
    }

    else if (key_field == ROOMS)
    {
    if (bedrooms > prop.bedrooms)
    number = -1;
    if (bedrooms < prop.bedrooms)
    number = 1;
    if (bedrooms == prop.bedrooms)
    number = 0;
    }

    else if (key_field == DAYS)
    {
    if (days_on_market > prop.days_on_market)
    number = -1;
    else if (days_on_market < prop.days_on_market)
    number = 1;
    else
    number = 0;
    }
    else
    number = 0;

    return number;
    }

    public static void PrintArray(String title, Propertys property_list[])
    {
    System.out.println("\n********** " + title + " **********\n");
    for (int k = 0; k < property_list.length; k++)
    System.out.println(property_list[k].Listing());
    System.out.println();
    }

    public String ConvertType()
    {
    String return_string = null;

    if (type == RNT)
    return_string = "Rental";
    if (type == CND)
    return_string = "Condo";
    if (type == SFD)
    return_string = "Single Family Dwelling";

    return return_string;
    }

    public String Listing()
    {
    String ret_string;

    ret_string = "Type: " + ConvertType() + ", Price: $" + price + ", " +
    "Days on Market: " + days_on_market + ", Bedrooms: " + bedrooms + ", "
    + address;

    return ret_string;
    }
    }

Similar Threads

  1. Replies: 0
    Last Post: 01-25-2011, 06:02 AM
  2. Replies: 4
    Last Post: 01-05-2011, 03:00 PM
  3. jsp-property-group error in web.xml
    By redforce.bala in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 10-25-2010, 11:04 AM
  4. Replies: 7
    Last Post: 08-22-2010, 11:51 AM
  5. Replies: 1
    Last Post: 05-20-2009, 08:46 PM

Posting Permissions

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