Switch Case


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Switch Case

  1. #1
    Join Date
    May 2009
    Posts
    1

    Switch Case

    Hello everyone i am currently working on a java program which is menu driven but i have completely stuck when entering the correct syntax in the switch case to allow each specific thing to work properly, i am really new to this so any help with the syntax would be greatly appreciated.
    Here is the code i have so far
    package assignment;
    import java.io.*;

    class propertyToLet
    {
    private String postcode;
    private String houseNo;
    private String monthlyRent;

    //Constructors

    public propertyToLet()
    {
    postcode="xxx";
    houseNo="xxxx";
    monthlyRent="xxx";
    }
    public propertyToLet(String postcode, String houseNo, String monthlyRent)
    {
    this.postcode=postcode;
    this.houseNo=houseNo;
    this.monthlyRent=monthlyRent;
    }

    //accessors

    public String getPostCode()
    {
    return postcode;
    }

    public String getHouseNo()
    {
    return houseNo;
    }

    public String getMonthlyRent()
    {
    return monthlyRent;
    }

    //mutators

    public void setpostcode(String newpostcode)
    {
    postcode = newpostcode;
    }

    public void sethouseNo (String newhouseNo)
    {
    houseNo = newhouseNo;
    }

    public void setmonthlyRent (String newmonthlyRent)
    {
    monthlyRent = newmonthlyRent;
    }

    }
    class propertyList
    {
    private String filename;
    private propertyToLet[] property;

    int numberofproperties=0;

    public propertyList() throws IOException
    {
    property = new propertyToLet[200];
    filename = "properties.txt";



    final FileReader f = new FileReader (filename);
    final BufferedReader tInputHandle = new BufferedReader(f);

    for(int i=0 ; i<200 ; i++)
    {
    property[i] = new propertyToLet();
    }

    while(tInputHandle.ready())
    {
    String tLine = tInputHandle.readLine();
    System.out.println();
    property[numberofproperties].sethouseNo(tLine);
    tLine = tInputHandle.readLine();
    property[numberofproperties].setpostcode(tLine);
    tLine = tInputHandle.readLine();
    property[numberofproperties].setmonthlyRent(tLine);

    numberofproperties++;

    }

    }
    public String getPostCode(int propertyID)
    {
    return property[propertyID].getPostCode();
    }

    public String getHouseNo(int propertyID)
    {
    return property[propertyID].getHouseNo();
    }

    public String getMonthlyRent(int propertyID)
    {
    return property[propertyID].getMonthlyRent();
    }

    public int getnumberofproperties()
    {
    return numberofproperties;
    }

    }
    public class Main {


    public static void main(String[] args) throws IOException

    {
    propertyList mypropertyList = new propertyList();

    int menu=0;

    do
    {


    final BufferedReader tKeyboard = new BufferedReader(new InputStreamReader(System.in));

    System.out.println("1, Add property");
    System.out.println("2, Remove properties from list");
    System.out.println("3, Load list of properties");
    System.out.println("4, Exit the system");
    System.out.print("\n Enter your choice: ");

    String tLine = tKeyboard.readLine();


    switch(menu)
    {
    case 1:
    System.out.println("Please Select the postcode, house number and monthly rent to add a property");

    break;

    case 2:
    System.out.println("Select the property that you would like to remove from your list");
    break;

    case 3:
    System.out.println("Properties in list");


    for(int i=0 ; i<mypropertyList.getnumberofproperties(); i++)


    break;

    case 4:
    System.out.println("Goodbye");
    System.exit(0);

    break;

    default:
    System.out.println("Error: Should not reach here.");
    }

    } while(menu >=1 && menu <= 4);

    }


    }
    Thanks

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    The switch value must be an integral value, can't be a String. Where are you setting the value for menu?

Similar Threads

  1. Databind Dropdown Asp.net
    By geo039 in forum ASP.NET
    Replies: 3
    Last Post: 08-06-2007, 03:46 PM
  2. errors with some varibles
    By ELHEK in forum Java
    Replies: 1
    Last Post: 10-01-2006, 05:08 PM
  3. Why is this in the console?
    By Dark Rain in forum Java
    Replies: 8
    Last Post: 09-30-2005, 06:42 PM
  4. Run-time error by a blank record made by code
    By VanDam in forum Database
    Replies: 0
    Last Post: 07-09-2005, 04:18 AM
  5. ADOX problem
    By Yoel Martinez in forum VB Classic
    Replies: 1
    Last Post: 12-12-2000, 03:17 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center