java - Writing a .class file? -


currently, i'm working on project user can enter in custom values in gui values translated .class file runtime read when program starts up. realize writing .txt file easier, not want do. new .class file making extend abstract class called "problem" also. can point me in right direction writing aforementioned file? in advance helpers! way, if have construct .java file compile somehow, solution also. still, don't know how :/

more code:

package resources;  import java.awt.image; import java.io.file; import java.io.serializable;  public abstract class problem implements comparable<problem>, serializable{      private static final long serialversionuid = 42l;     private file locatedat;     public static final int easy = 0;     public static final int medium = 1;     public static final int hard = 2;      public abstract string gettitle();     public abstract string getquestion();     public abstract image getquestionimage();     public abstract int getdifficulty();     public abstract topic gettopic();     public abstract string getauthor();     public abstract boolean iscorrect(string answer);      public final int compareto(problem p){         return this.gettitle().compareto(p.gettitle());     }      public final string tostring(){         return gettitle();     }      public final void setlocatedat(file file){         locatedat = file;     } }   package resources;  import java.util.stringtokenizer;  public abstract class numericproblem extends problem{      /**      * must specify number of significant digits answer should contain.      * if don't want check significant digits, return 0      *       * @return number of significant digits answer should have      *       * @since v 1.0      */     public abstract boolean checksigfigs();      /**      * must specify amount of error answer user can within       * remain correct. number should represented x% , not decimal       * format.      *       * @return amount of error submitted answer can deviate specified answer      *       * @since v 1.0      */     public abstract double geterrorpercentage();      /**      * must specify type of units problem should contain.      * if answer doesn't have units return "". if units shouldn't      * checked, return null.      *       * @return unit type answer should contain      *       * @since v 1.0      */     public abstract string getunits();      /**      * must specify answer problem being asked. number      * represented string because of significant digits.       *       * @return answer given problem      *       * @since v 1.0      */     public abstract string getanswer();       public final boolean iscorrect(string useranswer){          string answer = getanswer().trim();          useranswer = useranswer.trim();          stringtokenizer tokener = new stringtokenizer(useranswer, " ");         if(tokener.counttokens() != 2){             system.err.println("failed @ formatting");             return false;         }          useranswer = tokener.nexttoken();         string userunits = tokener.nexttoken();          system.out.println(sigfigsin(answer));         system.out.println(sigfigsin(useranswer));          // checks sigificant digits         if(checksigfigs()){             if(!(sigfigsin(useranswer) == sigfigsin(answer))){                 system.err.println("failed @ sig figs");                 return false;             }         }          // checks numeric         if(!checknumeric(useranswer, answer)){             system.err.println("failed @ numeric");             return false;         }          //checks units         if(getunits() != null){             if(!userunits.equals(getunits())){                 system.err.println("failed @ units");                 return false;             }         }          system.out.println("passed!");         return true;     }      private int sigfigsin(string anumber){          // removes unnecessary zeroes before answer         boolean done = false;         boolean periodhappened = false;          while(!done)         {             if(anumber.charat(0) == '0'){                 anumber = anumber.replacefirst("0", "");             }else if (anumber.charat(0) == '.'){                 anumber = anumber.replacefirst(".", "");                 periodhappened = true;             }else{                 done = true;             }         }          // if it's number 300 1 sig fig, dis         if(!periodhappened){             if(!anumber.contains(".")){                 done = false;                 while(!done){                     if(anumber.charat(anumber.length() - 1) == '0'){                         anumber = anumber.substring(0, anumber.length() - 1);                     }else{                         done = true;                     }                 }             }         }          return anumber.replaceall("\\.", "").length();      }      private boolean checknumeric(string answer, string useranswer){          double answer = double.parsedouble(answer);         double useranswer = double.parsedouble(useranswer);         double ep = geterrorpercentage() / 100;          if((answer * (1+ep) >= useranswer) && (useranswer >= answer * (1-ep)))             return true;          return false;      }    package problems;  import java.awt.image; import resources.numericproblem; import resources.problem; import resources.topic; import resources.formula;  public class anumericproblem extends numericproblem{      private final formula formula;      public anumericproblem(){         formula = formula.createrandomformula();     }      @override     public boolean checksigfigs() {         return true;     }      @override     public double geterrorpercentage() {         return 200;     }      @override     public string getunits() {         return "mols";     }      @override     public string getanswer() {         return formula.getmols();     }      @override     public string gettitle() {         return "formula";     }      @override     public string getquestion() {         return "how many moles in 4.9g of " + formula.getformula();     }      @override     public image getquestionimage() {         return null;     }      @override     public int getdifficulty() {         return problem.easy;     }      @override     public topic gettopic() {         return new topic("grams moles");     }      @override     public string getauthor() {         return "shawn";     }  }       } 

it's not asked for, problem sounds want build object bunch of values, save result later. if case, interested in object serialization, allows save object byte stream, , load object @ later time.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -