Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Storing numbers and recalling numbers ?

    Storing numbers and recalling Question

    Lets say you've entered a value displays the output i.e

    String s;
    float A;
    double Number;
    s=TextFieldValueA.getText();
    A=Integer.parseInt(s);
    Number= (double)Math.round(A);
    s=String.valueOf(Number);
    txtNumber.setText(s);

    now when you select store on the menu it stores the number

    "ValueOf(Number)" and TextField A just like when you click store buttton on a calcutor M+ and M- to recall that number

    and
    to recall the Stored Values to be displayed on the textfields Number and A
    when recall is selected this can be done in Pascal when programming your calculator like the TI 84 Silver

    i.e 1-(sto)-> A A= 1 rcl A, A=1

    ive tried the stack method of push pop etc no success in achieving if theres a simple method your help would be appreciated on this one

    Thanks >>>>>>>>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by Inquisit View Post
    ive tried the stack method of push pop etc no success in achieving if theres a simple method
    what did u try?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question

    example ive used the node method trial

    Code:
    class Node{
    String item;
    Node next;
    Node first= new Node();
    Node Second=new Node();
    Node third=new Node();
     
    first.item ="1";
    second.item="2";
    third.item="3"
    first.next= second;
    second.next= third
    third.next=null;
    didnt work


    Code:
    public String toString() {
    String s= "";
    for (Node x= first; 
    x!= null;
    x=x.next;)
    s += x.item +"";
    return s;
    didnt work


    stack method

    StackClass stack1=new StackClass();
    try
    {
    stack1.push(new IntElement(1); got sophisticated so left it out

    i need just to make it simple thats all

    M+ (memory store button is clicked) stores the values
    M- (Memory recall button is clicked ) recalls the values as mentioned earlier

    when the recall button is clicked it sets the stored numbers back on the textField A and Number using setText("") method its possible with a calculator like microsoft calculator as you know why not java if not any thing is possible

    Your help im really stuck on this one i know it is straight forward any suggestions??
    Last edited by Inquisit; 09-25-2008 at 10:57 PM. Reason: mistake

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Aren't you overcomplicating things? IMHO all you need is a single instance variable to hold the contents of the _memory_

    Code:
    class Calculator {
      double memory;
      TextField textField;
      ...
      public double memoryAdd(double another) {
        memory += another;
        return memory;
      }
      public double memorySubtract(double another) {
        memory -= another;
        return memory;
      }
      public void memoryClear() {
        memory = 0;
      }
      public void memoryStore() {
        memory = Double.parseDouble(textField.getText());
      }
      public void memoryRecall() {
        textField.setText(String.valueOf(memory));
      }
    ...
    }
    this should give you a fair idea
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    New Coder
    Join Date
    Aug 2008
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up

    Splendid God bless

    i can now work my way into a complex solution

    really appreciate thanks

    just one question why cant i give a reputation round here i keep getting this message neeed to spread reputation first before.... so and so

    very helpful


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •