Swing Calculator - Logical errors

Hello,
I have a couple of problems with the code below
one of them is with the setLayout().
Can anyone give a look to that code and tell me what's going wrong , or help me to make it work ??
Thanks in advance!
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.*;
public class Calculator extends JFrame implements ActionListener
    public static final int Width = 500;
    public static final int Height = 500;
    private JTextField Board;
    private JButton jbo0, jbo1, jbo2, jbo3, jbo4, jbo5, jbo6, jbo7, jbo8, jbo9,
                    jboAddition, jboSubtraction, jboMultiplication, jboDivision,
                    jboDot, jboLp, jboRp, jboClear, jboResult;
    public static void main(String args[])
    JFrame applet = new Calculator();
    JFrame frame = new JFrame();
    frame.add(frame);
    frame.setSize(Width,Height);
    frame.show();
public static void main(String args[])
    JFrame outputFrame = new Calculator();
//panel1.add(allyourstuff);
//panel1.add(moreofyourstuff);
    outputFrame.setVisible(true);
    public Calculator()
        Container outputPane = this.getContentPane();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(Width, Height);
        outputPane.setLayout(new GridLayout (3, 3));
        Panel panel1 = new Panel();
        this.setDefaultCloseOperation( EXIT_ON_CLOSE );
        Board = new JTextField();
        panel1.add(Board);
        outputPane.add(panel1);
        //panel1.add(jbo0);
        //Numbers
        setLayout(new FlowLayout());
        setFont(new Font("Helvetica", Font.PLAIN, 8));
        JButton jbo0 = new JButton("0");
        jbo0.addActionListener(this);
        panel1.add(jbo0);
        jbo1 = new JButton("1");
        panel1.add(jbo1);
        jbo1.addActionListener(this);
        jbo2 = new JButton("2");
        panel1.add(jbo2);
        jbo2.addActionListener(this);
        jbo3 = new JButton("3");
        panel1.add(jbo3);
        jbo3.addActionListener(this);
        jbo4 = new JButton("4");
        panel1.add(jbo4);
        jbo4.addActionListener(this);
        jbo5 = new JButton("5");
        panel1.add(jbo5);
        jbo5.addActionListener(this);
        jbo6 = new JButton("6");
        panel1.add(jbo6);
        jbo6.addActionListener(this);
        jbo7 = new JButton("7");
        panel1.add(jbo7);
        jbo7.addActionListener(this);
        jbo8 = new JButton("8");
        panel1.add(jbo8);
        jbo8.addActionListener(this);
        jbo9 = new JButton("9");
        panel1.add(jbo9);
        jbo9.addActionListener(this);
        //Math Operations
        jboAddition = new JButton("+");
        panel1.add(jboAddition);
        jboAddition.addActionListener(this);
        jboSubtraction = new JButton("-");
        panel1.add(jboSubtraction);
        jboSubtraction.addActionListener(this);
        jboMultiplication = new JButton("*");
        panel1.add(jboMultiplication);
        jboMultiplication.addActionListener(this);
        jboDivision = new JButton("/");
        panel1.add(jboDivision);
        jboDivision.addActionListener(this);
        //Result etc..
        jboDot = new JButton(".");
        panel1.add(jboDot);
        jboDot.addActionListener(this);
        jboLp = new JButton("(");
        panel1.add(jboLp);
        jboLp.addActionListener(this);
        jboRp = new JButton(")");
        panel1.add(jboRp);
        jboRp.addActionListener(this);
        jboClear = new JButton("C");
        panel1.add(jboClear);
        jboClear.addActionListener(this);
        jboResult = new JButton("=");
        panel1.add(jboResult);
        jboResult.addActionListener(this);
    public void actionPerformed(ActionEvent e)
        if (e.getSource() instanceof JButton)
            JButton buClicked = (JButton) e.getSource();
            if (buClicked == jboClear)
                boardClear();
            else if(buClicked == jboResult)
                Calculate();
        else
            Calculate();
    public void UserInput(JButton buClicked)
        String input;
        input = Board.getText();
        if (buClicked == jbo0)
            Board.setText(input + "0");
        if (buClicked == jbo1)
            Board.setText(input + "1");
        if (buClicked == jbo2)
            Board.setText(input + "2");
        if (buClicked == jbo3)
            Board.setText(input + "3");
        if (buClicked == jbo4)
            Board.setText(input + "4");
        if (buClicked == jbo5)
            Board.setText(input + "5");
        if (buClicked == jbo6)
            Board.setText(input + "6");
        if (buClicked == jbo7)
            Board.setText(input + "7");
        if (buClicked == jbo8)
            Board.setText(input + "8");
        if (buClicked == jbo9)
            Board.setText(input + "9");
        if (buClicked == jboAddition)
            Board.setText(input + "+");
        if (buClicked == jboSubtraction)
            Board.setText(input + "-");
        if (buClicked == jboMultiplication)
            Board.setText(input + "*");
        if (buClicked == jboDivision)
            Board.setText(input + "/");
        if (buClicked == jboDot)
            Board.setText(input + ".");
        if (buClicked == jboLp)
            Board.setText(input + "(");
        if (buClicked == jboRp)
            Board.setText(input + ")");
     private void boardClear()
        Board.setText("");
    public void Calculate()
        int counter;
        int numParenthesis = 0;
        int lenInput;
        String calc;
        String Answer = "";
        char NumOther;
        calc = Board.getText();
        lenInput = calc.length();
        for (counter = 0; counter < lenInput; counter++)
            NumOther = calc.charAt(counter);
            if (NumOther == ')')
                numParenthesis--;
            if (NumOther == '(')
                numParenthesis++;
            if ((NumOther < '(') || (NumOther > '9') || (NumOther == '.'))
                Board.setText("Error");
            if (NumOther == '.' && (counter + 1 < calc.length()))
                for (int k = counter + 1; (k < calc.length()) && ((Character.isDigit(calc.charAt(k))) || ((calc.charAt(k))) == '.'); k++)
                    if (calc.charAt(k) == '.')
                        Board.setText("Error");
        if (numParenthesis != 0)
            Board.setText("Error");
        else
            Answer = Calculate2(calc);
            Board.setText(Answer);
    private String CalculatorImp(String oper1, String oper2, char Oper)
        Double op1, op2;
        double ops1, ops2;
        double ans = 0;
        String result;
        op1 = new Double (oper1);
        op2 = new Double (oper2);
        ops1 = op1.doubleValue();
        ops2 = op2.doubleValue();
        if (Oper == '+')
            ans = ops1 + ops2;
        if (Oper == '-')
            ans = ops1 - ops2;
        if (Oper == '*')
            ans = ops1 * ops2 ;
        if (Oper == '/')
            ans = ops1/ops2;
        result = Double.toString(ans);
        return result;
    private String Calculate2(String process)
        String answer = process;
        String op1 = "";
        String op2 = "";
        char userinput;
        int index = 0;
        int indexL = 0;
        int indexR = 0;
        int numInput = answer.length();
        int numPar = 0;
        int matchPar = 0;
        int indexOp1 = 0;
        int indexOp2 = 0;
        if (answer  != "Error")
            for (index = 0; index < numInput; index++)
                userinput = answer.charAt(index);
                if (userinput  == '(')
                    if (matchPar == 0)
                        indexOp1 = index;
                    matchPar++;
                    numPar++;
                if (userinput == ')')
                    matchPar--;
                    if (matchPar ==0)
                        indexOp2 = index;
            if (indexOp1 + 1 == indexOp2)
                Board.setText("Error");
            if (answer == "Error"  && numPar > 0)
                if (indexOp1 == 0)
                    if (indexOp2 == (numInput - 1))
                        if (indexOp1 != indexOp2)
                            answer = Calculate2(answer.substring(indexOp1 + 1, indexOp2));
                else if (indexOp1 == 0 && indexOp2 > 0)
                    if ((Character.isDigit(answer.charAt(indexOp2 + 1))))
                        Board.setText("Error");
                    else
                        answer = Calculate2(answer.substring(indexOp1 + 1, indexOp2)) + answer.substring(indexOp2 + 1);
                        numPar--;
                        while (numPar != 0)
                            answer = Calculate2(answer);
                            numPar--;
                else if ((indexOp1 > 0) && (indexOp2 > 0) && (indexOp2 != numInput - 1))
                    if (((Character.isDigit(answer.charAt(indexOp2 + 1 ))) ||  (Character.isDigit(answer.charAt(indexOp1 - 1 ))) ))
                        Board.setText("Error");
                    else
                        answer = answer.substring(0, indexOp1) + Calculate2(answer.substring(indexOp1 + 1, indexOp2)) + answer.substring(indexOp2 + 1);
                        numPar--;
                        while (numPar != 0)
                            answer = Calculate2(answer);
                            numPar--;
                else if (indexOp2 == numInput - 1 && indexOp1 > 0)
                    if (((Character.isDigit(answer.charAt(indexOp1 - 1)))))
                        Board.setText("Error");
                    else
                        answer = answer.substring(0, indexOp1) + Calculate2(answer.substring(indexOp1 + 1, indexOp2));
                        numPar--;
                        while (numPar != 0)
                            answer = Calculate2(answer);
                            numPar--;
            if (numPar == 0)
                if (answer != "Error")
                    if (!(Character.isDigit(answer.charAt(0))))
                        if (answer.charAt(0) != '-')
                            if (!(Character.isDigit(answer.charAt(answer.length() - 1))))
                                Board.setText("Error");
            for (index = 0; index < answer.length() && (answer == "Error"); index++)
                userinput = answer.charAt(index);
                if (userinput == '*' || userinput == '/')
                    if (!(Character.isDigit(answer.charAt(index-1))) || (!(Character.isDigit(answer.charAt(index + 1)))))
                        if (answer.charAt(index + 1) != '-')
                            Board.setText("Error");
                    if (answer.charAt(index + 1) == '-')
                        if (!(Character.isDigit(answer.charAt(index + 2))))
                            Board.setText("Error");
                    if (answer == "Error")
                        indexL = index - 1;
                        if (indexL > 2)
                            if ((answer.charAt(indexL - 1)) == '-')
                                if ((answer.charAt(indexL - 2)) == 'E')
                                    indexL = indexL -2;
                            while ((indexL  > 0) && ((Character.isDigit(answer.charAt(indexL - 2)) || ((answer.charAt(indexL - 1)) == '.') || ((answer.charAt(indexL - 1)) == 'E' ))))
                                indexL--;
                            if (indexL == 1)
                                if ((answer.charAt(indexL - 1)) == '-')
                                    indexL--;
                            if (indexL > 2)
                                if (((answer.charAt(indexL - 1)) == '-') && !(Character.isDigit(answer.charAt(indexL - 2))))
                                        indexL--;
                            op2 = answer.substring(index + 1, indexR + 1);
                for (index = 0; index < answer.length() && (answer != "Error"); index++)
                    if (index == 0)
                        index = 1;
                if (index > 0)
                        if (answer.charAt(index + 1) == '-')
                            index = index + 2;
                userinput = answer.charAt(index);
                if ((userinput == '+') || (userinput == '-'))
                    if (!(Character.isDigit(answer.charAt(index - 1))))
                        Board.setText("Error");
                    if (!(Character.isDigit(answer.charAt(index + 1))))
                        Board.setText("Error");
                    if ((answer.charAt(index+1) == '-') && (!(Character.isDigit(answer.charAt(index+2)))))
                         Board.setText("Error");
                    if (answer != "Error")
                        indexL = 0;
                        op1 = answer.substring(indexL , index);
                        indexR = index + 1;
                        while((indexR < answer.length()-1) && ((Character.isDigit(answer.charAt(indexR + 1))) || ((answer.charAt(indexR + 1)) == '.') || ((answer.charAt(indexR + 1)) == 'E')))
                            indexR++;
                            if (indexR < answer.length() - 2)
                                    if ((answer.charAt(indexR + 1)) == '-')
                                        indexR++;
                        op2 = answer.substring(index + 1, indexR + 1);
                        answer = CalculatorImp(op1, op2, userinput ) + answer.substring(indexR + 1);
                        index = 0;
        return answer;
}

