Advertisement
speedyRc

eqsolv

May 24th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /*
  6.  *     Your goal is to build a, b and c so that the equation a * b + c comes as closes to target as possible
  7.  *    
  8.  *     You will build a first, then build b and then build c
  9.  *
  10.  *     add the number n, 0 <= n <= 9, to any unoccupied place value in the String num.
  11.  *    
  12.  *     e.g., if the str = " 3 ", the build_a(str, 8) could return:    "83 " or " 38"
  13.  *     or    if the str = "  1  5", the build_a(str, 0) could return:
  14.  *                              "0 1 5", " 01 5" or "  105"
  15.  */
  16.  
  17. public class EquationSolver
  18. {
  19.     private int target;
  20.  
  21.     /*
  22.      *   you should keep a record of the values of a and b and c.
  23.      *  
  24.      *   I will let you figure out how you want to accomplish that task
  25.      *    
  26.      */    
  27.  
  28.     /* post condition
  29.      *   0 <= t <= 99,999
  30.      */
  31.     public EquationSolver(int t)
  32.     {
  33.         target = t;
  34.     }
  35.  
  36.     public String getName()
  37.     {
  38.         return "Michael Baik";
  39.     }
  40.    
  41.     /*
  42.      *    create term a of the equation a * b + c that is closes to target
  43.      *    
  44.      *    0 <= a <= 999
  45.      */
  46.     public String build_a(String str, int n)
  47.     {
  48.         int i = str.indexOf(" ");
  49.         return str.substring(0,i) + n + str.substring(i+1,3);
  50.     }
  51.  
  52.     /*
  53.      *    create term b of the equation a * b + c that is closes to target
  54.      *    
  55.      *    0 <= b <= 999
  56.      */
  57.     public String build_b(String str, int n)
  58.     {
  59.         int i = str.indexOf(" ");
  60.         return str.substring(0,i) + n + str.substring(i+1,3);
  61.     }
  62.  
  63.     /*
  64.      *    create term c of the equation a * b + c that is closes to target
  65.      *    
  66.      *    0 <= c <= 99999
  67.      */
  68.     public String build_c(String str, int n)
  69.     {
  70.         int i = str.indexOf(" ");
  71.         return str.substring(0,i) + n + str.substring(i+1,5);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement