Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

CardHandler
Saturday, December 15th, 2007 at 5:16:51am MST 

  1. /************  CardHandler.java  ************/
  2. import java.io.*;
  3. import java.util.Formatter;
  4.  
  5. public class CardHandler {
  6.         protected String Name;
  7.         protected double Value;
  8.         protected String Type;
  9.         protected String LastAction;
  10.        
  11.         File cardFile;
  12.        
  13.         public boolean openFromPath(String filename) {
  14.                 cardFile = new File(filename);
  15.                 if (!cardFile.exists()) { return false; }
  16.                 try {
  17.                         FileReader input = new FileReader(filename);
  18.                         BufferedReader bufRead = new BufferedReader(input);
  19.                         //String line = getClass().getName();   // String that holds current file line
  20.                        
  21.                         String Line[] = new String[4];
  22.                         for (int i=0; i<Line.length; i++) {
  23.                                 Line[i] = bufRead.readLine();
  24.                         }
  25.                         Type = Line[0];
  26.                         Name = Line[1];
  27.                         Value = Double.valueOf(Line[2].trim()).doubleValue();
  28.                         LastAction = Line[3];
  29.                        
  30.                         bufRead.close();   
  31.                 }
  32.                 catch (ArrayIndexOutOfBoundsException e){ System.out.println("array index error"); return false; }
  33.                 catch (IOException e) { System.out.println("IO error"); return false; }
  34.                 return true;
  35.         }
  36.        
  37.         public boolean isInserted() {
  38.                 return cardFile.exists();
  39.         }
  40.  
  41.         public String getMeta(String dataname) {
  42.                 if (dataname.equals("Type")) {return Type;}
  43.                 if (dataname.equals("Name")) {return Name;}
  44.                 if (dataname.equals("LastAction")) {return LastAction;}
  45.                 return null;
  46.         }
  47.         public double getValue() {
  48.                 return Value;
  49.         }
  50.  
  51.         public void setMeta(String dataname, String newValue) {
  52.                 if (dataname.equals("Type")) {this.Type = newValue;}
  53.                 if (dataname.equals("Name")) {this.Name = newValue;}
  54.                 if (dataname.equals("Value")) {this.Value = Double.valueOf(newValue).doubleValue();}
  55.                 if (dataname.equals("LastAction")) {this.LastAction = newValue;}
  56.         }
  57.        
  58.         public void adjustValue(double difference) {
  59.                 Value += difference;
  60.         }
  61.  
  62.         public boolean close() {
  63.                 try
  64.                 {
  65.                         PrintStream ps = new PrintStream(cardFile);
  66.                         ps.println(Type);
  67.                         ps.println(Name);
  68.                         ps.println(Value);
  69.                         ps.println(LastAction);
  70.                         ps.close();
  71.                 }
  72.                 catch (IOException e) { return false; }
  73.                 return true;
  74.         }
  75. }

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

fantasy-obligation
fantasy-obligation