Jump to content

modmouse

Members
  • Posts

    4
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by modmouse

  1. I'm after validation for these bellow with an explanation to what I'm trying to attempt for each one. public void setPrice(int aPrice)throws DishException { if (aPrice < 0) throw new DishException ("Price cannot not be a negative number"); price = aPrice; } Only accept numbers, and cannot be empty. public void setType(char aType) throws DishException { if(aType == 0) throw new DishException ("A dish type must be entered"); type = aType; } Only accept one letter from the following [s,m,d or S,M,D] public void setName (String aName)throws DishException { if(aName.length() == 0) throw new DishException ("A dish name must be entered"); name = aName; } Only allow words no numbers or symbols Any help would be great B)
  2. Main.java public static void saveAsHandler() throws IOException, DishException { String fileName = StringIO.ask("file name: "); myMenu.saveAs(fileName); } public static void openHandler() throws IOException, DishException, ClassNotFoundException { String fileName = StringIO.ask("file name: "); myMenu.open(fileName); } ========================== Menu.java public void saveAs (String aFilename) throws IOException { FileOutputStream outFile = new FileOutputStream (aFilename); ObjectOutputStream itemsFile = new ObjectOutputStream (outFile); itemsFile.writeObject(menu); itemsFile.writeObject(codes); itemsFile.close(); } public void open (String aFilename) throws IOException, ClassNotFoundException { FileInputStream inFile = new FileInputStream (aFilename); ObjectInputStream itemsFile = new ObjectInputStream (inFile); menu = (Vector)itemsFile.readObject(); codes = (Vector)itemsFile.readObject(); itemsFile.close(); }[/CODE]At the moment files are saved in the same directory as the program has been run from but when I burn it to cd of course this is not possible. I've seen examples but I cannot work out where things like [CODE]("Z:\\results\\results.txt"); or ("z:\\results.txt"); or ("z:/results.txt");[/CODE] are supposed to be placed to save a file created by the java application to a pre determined location. Or even one set by the user.
  3. Thanks, I also want validation to check not at the end of entering a set of data but after each piece of data has been added how best would I be able to do this?
  4. public void setType(char aType) throws DishException { if(aType.length() == 0) throw new DishException ("A dish type must be entered"); type = aType; } ERROR: object type required, but char found.[/CODE] I am using jbuilder 3 and I am aware I am using the wrong validation but since I'm unsure what is the correct method to use for char type validation I'm here to see what help I can get. Since I've not covered char before this is new too me. This is the only validation error I am having others are intiger and string without any errors. I have to keep it as character and not change it. Thanks in advance.
×
×
  • Create New...