Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Simple Printing Calculator w/ accumulator (Newbie programmer)

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Simple Printing Calculator w/ accumulator (Newbie programmer)

    Hi everyone,

    I'm not sure how much you guys are allowed to help me with my assignment and its due tomorrow afternoon before class but I'm already expecting to get a zero on it but would still like to learn how to program and complete this program. I'm very weak with Java and programming in general but this class is required in my Networking/Security degree program. Any help would be greatly appreciated.

    Here's the lab assignment:

    This program is a simple "printing" calculator. It will accept input from
    the user in the following form:

    number operator

    The number entered will be expected to be a float type.
    The operator will be expected to be one of the following:

    'E' or 'e' - Enter the number into the accumulator (this will destroy
    the current value). This operator is used to set the
    accumulator to a known value.
    'A' or 'a' - Add the number to the current value in the accumulator
    'S' or 's' - Subtract the number from the current value in the
    accumulator
    'M' or 'm' - Multiply the number times the current value in the
    accumulator
    'D' or 'd' - Divide the current value in the accumulator by the
    number (do not divide the accumulator by zero)
    'P' or 'p' - Raise the current value in the accumulator to the power
    of the number, for this problem truncate the number to
    its integer value. (negative numbers will not be allowed)
    Do not use the "Math.pow()" method to solve this problem.
    'T' or 't' - Terminate processing and print the final result. The
    number accompanying this operator should be ignored.

    The 't' or 'T' stop signal is entered by the user, the program will print
    out the final value contained in the accumulator and terminate.

    A sample session would be the following:

    User inputs: Calculator outputs:

    10.0 e = 10.0000
    2 D = 5.0000
    2 P = 25.0000
    55.0 s = -30.0000
    100.25 E = 100.2500
    4 m = 401.0000
    0 t = 401.0000

    When the program starts the initial value for the accumulator is set to zero.

    If the user gives an input that would result in an error if the operation
    were to be attempted, an error message is printed and the current accumulator
    value. This calculator handles three types of input errors:

    1). if the user enters an invalid operator, the message is printed:

    an invalid operator was entered - please reenter

    2). if the user attempts to cause a divide by zero, the message
    is printed:

    attempt to divide by zero - please reenter

    3). if the user attempts to raise the accumulator to a negative
    power, the message is printed:

    negative powers are not allowed - please reenter
    __________________________________________________ __________________________________________________ ______

    By looking at the requirements, here's how I would like to setup the program if I knew the proper syntax and all:

    Step 1: Create Class called 'calculatorProgram'

    Step 2: Use code that will allow UserInput after program executes (Our teacher forbids us to use Scanner, wants us to use InputStreamReader and BufferedReader)

    Step 3: Create Variables:
    *Fnum (It will be the Accumulating number)
    *Ans (displayed after Fnum + operator)
    *Operators: E, A, S, M, D, P, T (define their functions)

    Step 4: -Tell user: "How to use the calculator and what letters to use for their function"
    -Ask user to: "enter a number and an Operator function"
    -

    Step 5: Begin with a While loop( != 'T' || != 't'){} -I think that's how the loop should be formatted

    Step 6: Design proper If/else and nested If/else statements for each operator and its function, be sure to use
    nested if/else for invalid operators, divide by 0, and using negative powers.

    ***
    Assuming I knew how to write Java this is how I would want to code my program. If anyone could help by giving me a small jump-start in the right direction it would be extremely helpful. I understand the concept or I/O and the purpose of Conditional statements just I have a hard time knowing how to place the variables in the right places and writing proper syntax.

    Best regards,

    Dan


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,316
    My Mood
    Mellow
    Thanks
    194
    Thanked 671 Times in 658 Posts

    Default Re: Simple Printing Calculator w/ accumulator (Newbie programmer)

    Welcome! Please read this topic to learn how to post code correctly and other useful info for new members.

    You've got to give yourself a chance. You've waited too long to start your comeback. We can't do this for you, and we don't teach you what you need to know to be successful. Give this class more of your time and come back when you have more time to complete an assignment and something we can reasonably help you with.

    Good luck!

Similar Threads

  1. [SOLVED] Newbie, why is my program printing output twice?
    By VikingCoder in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 2nd, 2012, 07:47 PM
  2. Newbie Java Programmer saying hi
    By kc120us in forum Member Introductions
    Replies: 2
    Last Post: September 8th, 2011, 09:34 PM
  3. Simple Calculator
    By JKDSurfer in forum Loops & Control Statements
    Replies: 3
    Last Post: June 28th, 2011, 01:37 PM
  4. help on simple accumulator
    By Khalon in forum Loops & Control Statements
    Replies: 2
    Last Post: January 14th, 2010, 10:39 PM
  5. Calculator application using java
    By fabolous04 in forum Paid Java Projects
    Replies: 4
    Last Post: March 25th, 2009, 11:29 AM