public static void main(String[] args) {
    // read class name from command line args or user input
    String name;
    if (args.length > 0) name = args[0];
    else {
      Scanner in = new Scanner(System.in);
      System.out.println("Enter class name (e.g. java.util.Date): ");
      name = in.next();
    }

    try {
      // print class name and superclass name (if != Object)
      Class cl = Class.forName(name);
      Class supercl = cl.getSuperclass();
      String modifiers = Modifier.toString(cl.getModifiers());
      if (modifiers.length() > 0) System.out.print(modifiers + " ");
      System.out.print("class " + name);
      if (supercl != null && supercl != Object.class)
        System.out.print(" extends " + supercl.getName());

      System.out.print("\n{\n");
      printConstructors(cl);
      System.out.println();
      printMethods(cl);
      System.out.println();
      printFields(cl);
      System.out.println("}");
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    System.exit(0);
  }
Exemple #2
0
  public void remove() throws SQLException {
    Scanner sc = new Scanner(System.in);
    String id = sc.next();
    Dao<Account, String> accountDao = connect();

    accountDao.delete(accountDao.queryForId(id));
    System.out.println("Enter some string to continue");
    sc.next();
    connectionSource.close();
  }
Exemple #3
0
  public static void main(String[] args) throws Exception {
    AccountApp a = new AccountApp();
    Scanner sc = new Scanner(System.in);

    while (true) {
      System.out.println("1 - Write\n2 - Show\n3 - Remove");
      String stroka = sc.nextLine();
      if (a.select(stroka)) {
        System.out.println("Enter any key");
        sc.nextLine();
        continue;
      }
    }
  }
Exemple #4
0
  public void write() throws SQLException {
    Scanner sc = new Scanner(System.in);
    System.out.println("Text");
    String text = sc.nextLine();

    System.out.println("Prioritet");
    int prioritet = sc.nextInt();
    Account account = new Account();
    account.setText(text);
    account.setPrioritet(prioritet);
    Dao<Account, String> accountDao = connect();
    accountDao.create(account);
    System.out.println("Enter some string to continue");
    sc.next();
    connectionSource.close();
  }
Exemple #5
0
  void getInfo() {
    Scanner console = new Scanner(System.in);
    int maxCost = 0, maxSols = 0;
    Problem prob = null;
    Solver solve = null;
    ArrStack stk = new ArrStack();

    System.out.print("Enter problem type, solution type, " + "max cost and max # of solutions: ");
    try {
      prob = (Problem) Class.forName(console.next()).newInstance();
      solve = (Solver) Class.forName(console.next()).newInstance();
      maxCost = console.nextInt();
      maxSols = console.nextInt();
    } catch (Exception e) {
      System.out.println("" + e);
    }

    try {
      prob.read(console);
    } catch (Exception e) {
      System.out.println("Read error: " + e);
      return;
    }

    Solver.Solution[] sols;
    sols = solve.solveProblem(prob, maxCost, maxSols);
    if (sols == null) {
      System.out.println("No solutions ");
      return;
    }
    System.out.println("Answers are: ");
    for (int ans = 0; ans < sols.length && sols[ans] != null; ans++) {
      System.out.println("Answer " + ans + " with cost " + (sols[ans].mSteps.length - 1));
      for (int stepNdx = 1; stepNdx < sols[ans].mSteps.length; stepNdx++)
        System.out.println("   " + sols[ans].mSteps[stepNdx]);
    }
  }