Your UserInput method doesn't seem to get called anywhere.
You need to sort out the layout - try a vertical box containing the input and horizontal boxes for the button, or a simple grid. If using a GridLayout, the number of rows and column you give in the constructor should
Move the actual calculation code out into a separate class - you then can test it more easily with a driver which feeds it lots of expressions, and your UI code isn't all mixed up with it.
It's a convention to use lower case initial letters on variable and method names.
Your code is very redundant - create one ActionListener which you attach to each your single character button to append the value of that button to the input box, rather than having all those tests, and extract that code into a single method.
When you add a swing component to another, it keeps a reference to it so it can draw it. You don't need to, unless you want to do something else which it later on.
Eg:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingCalculator extends JFrame {
  public static void main(String args[]) {
    new SwingCalculator().setVisible(true);
  final JTextField board;
  public SwingCalculator () {
    Container outputPane = this.getContentPane();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setFont(new Font("Helvetica", Font.PLAIN, 18));
    setTitle("SwingCalculator");
    outputPane.setLayout(new BoxLayout(outputPane, BoxLayout.Y_AXIS));
    board = new JTextField();
    outputPane.add(board);
    final JPanel buttons = new JPanel();
    buttons.setLayout(new GridLayout (5, 4));
    outputPane.add(buttons);
    // Buttons which append to the board
    addButtons(buttons, "7", "8", "9", "+");
    addButtons(buttons, "4", "5", "6", "-");
    addButtons(buttons, "1", "2", "3", "*");
    addButtons(buttons, ".", "0", "E", "/");
    addButtons(buttons, "(", ")");
    // the C and = buttons have special action listeners
    final JButton cancel = new JButton("C");
    buttons.add(cancel);
    cancel.addActionListener(new ActionListener() {
      public void actionPerformed (ActionEvent event) {
        board.setText("");
    final JButton calculate = new JButton("=");
    buttons.add(calculate);
    // move the expression code to a separate class and call it here
    calculate.addActionListener(new ActionListener() {
      public void actionPerformed (ActionEvent event) {
        try {
          board.setText(ExpressionParser.evaluate(board.getText()));
        } catch (ExpressionParseException ex) {
          board.setText("ERROR");
    pack();
  // adds buttons which, when pressed, append their label to the board
  public void addButtons (JPanel panel, String... labels) {
    for (final String label:labels) {
      JButton button = new JButton(label);
      panel.add(button);
      button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          board.setText(board.getText() + label);
}

Similar Messages

  • Bracketed expression calculator logical error

    Hi,
    i've being working on a calculator which can handle expressions such as
    5 + 6 * 2 which results in 17 (so far only works well for this expression)
    (5 + 4) * (4 - 2) which results in 18
    (4 + (2 * (2 - 1))) * 1.2 results in 4.8
    given an input of an expression at command line for instance
    (6+3)*(5-1)
    my program would evaluate this expression using the following code( various print statement to that i was using to help me see what exactly was going on):
    fields within this class are:
    private Stack<String> expression = new Stack<String>();
    private Double x;
    private Stack<String> temphold = new Stack<String>();
    private String b = "";
    private String f;
    userEntry.trim();
                String[] temp = userEntry.split("[()]");
                for (int i = 0 ; i < temp.length ; i++) {
                    String a = temp;
    System.out.println(a);
    dump(temp);
    if(userEntry.startsWith("end")) {
    finished = true;
    System.out.println("Thank You for using Calculator");
    * dump. Places the input into a char array and push each
    * char to stack.
    * @param temp array of strings to be tokenized and
    * pushed ontop of stack.
    private void dump(String[] temp)
    for (int i = 0 ; i < temp.length ; i++) {
    String a = temp[i];
    final char[] chars = a.toCharArray();
    for(char c : chars) {
    Character C = new Character(c);
    String token;
    token = C.toString(); ......
           while (expression.size() >= 2) {
    String X = new String();
    String Y = new String();
    X = expression.pop();
    //System.out.println("Test2 "+X);
    if (X.equals("+")) {
    Y = expression.pop();
    double y = Double.parseDouble(Y);
    System.out.println(y+"to add");
    System.out.println(x+"to add");
    String result = Double.toString(Operation.PLUS.eval(x,y));
    System.out.println("Addition result"+result);
    output(result,expression);
    System.out.println(expression.peek());
    else if (X.equals("-")) {
    Y = expression.pop();
    double y = Double.parseDouble(Y);
    System.out.println(y+"to minus");
    System.out.println(x+"to minus");
    String result = Double.toString(Operation.MINUS.eval(y,x));
    System.out.println("subtraction result"+result);
    output(result,expression);
    System.out.println(expression.peek());
    else if (X.equals("/")) {
    Y = expression.pop();
    double y = Double.parseDouble(Y);
    String result = Double.toString(Operation.DIVIDE.eval(y,x));
    output(result,expression);
    else if (X.equals("*")) {
    Y = expression.pop();
    double y = Double.parseDouble(Y);
    System.out.println(y+ "to multiply");
    System.out.println(x+"to mutliply");
    String result = Double.toString(Operation.TIMES.eval(x,y));
    output(result,expression);
    else {
    try { x = Double.parseDouble(X); }
    catch (NumberFormatException e) {
    System.out.println("Unrecongizned Expresssion"); }
    System.out.println("Answer: "+expression.peek());
    System.out.println("expression size after all calculations: "+expression.size());
    System.out.println();
    expression.clear();
    Expressions restart = new Expressions();
    private void output(String ans,Stack<String> stack)
    stack.push(ans);
    } the out put of the program after carry out the coding body is:
    (6+3)*(5-3)
    6+3
    5-3
    Testing token 6
    Testing token +
    Testing token 3
    Testing token *
    Testing token 5
    Testing token -
    Testing token 3
    5.0to minus
    3.0to minus
    subtraction result2.0
    2.0
    3.0to multiply
    2.0to mutliply
    6.0to add
    6.0to add
    Addition result12.0
    12.0
    Answer: 12.0
    expression size after all calculations: 1
    As you can see from from the output, the multiplication gets excuted at a wrong time and using the wrong operands. Any ideas/input into how i can over come this problem and improve the structure of this class  would be so helpful as am i pretty much stuck without scraping this implement and taking on a different approach.
    If anythings needs explain or adding to feel free to say though i am not entirely convinced with code :|.
    THANKS ALOT!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    newark wrote:
    It'd be nice to see what class(es) the code you posted belongs to, as well as how they get called. Much easier to trace calls when you can see them being made.
    Oh, and what code is printing this?
    6+3
    5-3
    Testing token 6
    Testing token +
    Testing token 3
    Testing token *
    Testing token 5
    Testing token -
    Testing token 3i have the following classes
    Operators$Operation$4.class
    Operators.java
    Operators$Operation$1.class
    Operators$Operation$3.class
    Operators$1.class
    Operators.class
    Calculator.java
    Expressions.class
    Operators$Operation$2.class
    Calculator.class
    Expressions.java
    Operators$Operation.class
    The Calculator simply display a greeting message and creates an instantiated of the Expression class, this Expression class implements all the before code i posted and is a child of the Operators class .
    abstract class Operators
        /** Creates a new instance of Operators */
        public Operators()
         * enum types to spefcifc te equation to be calcuated and returned.
         * overridden at call with the speific equation to be carried out.
        public enum Operation
            PLUS   {  @Override
                    double eval(double x, double y) { return x + y; } },
            MINUS  {  @Override
                    double eval(double x, double y) { return x - y; } },
            TIMES  {  @Override
                    double eval(double x, double y) { return x * y; } },
            DIVIDE {  @Override
                    double eval(double x, double y) { return x / y; } };
            /** Do arithmetic op represented by this constant */
            abstract double eval(double x, double y);
        }taken from the code from my first post the below code prints:
    6+3
    5-3
    userEntry.trim();
                String[] temp = userEntry.split("[()]");
                for (int i = 0 ; i < temp.length ; i++) {
                    String a = temp;
    System.out.println(a);
    }taken from the code from my first post the below code prints:
    Testing token 6
    Testing token +
    Testing token 3
    Testing token *
    Testing token 5
    Testing token -
    Testing token 3private void dump(String[] temp)
    for (int i = 0 ; i < temp.length ; i++) {
    String a = temp[i];
    final char[] chars = a.toCharArray();
    for(char c : chars) {
    Character C = new Character(c);
    String token;
    token = C.toString();
    System.out.println("Testing token "+token);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • JFrames + Returning a Variable... Beginner's Logical Error

    Hi,
    I'm new to Java and programming in general. I'm trying to do something that seems pretty simple, but I'm making a logical error that is preventing my little program from working.
    All I'm trying to do is this... I've created a little JFrame that asks a user for a university's name, address, and the number of students in the university. All of this is within a class called InputWindowSmall. I just want to be able to return those Strings, univName, univAdress, univStudents, to my main program so I can put them into a different class.
    I've tried get methods, but that's silly, it doesn't work, it returns null because the program doesn't wait for the user's input.
    Does anyone have any suggestions?
    Also... I'm a terribly poor Object-Oriented-Thinker... If I'm doing anything that doesn't make sense in an Object-Oriented-Mindset, please point it out! I'd like to try and get better! Thanks!
    CODE
    InputWindowSmall
    package FinalProject;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import java.awt.GridLayout;
    import javax.swing.JTextField;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JButton;
    /** Class Definition: Input Window - small input window that asks for University name and address*/
    public class InputWindowSmall extends JFrame
         private JLabel nameLabel;
         private JLabel addressLabel;
         private JLabel numberStudentsLabel;
         private JLabel whiteSpace;
         private JTextField nameField;
         private JTextField addressField;
         private JTextField numberStudentsField;
         private JButton okButton;
         private String univName;
         private String univAddress;
         private String univStudents;
         /** Constructor with extra parameters     */
         public InputWindowSmall(University univ)
              //Names title bar of window
              super("Welcome!");
              //Sets layout of window
              setLayout(new GridLayout(4,2));
              //Sets text for nameLabel and adds to window
              JLabel nameLabel = new JLabel("    University Name: ");
              add(nameLabel);
              //Sets and adds nameField to window
              nameField = new JTextField(10);
              add(nameField);
              //Sets text for addressLabel and adds to window
              JLabel addressLabel = new JLabel("    University Address: ");
              add(addressLabel);
              //Sets and adds addressField to window
              addressField = new JTextField(10);
              add(addressField);
              //Sets text for numberStudentsLabel and adds to window
              JLabel numberStudentsLabel = new JLabel("    Number of Students: ");
              add(numberStudentsLabel);
              //Sets and adds numberStudentsField to window
              numberStudentsField = new JTextField(10);
              add(numberStudentsField);
              //Sets and adds white space
              JLabel whiteSpace = new JLabel("         ");
              add(whiteSpace);
              //Sets and adds button
              okButton = new JButton("OK");
              add(okButton);
              //create new ButtonHandler for button event handling
              ButtonHandlerSmall handler = new ButtonHandlerSmall();
              okButton.addActionListener(handler);
         }//end InputWindowSmall
         private class ButtonHandlerSmall implements ActionListener
              public void actionPerformed(ActionEvent event)
                   String univName = nameField.getText();
                   String univAddress = addressField.getText();
                   String univStudents = numberStudentsField.getText();
              }//end actionPerformed
         }//end ButtonHandlerSmall
         public String getUniversityName()
              return univName;
         }//end getUniversityName
         public String getUniversityAddress()
              return univAddress;
         public String getUniversityNumberStudents()
              return univStudents;
    }//ProjectTest (contains main)
    /** Class Definition: ProjectTest - contains main*/
    package FinalProject;
    import javax.swing.JFrame;
    public class ProjectTest {
         public static void main(String args[])
              //Creates a new university
              University univ = new University();
              //Instantiates and sets up the initial small window which asks for university name, address, and # students
              InputWindowSmall inputWindowSmall = new InputWindowSmall(univ);
              inputWindowSmall.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              inputWindowSmall.setSize(350, 120);
              inputWindowSmall.setVisible(true);
              inputWindowSmall.setLocationRelativeTo(null);
              String univN = inputWindowSmall.getUniversityName();
              String univA = inputWindowSmall.getUniversityAddress();
              String univS = inputWindowSmall.getUniversityNumberStudents();
              System.out.println(univN);
              System.out.println(univA);
              System.out.println(univS);
         }//end main
    }Edited by: heathercmiller on Apr 28, 2008 5:57 AM
    Edited by: heathercmiller on Apr 28, 2008 5:58 AM

    Oh! ...Here is a somewhat important detail I forgot to mention...
    There's another class called University (I've included it below). The main part of the program instantiates an object of type University, and that object is passed to the InputWindowSmall class. In the end, I want those variables I mentioned above to be placed within the University object I created. ...And I've already passed a University object to InputWindowSmall... I'm just not entirely sure how to assign values to the variables within the University object while in a different class. ...Does that make any sense?
    University
    package FinalProject;
    import java.util.Arrays;
    /** Class Definition: University*/
    public class University extends ProjectTest implements TuitionGenerate 
         private String universityName;     /** refers to the name of the University     */
         private String address;               /** refers to the address of the University     */
         private Student studentList[];     /** an array of Student objects                    */
         /** Default Constructor */
         University()
              setuniversityName("University_of_Miami");
              setaddress("555_Coral_Gables_St.");               
         /** Constructor with parameters */
         University(String name,String add)
              setuniversityName(name);
              setaddress(add);
         /** Constructor with extra parameters */
         University(String name,String add, Student array[])
              setuniversityName(name);
              setaddress(add);
              setstudentList(array);
         /** method: gets universityName*/
         public String getuniversityName()
              return universityName;
         /** method: gets address*/
         public String getaddress()
              return address;
         /** method: gets studentList*/
         public Student[] getstudentList()
              return studentList;
         /** method: sets universityName*/
         public void setuniversityName(String name)
              universityName=name;
         /** method: sets address*/
         public void setaddress(String add)
              address=add;
         /** method: sets studentList*/
         public void setstudentList(Student array[])
              studentList=new Student[array.length];
              studentList=array;
         /** method: returns a string representation of universityName and address*/
         public String toString()
              String output="University Name: " + universityName + "\nAddress: " + address + "\n\n";
              return output;
         /** method: sorts the array of students alphbetically by last name*/
         public void studentSort()
              String temp[]=new String[studentList.length];
              for(int i=0;i<studentList.length;i++)
                   temp=studentList[i].getlastName();
              Arrays.sort(temp);
              Student temp2[]=new Student[studentList.length];
              for(int i=0;i<temp.length;i++)
                   for(int j=0;j<studentList.length;j++)
                        if(temp[i].equals(studentList[j].getlastName()))
                             temp2[i]=studentList[j];
                             break;
              studentList=temp2;               
         /** method: prints the list of students*/
         public void printStudentList()
              System.out.println("Students:\n");
              for(int i=0;i<studentList.length;i++)
                   System.out.println(studentList[i].toString());
         /** method: prints tuition from interface GenerateTuition*/
         public void printTuition()
              for(int i=0;i<studentList.length;i++)
                   System.out.println(studentList[i].toString());
                   System.out.println(" Tuition: $" + studentList[i].calTuition() + "0");
         /** method: gets tuition from calTuition method*/
         public double getTuition(Student x)
                   return x.calTuition();
    Edited by: heathercmiller on Apr 28, 2008 6:07 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Logical error in the query

    create table my_employee
    (id number(4)primary key,
    last_name varchar2(25),
    first_name varchar2(25),
    userid varchar2(8),
    salary number(9,2)
    I want to write an INSERT statement to MY_EMPLOYEE table . Concatenate the first letter of the first name and first seven characters of the last name to produce user ID using a single sql statement
    I wrote the query like this and i am getting logical error
    insert into my_employee
    values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SQL> insert into my_employee
    2 values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&sal
    ary);
    Enter value for id: 20
    Enter value for last_name: popopopp
    Enter value for last_name: qwertyyuu
    Enter value for salary: 300000
    old 2: values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),
    new 2: values(20,'popopopp','o',substr('o',1,1)||substr('qwertyyuu',1,7),300000)
    1 row created.
    it is asking the last_name two times

    you can do it with a .sql script
    c:\my_emp.sql
    PROMPT
    PROMPT instering my_employees
    PROMPT
    ACCEPT ID NUMBER PROMPT 'ID ? : '
    ACCEPT FIRST_NAME CHAR PROMPT 'FIRST_NAME ?: '
    ACCEPT LAST_NAME CHAR PROMPT 'LAST_NAME ?: '
    ACCEPT SALARY NUMBER PROMPT 'SALARY ? : '
    insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SELECT * FROM my_employee where id=&&id;
    and then from sqlplus @c:\my_emp.sql
    scott@ORCL> @C:\MY_EMP
    instering my_employees
    ID ? : 20
    FIRST_NAME ?: john
    LAST_NAME ?: papas
    SALARY ? : 1000
    old 1: insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary)
    new 1: insert into my_employee values( 20,'papas','john',substr('john',1,1)||substr('papas',1,7), 1000)
    1 row created.
    old 1: SELECT * FROM my_employee where id=&&id
    new 1: SELECT * FROM my_employee where id= 20
    ID LAST_NAME FIRST_NAME USERID SALARY
    20 papas john jpapas 1000
    scott@ORCL>

  • Moving average price calculation logic of material with Price Control "S"

    Dear Gurus,
    As you know that there is a Moving price and standard price icon in the material master.
    I want to understand the calculation logic of the moving average price of the materials having price control "S"
    How the system calculates the MAP for standard price materials? The receipt from the process order I suppose is valuated at the process order cost after settlement, but if the issue has hapened for the material does the system recalculate the issue price also?
    Below is the sample process order receipt and issue scenario:
    Receipt from process order 161000000223
    300 kg and GR at standard cost value is Rs 5892
    Issue to process order 162000000294
    250 kg and GI at standard cost value is Rs 4910.
    Thus the balance at period end is 50 kg and balance at standard cost value is Rs 982.
    Here in process order 161000000223 the actual cost is 10 Rs. Then how will the system calculate the MAP?
    Thanking You,
    Amit Dhanurdhari

    Hi
    Try the following calculations,
    One of them will work depending upon your version and support pack
    Expected MAP calculation ( As with price control V)
    = ((Qty before transaction*MAP + Transaction Qty * transaction
    Price)) / quantity after transaction
    New Method ( when price control is S)
    = Old MAP + (Price Variance w.r.t Standard Price/Qty after transaction)
    Also go through the following notes,
    Note 1225167
    1253944
    518485 FAQ: Valuation of goods movements
    212286 Overview note: Valuation during goods movements
    209864 Moving average price is disproportionately large
    202166 Collective note: Statistical moving average price
    185961 Moving Average Price Calculation
    I have done extensive research on this, let me know if you need to know something specific.

  • ABAP LOGICAL ERRORS

    Expalin about ABAP Logical errors?
    Help me sending appropriate link to understand more.
    Moderator Message: Read the Rules of Engagement of this forum.
    Edited by: kishan P on Dec 27, 2011 9:50 PM

    Hi Vinay,
         You can't delete the ABAP Runtime errors. But  you can catch the errors using catch exception Statement.
    For Example,
    Class-based exceptions are handled in the following control structure:
    TRY.
      ...                       " TRY block (application coding)
    CATCH cx_... cx_... ...
        ...                     " CATCH block (exception handler)
    CATCH cx_... cx_... ...
        ...                     " CATCH block (exception handler)
      CLEANUP.
        ...                     " CLEANUP block (cleanup context)
    ENDTRY.
    Try This Sample Code,
    *--EXAMPLE FOR RUNTIME ERROR--
    *DATA : VALUE1 TYPE I.
    *VALUE1 = 1 / 0.        -
    >>>>>> IT MAKES RUN TIME ERROR.
    *WRITE : VALUE1.
    *-EXAMPLE FOR HOW TO CATCH THE ARITHMETIC ERROR AT THE RUN TIME USING SUBRC----
    DATA : VALUE1 TYPE I.
    CATCH SYSTEM-EXCEPTIONS ARITHMETIC_ERRORS = 1.
    VALUE1 = 1 / 0.
    WRITE : VALUE1.
    ENDCATCH.
    IF SY-SUBRC = 1.
    WRITE : ' IT MAKES ERROR'.
    ELSE.
    WRITE : VALUE1.
    ENDIF.
    Thanks,
    Reward If Helpful.

  • Logical Error in Script Logic

    Hello Experts,
    Please provide your guidance for the following scenario.
    I need to calculate the 'Accumulated Depreciation' for every month, based on the amounts in the 'AccumDep' and the 'Depreciation' accounts.
    In other words, the value of the Accumulated Depreciation for the month of Feb should be equal to (Accumulated Depreciation in Jan + Depreciation in Jan), and so on.
    To accomplish this, I have written the following script logic.
    *WHEN ACCOUNT
    *IS AccumDep, Depreciation
         *FOR %MON% = 2009.FEB,2009.MAR,2009.APR
              *REC(FACTOR=1, ACCOUNT=AccumDep, TIME=%MON%)
         *NEXT
    *ENDWHEN
    *COMMIT
    The above logic was validated without any 'syntax' errors.  However, I do not see the desired results, as the Accumulated Depreciation is not getting updated every month.  The amount from FEB appears for MAR & APR also.
    Therefore, could you please review the above script and let me know if there are any 'logical' errors?
    All your guidance is greatly appreciated.  Thanks...

    Hi,
    You are not getting the desired result because you are trying to aggregate the depreciation and the accumulated depreciation of the same month and post the result again in the same month. Lets say the code is working for 2009.MAR. You are trying to add the depreciation and accumulated depreciation of 2009.MAR. However, you still dont have the acc depreciation of 2009.MAR. You basically need to take the acc depreciation of the previous month.
    You can try something like:
    *WHEN ACCOUNT
    *IS Depreciation
         *FOR %MON% = 2009.FEB,2009.MAR,2009.APR
              *REC(EXPRESSION = %VALUE% + ([ACCOUNT].[AccumDep],[TIME].Previous), ACCOUNT=AccumDep)
         *NEXT
    *ENDWHEN
    *COMMIT
    You can have a property called Previous to store the previous month of each period in the time dimension.
    Hope you got the idea.

  • Newbie - JSP & bean shopping cart logic error?

    Hello,
    I am attempting to bulid a shopping cart facility on a JSP site that I am building.
    I am having difficulties adding an item to the basket.
    The page below (bookDetail.jsp) displays items for sale from a database. At the foot of the page, I have set up a hyperlink to add an item to a basket bean instance created in this page.
    What happens is the page will load correctly, when i hover the mouse over the hyperlink to add the item to the basket, the status bar shows the URL of the current page with the details of the book appended. This is what I want. But when I click the link, the page will only reload showing 20% of the content.
    Netbeans throws up no errors, neither does Tomcat, so I am assuming I have made a logical error somewhere.
    I have enclosed the Book class, and the ShoppingCart class for your reference.
    Any help would be really appreciated as I am at a loss here.
    Cheers.
    Edited highlights from bookDetail.jsp
    //page header importing 2 classes - Book and ShoppingCart
    <%@ page import="java.util.*, java.sql.*, com.shopengine.Book, com.shopengine.ShoppingCart" errorPage="errorpage.jsp" %>
    //declare variables to store data retrieved from database
    String rs_BookDetail_bookRef = null;
    String rs_BookDetail_bookTitle = null;
    String rs_BookDetail_author = null;
    String rs_BookDetail_price = null;
    //code that retrieves recordset data, displays it, and places it in variables shown above
    <%=(((rs_BookDetail_bookRef = rs_BookDetail.getString("book_ref"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_bookRef)%>
    <%=(((rs_BookDetail_author = rs_BookDetail.getString("author"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_author)%>
    <%=(((rs_BookDetail_bookTitle = rs_BookDetail.getString("book_title"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_bookTitle)%>
    <%=(((rs_BookDetail_price = rs_BookDetail.getString("price"))==null || rs_BookDetail.wasNull())?"":rs_BookDetail_price)%>
    //this link is to THIS PAGE to send data to server as request parameters in Key/Value pairs
    // this facilitates the add to basket function
    <a href="<%= response.encodeURL(bookDetail.jsp?title=
    "+rs_BookDetail_bookTitle+"
    &item_id=
    "+rs_BookDetail_bookRef +"
    &author="+rs_BookDetail_author +"
    &price=
    "+rs_BookDetail_price) %> ">
    <img src="images\addtobasket.gif" border="0" alt="Add To Basket"></a></td>
    // use a bean instance to store basket items
    <jsp:useBean id="basket" class="ShoppingCart" scope="session"/>
    <% String title = request.getParameter("title");
    if(title!=null)
    String item_id = request.getParameter("item_id");
    double price = Double.parseDouble(request.getParameter("price"));
    Book item = new Book(item_id, title, author, price);
    basket.addToBasket( item );
    %>
    ShoppingCart class that is used as a bean in bookDetail.jsp shown above
    package com.shopengine;
    //import packages
    import java.util.*;
    //does not declare explicit constructor which automatically creates a zero argument constructor
    //as this class will be instantiated as a bean
    public class ShoppingCart
    //using private instance variables as per JavaBean api
         private Vector basket;
         public ShoppingCart()
              basket = new Vector();
         }//close constructor
    //add object to vector
         public void addToBasket (Book book)
              basket.addElement(book);
         }//close addToBasket method
    //if strings are equal, delete object from vector
         public void deleteFromBasket (String foo)
    for(Enumeration enum = getBasketContents();
    enum.hasMoreElements();)
    //enumerate elements in vector
    Book item = (Book)enum.nextElement();
    //if BookRef is equal to Ref of item for deletion
    //then delete object from vector.
    if (item.getBookRef().equals(foo))
    basket.removeElement(item);
    break;
    }//close if statement
    }//close for loop
         }//close deleteFromBasket method
    //overwrite vector with new empty vector for next customer
         public void emptyBasket()
    basket = new Vector();
         }//close emptyBasket method
         //return size of vector to show how many items it contains
    public int getSizeOfBasket()
    return basket.size();
         }//close getSizeOfBasket method
    //return objects stored in Vector
         public Enumeration getBasketContents()
    return basket.elements();
         }//close getBasketContents method
         public double getTotalPrice()
    //collect book objects using getBasketContents method
    Enumeration enum = getBasketContents();
    //instantiate variable to accrue billng total for each enummeration
    double totalBillAmount;
    //instantiate object to store data for each enummeration
    Book item;
    //create a loop to add up the total cost of items in basket
    for (totalBillAmount=0.0D; enum.hasMoreElements(); totalBillAmount += item.getPrice())
    item = (Book)enum.nextElement();
    }//close for loop
    return totalBillAmount;
         }//close getTotalPrice method
    }//close shopping cart class
    Book Class that is used as an object model for items stored in basket
    package com.shopengine;
    import java.util.*;
    public class Book{
         //define variables
    private String bookRef, bookTitle, author;
         private double price;
    //define class
    public Book(String bookRef, String bookTitle, String author, double price)
    this.bookRef= bookRef;
    this.bookTitle=bookTitle;
    this.author=author;
    this.price=price;
    //create accessor methods
         public String getBookRef()
              return this.bookRef;
         public String getBookTitle()
              return this.bookTitle;
         public String getAuthor()
              return this.author;
         public double getPrice()
              return this.price;
    }//close class

    page will only reload showing 20% of the content.Im building some carts too and I had a similiar problem getting null values from the mysql database. Are you getting null values or are they just not showing up or what?
    On one of the carts I'm building I have a similiar class to yours called products that I cast onto a hashmap works alot better. Mine looks like this, maybe this is no help I don't know.......
    public class Product {
        /**An Item that is for sale.*/
          private String productID = "Missing";
          private String categoryID = "Missing";
          private String modelNumber = "Missing";
          private String modelName = "Missing";
          private String productImage = "Missing";
          private double unitCost;
          private String description = "Missing";
          public Product( 
                           String productID,
                           String categoryID,
                           String modelNumber,
                           String modelName,
                           String productImage,
                           double unitCost,
                           String description) {
                           setProductID(productID);
                           setCategoryID(categoryID);
                           setModelNumber(modelNumber);
                           setModelName(modelName);
                           setProductImage(productImage);
                           setUnitCost(unitCost);
                           setDescription(description);        
          public String getProductID(){
             return(productID);
          private void setProductID(String productID){
             this.productID = productID;
          public String getCategoryID(){
             return(categoryID);
          private void setCategoryID(String categoryID){
             this.categoryID = categoryID;
          public String getModelNumber(){
             return(modelNumber);
          private void setModelNumber(String modelNumber){
             this.modelNumber = modelNumber;
          public String getModelName(){
             return(modelName);
          private void setModelName(String modelName){
             this.modelName = modelName;
          public String getProductImage(){
             return(productImage);
          private void setProductImage(String productImage){
             this.productImage = productImage;
          public double getUnitCost(){
              return(unitCost);
          private void setUnitCost(double unitCost){
              this.unitCost = unitCost;
          public String getDescription(){
              return(description);
          private void setDescription(String description){
              this.description = description;

  • Identifying syntax and logical errors

    Hey guys,
    I'm new to java and I can't figure out this problem as I can't make JDK work with comand prompt for some reason and when trying to write the java in a web page it won't work.
    Can anyone tell me what the three syntax errors and one logical error in the following code is?
    public class Add
    public static void main(String[] args)
    double weight1 = 85.5
    double weight2 = 92.3
    double averWeight = weight1 + weight2 / 2;
    System.out.println("Average is " + aver);
    Any help would be very much appreciated.

    Ok. I'm new to Java. Thanks to the both of you for your help.You're welcome of course; here's a tip: type in these little exercises
    and try to compile them; carefully read what the compiler has to say
    about the possible errors. Note that the compiler is totally blind to
    most "logical errors".
    kind regards,
    Jos

  • Too many logical errors (in terms of business processes); maximum was 100

    hi friends !
    I'm using the direct input program RMDATIND for uploading the material master data. and i'm facing the error:
    "Too many logical errors (in terms of business processes); maximum was 100"
    thanks and regards,
    sachin soni

    Hi,
    If you checked in standard program,problem is occuring in the function module
    'MATERIAL_MAINTAIN_DARK'.

  • Logic error in a class I wrote...help

    I wrote this class to filter a simplified version of Military time; basically it
    returns a true or false statement to whether a specified string contains
    the appropriate character sequence. My problem is that it seems to
    report false even if my time format is correct.
    example:
    correct time: "0700"
    incorrect time: "700" or invlalid characters "asdf "
    maybe you all could catch me logic error...my head is bust
    class SimpleMilitaryTime
         //Verify that their are only 4 characters in the string
         public boolean verifyLength(String time)
              int textFieldLength;
              boolean flag = true;
              textFieldLength = time.length();
              if (textFieldLength == 4)
                   flag = true;
              else
                   flag = false;
              return flag;
         }//end verify length
         //Method for comparing characters that can be used
         public boolean verifyNumerals( String time )
              boolean flag = true;
              int flagCounter = 0;
              char theChar;
    //testing characters to see if they match or dont
    //match the below lists of char numerals
    //If they don't, the flagcounter is increased by 
    //one and the flag is returned as false
    //because the flagcounter is greater than 0 
    //indicating that they are not all numerals but
    //some other sort of character
              for (int i = 0; i <= time.length(); i++)
                     theChar = (char)time.indexOf(i);
                   switch (theChar)
                        case '0':
                             break;
                        case '1':
                             break;
                        case '2':
                             break;
                        case '3':
                             break;
                        case '4':
                             break;
                        case '5':
                             break;
                        case '6':
                             break;
                        case '7':
                             break;
                        case '8':
                             break;
                        case '9':
                             break;
                        default:
                              flagCounter = flagCounter + 1;
                   }//end of switch
              }//end of for loop
              if (flagCounter < 0 )
                   flag = true;
              else
                   flag = false;
              return flag;
         }//End of Method
         //Method to determine numeral format
         public boolean verifyFormat( String time )
              boolean flag = true;
              boolean hrFlag = true;
              boolean minFlag = true;
              String hr, min;
              hr = time.substring(0, 1);
              min = time.substring(2, 3);
              hrFlag = verifyHrRange( hr );
              //return true if its in the hour range of 0 to 23
              minFlag = verifyMinRange( min );     
                                              //return true if its in the minutes range of 0 to 59
              //If hrFlag or minFlag is false then format does
                                               //not meet the Military Time Format
              if (hrFlag == false || minFlag == false)
                   flag = false;
              else
                   flag = true;
         return flag;
         }//end of Method
         //Verify the Range of Hr  between 0 and 23
         public boolean verifyHrRange( String hr )
              int hrTime;
              boolean flag = true;
              hrTime = Integer.parseInt( hr );
              if ( hrTime >= 0 && hrTime <= 23 )
                   flag = true;
              else
                   flag = false;
         return flag;
         }//End of Method
         //Verify the Range of Minutes  between 0 and 59
         public boolean verifyMinRange( String min )
              int minTime;
              boolean flag = true;
              minTime = Integer.parseInt( min );
              if ( minTime >= 0 && minTime <= 59 )
                   flag = true;
              else
                   flag = false;
         return flag;
         }//End of Method
         //Method validates total time content
         public boolean validateTime( String time )
              boolean flag = true;
              boolean flagLength = true;
              boolean flagNumerals = true;          
              boolean flagFormat = true;          
              flagLength = verifyLength( time );                         //Is the length  == to 4 characters long
              if( flagLength == true )
                   flagNumerals = verifyNumerals( time );               //Is the content made up of numerals
                   if( flagNumerals == true )
                        flagFormat = verifyFormat( time );               //Is the format within MilitaryTime Specs
                        if( flagFormat == true )
                             flag = true;
                        else
                             flag = false;                                             //IF one or all are FALSE then FLAG is set to false
                   else
                        flag = false;
              else
                   flag = false;
              //return status of test run
              return flag;               
         }//End of Method
    }//End of Class

    Interestingly enough, although both examples simplify the logic, I still
    recieve a "false" when testing it. Here is some more code that I use
    when a text field has lost focus. Right now the code is set to just test
    the input.
    The field is inialized to "1234". Once the field gains focus, it immediately sets to "false"...not sure why.?.? Even after resetting field
    to another 4 digit numeral sequence I still get a "false" return instead of
    verifying it as "true. " any ideas?
    here is the code for testing the MilitaryTime class:
    private class TextFieldListener extends FocusAdapter
         //method that listens losing focus of textfield
         public void focusLost( FocusEvent ev )
              boolean flag;
              String indFALSE, indTRUE;
              indFALSE = "FALSE";
              indTRUE = "TRUE";
              int strLength;
              flag = mt.isValidTime(sunMornStartTime_str); //mt is for MilitaryTime
              if (flag == false)
              sunMornStartTime.setText(new String(indFALSE));
              if (flag == true)
              sunMornStartTime.setText(new String(indTRUE));
         }//End of Method
    }//End of private class TextFieldAction

  • Logical error iExpenses

    There is a way to follow the details of each paguina Web within iExpenses, I have a logical error where I erased information already captured by pressing the button "Save" someone could mencionarme something.
    Thanks

    you can do it with a .sql script
    c:\my_emp.sql
    PROMPT
    PROMPT instering my_employees
    PROMPT
    ACCEPT ID NUMBER PROMPT 'ID ? : '
    ACCEPT FIRST_NAME CHAR PROMPT 'FIRST_NAME ?: '
    ACCEPT LAST_NAME CHAR PROMPT 'LAST_NAME ?: '
    ACCEPT SALARY NUMBER PROMPT 'SALARY ? : '
    insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary);
    SELECT * FROM my_employee where id=&&id;
    and then from sqlplus @c:\my_emp.sql
    scott@ORCL> @C:\MY_EMP
    instering my_employees
    ID ? : 20
    FIRST_NAME ?: john
    LAST_NAME ?: papas
    SALARY ? : 1000
    old 1: insert into my_employee values(&id,'&last_name','&first_name',substr('&&first_name',1,1)||substr('&last_name',1,7),&salary)
    new 1: insert into my_employee values( 20,'papas','john',substr('john',1,1)||substr('papas',1,7), 1000)
    1 row created.
    old 1: SELECT * FROM my_employee where id=&&id
    new 1: SELECT * FROM my_employee where id= 20
    ID LAST_NAME FIRST_NAME USERID SALARY
    20 papas john jpapas 1000
    scott@ORCL>

  • Essbase Internal Logic Error [7333]

    We have a "backup" application to which we copy all of our applications' databases to every night.
    However now when we try to start the backup application we get one or more of the following errors in the log, and the app won't start:
    Unable to Allocate Aligned Memory for [pMemByte] in [adIndInitFree].
    Unable to Allocate Aligned Memory for [pTct->pTctFXBuffer] in [adTmgAllocateFXBuffer].
    Essbase Internal Logic Error [7333]
    RECEIVED ABNORMAL SHUTDOWN COMMAND - APPLICATION TERMINATING
    The other live applications that I'm copying from all start correctly. There is plenty of disk space and free memory on the server.
    I've read about other people getting these errors and tried the following:
    - Recreated the backup application (which cleared out any temporary files that might have been hanging around)
    - Validated all the other applications that I'm copying from
    It does seem to be a capacity issue because when I remove some of the larger databases from the backup application it does start. However I can't attribute the problem to an individual large database because when I copy each of them to the application by themselves then they're fine.
    I'd appreciate any ideas on what to try next... could this suggest that something's wrong with the memory chips on the server?
    Thanks
    Mark
    Update: I have used a workaround by putting half of the databases in one backup application and the other half in another application. Both of these applications start without a problem. Is there a maximum size of databases in an app? I am trying to add 21 databases with a combined .PAG file size of only 2.4GB.
    Edited by: MatMark on Nov 22, 2010 2:46 PM

    Thank you John, yes it appears to be the 2GB limit, however I'm a bit confused as to what I should be measuring that exceeds 2GB, you mentioned index cache (I assume these are IND) which total to only 140MB.
    The PAG files total to 3.7GB but these would have been greater than 2GB for a long time, before this problem started occurring.
    Anyway, case closed, I have to split these up into separate applications. Thanks for your help.

  • Essbase Internal logic error

    Hi,
    In one our job, after loading the data files we are running a calc on the database. But we got the following error. We are Essbase 6.5.1. This is a daily job where we load the data files & calc the database & in the past didn't run into any issues.
    Can someone help me understanding what went wrong here?
    [Sun Mar 01 22:17:59 2009]Local/Objectiv///Info(1008108)
    Essbase Internal Logic Error [7421]
    [Sun Mar 01 22:17:59 2009]Local/Objectiv///Info(1008106)
    Exception error log [D:\ESSBASE\app\Objectiv\log00003.xcp] is being created...
    [Sun Mar 01 22:18:00 2009]Local/Objectiv///Info(1008107)
    Exception error log completed -- please contact technical support and provide them with this file
    [Sun Mar 01 22:18:00 2009]Local/Objectiv///Info(1002089)
    RECEIVED ABNORMAL SHUTDOWN COMMAND - APPLICATION TERMINATING
    Appreciate your help
    Vamsi

    The exception file means that Essbase had a problem and basically the application crashed. Have you tried to see if the application will restart? If so, you might want to try to rerun your process, sometimes it's an intermittent thing. If not, look at the log in more detail and see what it was doing when it failed. Data load, calc script, etc to see it you can narrow down what it was doing.

  • SOME LOGICAL ERROR

    sir i write code for finding freuent pattern but it give some logical error plz see that and correct that
    i send the complete information to u my input file my project code my output file and my actual output that i need ......plz sir chek it where is he logical mistak in code i completely chek lots of time i m not able to find where is the logical mistak plz sir help me
    input file "transactions.xml"
    <?xml version="1.0" standalone="yes"?>
    <transactions>
    <transaction id="1">
    <items>
    <item>a</item>
    <item>d</item>
    <item>e</item>
    </items>
    </transaction>
    <transaction id="2">
    <items>
    <item>b</item>
    <item>c</item>
    <item>d</item>
    </items>
    </transaction>
    <transaction id="3">
    <items>
    <item>a</item>
    <item>c</item>
    <item>e</item>
    </items>
    </transaction>
    <transaction id="4">
    <items>
    <item>b</item>
    <item>c</item>
    <item>d</item>
    </items>
    </transaction>
    <transaction id="5">
    <items>
    <item>a</item>
    <item>b</item>
    </items>
    </transaction>
    </transactions>
    coding :=
    xquery version "1.0";
    declare namespace local = "http://www.w3.org/2003/11/xpath-local-functions";
    declare function local:join($X as element()*, $Y as element()*) as element()* {
    let $items := (for $item in $Y
    where every $i in $X satisfies
    $i != $item
    return $item)
    return $X union $items
    declare function local:commonIts($X as element()*, $Y as element()*) as element()* {
    for $item in $X
    where some $i in $Y satisfies $i = $item
    return $item
    declare function local:removeIts($X as element()*, $Y as element()*) as element()* {
    for $item in $X
    where every $i in $Y satisfies $i != $item
    return $item
    declare function local:candidateGen($l as element()*) as element()* {
    for $freqSet1 in $l
    let $items1 := $freqSet1//items/*
    for $freqSet2 in $l
    let $items2 := $freqSet2//items/*
    where $freqSet2 >> $freqSet1 and
    count($items1)+1 = count($items1 union $items2)
    and local:prune(local:join($items1,$items2), $l)
    return
    <items>{local:join($items1,$items2)}</items>
    declare function local:prune($X as element()*, $Y as element()*) as xs:boolean
    every $item in $X satisfies
    some $items in $Y//items satisfies
    count(local:commonIts(local:removeIts($X,$item),$items/*))
    = count($X) - 1
    declare function local:removeDuplicate($C as element()*) as element()*
    for $itemset1 in $C
    let $items1 := $itemset1/*
    let $items :=(for $itemset2 in $C
    let $items2 := $itemset2/*
    where $itemset2>>$itemset1 and
    count($items1) =
    count(local:commonIts($items1, $items2))
    return $items2)
    where count($items) = 0
    return $itemset1
    declare function local:getLargeItemsets($C as element()*, $minsup as xs:decimal, $total as xs:decimal, $src as element()*) as element()*
    for $items in $C
    let $trans := (for $tran in $src
    where every $item1 in $items/* satisfies
    some $item2 in $tran/*
    satisfies $item1 = $item2
    return $tran)
    let $sup := (count($trans) * 1.00) div $total
    where $sup >= $minsup
    return <largeItemset> {$items}
    <support> {$sup} </support>
    </largeItemset>
    declare function local:fp-growth($l as element()*, $L as element()*, $minsup as xs:decimal, $total as xs:decimal, $src as element()*) as element()*
    let $C := local:removeDuplicate(local:candidateGen($l))
    let $l := local:getLargeItemsets($C, $minsup, $total, $src)
    let $L := $l union $L
    return if (empty($l)) then
    $L
    else
    local:fp-growth($l, $L, $minsup, $total, $src)
    let $src := doc("transactions.xml")//items
    let $minsup := 0.5
    let $total := count($src) * 1.00
    let $C := distinct-values($src/*)
    let $l :=(for $itemset in $C
    let $items := (for $item in $src/*
    where $itemset = $item
    return $item)
    let $sup := (count($items) * 1.00) div $total
    where $sup >= $minsup
    return <largeItemset>
    <items> {$itemset} </items>
    <support> {$sup} </support>
    </largeItemset>)
    let $L := $l
    return <largeItemsets> { local:fp-growth($l, $L,$minsup, $total, $src) }
    </largeItemsets>
    output that is get for running the query:=
    <?xml version="1.0" encoding="UTF-8"?>
    <largeItemsets>
    <largeItemset>
    <items>a</items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <items>d</items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <items>b</items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <items>c</items>
    <support>0.6</support>
    </largeItemset>
    </largeItemsets>
    but sir i want my output like that:=
    <?xml version="1.0" standalone="yes"?>
    <largeItemsets>
    <largeItemset>
    <Items>
    <item>a</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>d</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>b</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>c</item>
    </Items>
    <support>0.6</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>d</item>
    <item>b</item>
    </Items>
    <support>0.4</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>b</item>
    <item>c</item>
    </Items>
    <support>0.4</support>
    </largeItemset>
    <largeItemset>
    <Items>
    <item>d</item>
    <item>c</item>
    <item>b</item>
    </Items>
    <support>0.4</support>
    </largeItemset>
    </largeItemsets>
    sir i want that output which i shown last help me sir how i sort out this problem
    thank i advance
    SIR PLZ HELP ME WHAT I DO HOW I SOLVE THAT PROBLEM PLZ ANY ONE HELP ME
    Edited by: MAXIMUM on Apr 9, 2012 10:43 PM

    The code is unreadable. It would be great if you can explain the problem statement.

Maybe you are looking for

  • Can't send SMS from iPhone 4, iOS 5.0.1

    Hello! I have an iPhone 4 with iOS 5.0.1 simfree. I can recieve sms but I can't send one. It seems like there are issues with imessage, 'cause it says "waiting for activation" and doesn't offer me use my phone number to send sms via, but only my e-ma

  • Showing only Approved Metapedia Terms

    This question is two fold: 1) Is there a way to only show approved metapedia terms? 2) How have others managed their metapedia terms in a "multi-tier" environment (dev / qa / prod)? Do you promote your terms / changes through different environments o

  • Will this scenario work?

    Im looking to purchase a Time Capsule to use with Time Machine for my MBP. I will have an external HDD connected to the Time Capsule. On this external HDD, I have a folder called 'Movies' (where I create backups all my DVD collection so I dont have t

  • Automatic release of production order for perticular work center

    hello, any body please help me how to set automatic release of production order when creation for a particular work center. please suggest me. Thanks & Regards Bhakta

  • EP Web services need to be restarted after some inactivity period

    Hi All, My EP Web services go down after some inactivity period. The services need to be restarted. Can anybody help me on this? Thanks!