Simple calculator for viewing in cmd

i am taking my first programming class and have started to feel overwhelmed. this is my assignment:
To write a program that lets a user do simple math operations on two numbers
? To demonstrate using decision logic in a Java program.
? To become aware of error conditions when writing a program
? To continuing practicing working with two files in a Java program, one Java class
and a tester
Programming Requirements
1. Get user input for the users? name and two integer numbers.
2. Get the user input for a choice of math operation: addition, subtraction,
multiplication.
3. Output the user?s name and the result of the math operation on the two numbers
that were input by the user.
Output: The output should look similar to the following:
What is your name?
Java
Enter a number:
7
Enter another number:
3
Choose a math operation: (A) addition, (S) subtraction, (M)
multiplication
M
Hello Java! 7 * 3 = 21
all i have so far is:
* Calculator.java
* Modified on July 14, 2008
* This class has a method that accepts input from a user about their name, 2 integers, and mathematical
* operation. it then calculates answer and outputs information to screen
import java.util.Scanner; // This import is so that I can have access to the Scanner code.
* @author sandra
/** Creates a new instance of Calculator */
public Calculator() {
* @param args the command line arguments
public static void main(String[] args) {
//I am creating an object of type Scanner to help me get input from the user.
Scanner inputScanner = new Scanner(System.in);
     // value for variables are listed below
int firstNumber = 0; // initialize input to 0
int secondNumber = 0:
String inputName = "Doe"; //assigns an initial value for the string value inputName
System.out.println("What is your name?");
inputName = inputScanner.nextLine(); //Stores user input for later use
System.out.println("Enter a number");
int firstNumber = inputScanner.nextInt();
myScanner.nextLine(); // Reading the return character from the previous integer input to get around bug...
System.out.println("Enter another number");
int secondNumber = inputScanner.nextIt();
myScanner.nextLine(); // Reading the return character from the previous integer input to get around bug...
System.out.println("Choose a math operation:");
System.out.println("(1) Addition");
System.out.println("(2) Subtraction");
System.out.println("(3) Multiplication");
// Store the user's response as an integer
int operation = myScanner.nextInt();
myScanner.nextLine(); // Reading the return character from the previous integer input to get around bug...
if (operation == 1 )
i know i'm probably on the wrong track. the if/else statements are frying my brain. PLEASE help. thanks

Looks like you are on the right track to me. I give a little hint.
if(....) {
    // what should you do if user enters 1?
} else if(....) {
    // what should you do if user enters 2?
} else if(....) {
    // what should you do if user enters 3?
} else {
    // what should you do if user enters 42?
System.out.println(....);Just work out what the dots are.

Similar Messages

  • Design a simple calculator for multiple number systems

    Details:
    1.     Before designing the graphical user interface, create an abstract class called Number and four derived classes called Binary, Octal, Decimal, and Hexadecimal. Use the following structure for your Number class. The derived classes should include two constructors paralleling the abstract class and implementations of the two abstract methods.
    Number
    - n: int
    + Number() // Initialize n to zero
    + Number(int i): // Initialize n to i
    + add(Number a): void // Add Number a to this Number
    + subtract(Number s): void // Subtract Number s from this Number
    + getN(): int // Obtain current value of n
    + setN(int i): void // Set value of n to i
    + toString(): String (abstract) // Return current number as a String in
    // appropriate number system
    + setN(String s): void (abstract) // Set value of n based on String
    // representation of the number
    // throws NumberFormatException if String
    // contains inappropriate characters for
    // the given number system
    2.     Interface operation.
    �     Clicking Binary, Octal, Decimal, or Hexadecimal changes the number in the text box and the current total to the selected number system. If there is a NumberFormatException, display an error message below the text box and do not make the change.
    �     Clicking Add To Total or Subtract From Total uses the value in the text box to update the current total. If there is a NumberFormatException, display an error message below the text box and do not make the change.
    �     Clear Entry clears the text box, Clear Total resets the current total to zero, and Clear All does both.
    �     Indicate the current number system in use with a color and display error messages in red. Feel free to improve the layout as desired.
    3.     The Integer wrapper class has a toString() method and parseInt() method each with a parameter called radix that allows you to specify the number system. These will help immensely with your abstract methods. Your calculator should work with negative numbers.
    4.     Programming hint: Provide an object of type Number to store the value in the text box and another object of type Number to store the current total. These will be able to hold values from any number system and simplify your coding.

    Thank you for posting your homework on the Sun Developer Network Java Forum! Your request has been assigned the following ticket number (you should keep this for your reference) 3405691582.
    At the present we are experiencing higher than normal volumes of lack of interest in helping you cheat on another homework assignment. Please stand by until somebody inept comes along to do it for you or you fail. We appreciate your patience in this matter.

  • Simple Calculation (for anyone other than me)

    I cant beleive I am posting this but I have fallen and can't
    get up...
    I'm trying to calculate (2) dollar amounts for this 401(k)
    calculator I am creating.
    Can someone assist? I am trying to add the 'Your Investment'
    value to the 'Company Contribution' value to get the total
    combined... Everything I come up with = NaN
    Source .as file is here:
    http://home.comcast.net/~shane.swoboda/four01k.as
    Flash file:
    http://home.comcast.net/~shane.swoboda/four01k.fla

    Sorry, but I don't generally download files from thes forums.
    Why don't you pull out the relevant bits and post them here?
    The usual suspects are that you are trying to add them before
    the user (or whatever) has input the data. Or that you aren't
    converting one of them to a number.
    Are you assigning them to an intermediate variable or are you
    trying to pull directly from the text field?
    What happens if you do this:
    trace("the value is ["+myTextField.text+"]");
    right before you need to add them?
    Also a good trick is to go to the debug menu in the testing
    environmnet and select "List variables" this will show you where
    everything is defined. Perhaps your textfields are not in the scope
    of where you are trying to add them?

  • Process sampled data and perform simple calculation to by pass Matlab?

    I have files that contain large number current samples (like 300,000 for example). I need them to performing simple calculations (for example to calculate energy).
    Before, I used Matlab to load all those samples into array and to do all calculations there.
    However... that process is kind of slow. What can I use to simply this and replace Matlab by some script?
    Can I use perl or php to perform this operation on set of sample files to spit out final calculation values into new file?
    Last edited by kdar (2012-05-11 13:21:05)

    I'm surprised no one has suggested numpy and scipy, which are modules for python 2. They have syntax that's similar to mattlab, they're very fast, and python is useful in other circumstances and easy to learn.
    I did something similar for spectral data. Here's an example of what I did in python:
    #!/usr/bin/env python
    #This program goes through rayleigh line data and finde the mean shift
    #in nanometers and the standard deviation
    import sys, os
    import numpy as np
    import scipy as sp
    import scipy.optimize as op
    import time
    ray = []
    filenames = []
    line = 633
    def rs(wavelength,laser):
    return ((float(1)/laser)-(float(1)/wavelength))*(10**7)
    def main(argv): #Goes through a file and finds the peak position of the rayleigh line
    f = np.loadtxt(argv).transpose() #opens the file
    maxi = np.amax(f[1]) #Finds the value of hte peak of the rayleigh line
    intensity = [f[1,i] for i in range(len(f[1]))] #extrants the array into a list
    indi = intensity.index(maxi) #Finds the index of the rayleigh line
    ray.append(f[0,indi])
    filenames.append(str(argv))
    # Goes through each file named in the CLI call and applies the main function to it
    for filename in sys.argv[1:]:
    main(filename)
    # Use numpy for some basic calculations
    mean = np.mean(ray)
    StandardDeviation = np.std(ray)
    median = np.median(ray)
    variance = np.var(ray)
    ramanshift = [rs(ray[i],line) for i in range(len(ray))]
    rsmean = np.mean(ramanshift)
    rsSD = np.std(ramanshift)
    rsmedian = np.median(ramanshift)
    rsvariance = np.var(ramanshift)
    tname = str(time.asctime())
    # Write all calculations to a file
    output = open('rayleigh_'+tname+'.dat','w')
    output.write('#The files used for this compilation are:\n')
    for i in range(len(filenames)):
    output.write('#'+filenames[i]+'\n')
    output.write('The wavelengths of the Rayleigh line are (in nm):\n')
    for i in range(len(ray)):
    output.write(str(ray[i])+'\n')
    output.write('The raman shifts of the rayleigh line for '+str(line)+'nm are (in rel. cm^(-1):\n')
    for i in range(len(ray)):
    output.write(str(ramanshift[i])+'\n')
    output.write('Mean = '+str(mean)+'nm, or '+str(rsmean)+' rel. cm^(-1)\n')
    output.write('Standard Deviation = '+str(StandardDeviation)+' nm, or '+str(rsSD)+' rel. cm^(-1)\n')
    output.write('Median = '+str(median)+'nm or, '+str(rsmedian)+' rel. cm^(-1)\n')
    output.write('Variance = '+str(variance)+'nm or, '+str(rsvariance)+' rel. cm^(-1)\n')
    output.close()
    Last edited by Yurlungur (2012-05-13 21:14:54)

  • Generating Dependencies for Calculation/Analytical View in SAP HANA.

    Hi Everyone,
    I am trying to find out the dependencies for a specific Calculation/Analytical View. I have used sys.object_dependencies but that gives only the table names on which the calculation view is dependent on, but not theanalytical and attribute views.
    For example, consider a calculation view which is developed by joining 2 analytical views and the analytical views in turn uses some attribute views. So my ask is to get all these object information not just the tables. This is very basic info and I assume it must be captured in some metadata views. My aim is to query such metadata views and get the dependencies. Any pointers to this would be highly helpful.
    Best Regards. 

    Hi Samarpan,
    You can right click on the view and select option 'Auto Documentation' with content type as 'Model Details' in the wizard. Select a target location for the document to generate.
    When you open the generated document, in the last there is a section as 'Cross References' which will give you full hierarchy of views/tables used.
    Hope this will solve your problem
    Regards,
    Rashmi

  • Web Dynpro Application For developing a simple calculator

    Dear Experts,
    I am trying to develop a simple calculator application in abap web dynpro .
    but i am not able to enable the buttons (1 to 9) . that is what i want is like how it happens in a normal calculator if we press 1 , then in the screen, 1 comes and if 11 then twice we press 1. Like wise i want if the button 1 is enabled then in the input field it should take 1 and if 11 then it should take 11. Kindly give some suggestions to develop this application.
    Regards
    Swarnadeepta

    Hi Swarnadeepta,
    I developed a calculator in web dynpro...please go through the following code. I have made a few changes with respect to modularization but the basic concept is still the same.
    Method to Enter Data on the screen
    METHOD enter_data .
      DATA lv_input TYPE i.
      DATA lv_flag TYPE c.
    ***Read input in the screen 
    wd_this->get_input(
        IMPORTING
          ev_input = lv_input                       " integer
    ***See whether flag is set. If yes save the present value in global attribute gv_previous.
      wd_this->get_flag(
        IMPORTING
          ev_flag = lv_flag                        " wdy_boolean
      IF lv_flag = 'X'.
        wd_this->gv_previous = lv_input.
        lv_input = 0.
      ENDIF.
    ***Modify screen input
      IF lv_input IS INITIAL.
        lv_input = iv_number.
      ELSE.
        lv_input = lv_input * 10 + iv_number.
      ENDIF.
    ***Set the new value of input field
      wd_this->set_input(
        iv_input = lv_input                          " integer
    ***Reset the flag
      wd_this->set_flag(
        iv_flag = ''                           " wdy_boolean
    ENDMETHOD.
    Use the above method on button click
    method ONACTIONONE .
      wd_this->enter_data(
        iv_number = 1                        " integer
    endmethod.
    Method to Register Operations
    method ENTER_OPERATION .
      wd_this->set_flag(
        iv_flag = 'X'                           " wdy_boolean
      wd_this->set_operation(
        iv_operation = iv_operation                      " string
    endmethod.
    Use of above method in operations button
    method ONACTIONADD .
      wd_this->enter_operation(
        iv_operation = 'ADD'                     " string
    endmethod.
    Method to calculate
    method ONACTIONEQL .
    DATA lv_operation TYPE string.
    DATA lv_input TYPE i.
    ***Read screen input 
    wd_this->get_input(
         IMPORTING
           ev_input = lv_input                        " integer
    ***read operation requested
      wd_this->get_operation(
        IMPORTING
          ev_operation = lv_operation                   " string
    CASE lv_operation.
    WHEN 'ADD'.
    lv_input = wd_this->gv_previous + lv_input.
    WHEN 'SUB'.
    lv_input = wd_this->gv_previous - lv_input.
    WHEN 'MUL'.
    lv_input = wd_this->gv_previous * lv_input.
    WHEN 'DIV'.
    lv_input = wd_this->gv_previous / lv_input.
    WHEN OTHERS.
    ENDCASE.
    ***Set the new value of input field
      wd_this->set_input(
        iv_input = lv_input                         " integer
    ***Clear the operation attribute
      wd_this->set_operation(
        iv_operation = ''                     " string
    endmethod.
    Getter Methods example for attribute INPUT
    method GET_INPUT .
      DATA lo_el_context TYPE REF TO if_wd_context_element.
      DATA ls_context TYPE wd_this->element_context.
      DATA lv_input TYPE wd_this->element_context-input.
    get element via lead selection
      lo_el_context = wd_context->get_element( ).
    @TODO handle not set lead selection
      IF lo_el_context IS INITIAL.
      ENDIF.
    get single attribute
      lo_el_context->get_attribute(
        EXPORTING
          name =  `INPUT`
        IMPORTING
          value = lv_input ).
    EV_INPUT = lv_input.
    endmethod.
    Setter Methods example for attribute INPUT
    method SET_INPUT .
      DATA lo_el_context TYPE REF TO if_wd_context_element.
      DATA ls_context TYPE wd_this->element_context.
      DATA lv_input TYPE wd_this->element_context-input.
    get element via lead selection
      lo_el_context = wd_context->get_element( ).
    @TODO handle not set lead selection
      IF lo_el_context IS INITIAL.
      ENDIF.
    @TODO fill attribute
    lv_input = iv_input.
    set single attribute
      lo_el_context->set_attribute(
        name =  `INPUT`
        value = lv_input ).
    endmethod.
    Hope this will be helpful. Let me know if you have any doubt.
    Its working fine for me.
    Regards,
    Sayan

  • How to make a BW Infoprovider for a SAP HANA Calculation-/Analytcial-View

    Hi
    I have got a BW 73 with a Hana.
    How can I  make a BW Infoprovider for a SAP HANA Calculation-/Analytcial-View in SAP BW ?
    Thank You
    Best Martin

    Hi Rekha,
    No need to do anything, just we need do migrate standard info cube to In-memory Optimized Info Cube. Once it is turned to In-Memory optimized Info Cube(We will have F table surrounded by master data tables) and no dimension tables in HANA.
    F-tables is nothing but Analytic View in HANA and Master data tables are nothing but Attributes in HANA.
    once you migrate to In-Memory Info Cube, your tables are ready in HANA and you can create different view.
    have a look at the below videos.
    https://www.experiencesaphana.com/blogs/bwonhana/2011/10/18/prerequisites-for-bw-on-hana
    http://www.sdn.sap.com/irj/scn/data-warehousing-elearning
    Regards,
    Venkatesh

  • Simple calculations in Universe not working for XI 3.0

    Simple calculations in Universe using key figures are not working in XI 3.0(without any Fix Pack)
    Below is the steps I followed.
    1. Using key figure [Jan] I am trying to round the values by deviding it by 1000.
    <EXPRESSION>@Select([Jan])/1000</EXPRESSION>
    This gives me a null cell value.
    2. I tried addition then
    <EXPRESSION>@Select([Jan])+1000</EXPRESSION> result was all the cell values changed to 1000.
    3. Finally without calculation I tried
    <EXPRESSION>@Select[Jan]</EXPRESSION> this also resulted null value
    But without EXPRESSION tag if I try @Select[Jan] it works fine.
    Am I missing anything in above expressions.
    As of now I am creating variable in report to incorporate the rounding.
    Thanks
    Raghu

    It was my mistake while writing the question. Path I have used is correct one only @Select(Key Figures/.
    If i use the above alone, I am able to se the data. But if I use in betwen <EXPRESSION> then it gives null value.
    Note: Pls dont confuse with flower bracket i used it just to avoid coverting it to a html link and also the backslash it was not showing in preview
    I have followed that pdf and created calculation in universe.
    Edited by: Raghavendra Barekere on Feb 6, 2009 6:42 AM

  • Gtksql pkgbuild. Simple GUI for sql queries.

    This is simple program for running sql queries. I made this pkgbuild some time ago but I'm not sure how much it is good. Gtksql should support both mysql and postgresql but postgresql support is broken (probably to old). Developer promises a brand new gtk2 based application. We will see...
    Since I can't make this pkgbuild any better I'm just posting it.
    gtksql PKGBUILD
    pkgname=gtksql
    pkgver=0.4.2
    pkgrel=1
    pkgdesc="Gtk front-end for sql queries"
    url="http://gtksql.sourceforge.net/"
    depends=('lua' 'gtk')
    makedepends=('mysql')
    source=(http://dl.sourceforge.net/sourceforge/gtksql/$pkgname-$pkgver.tar.gz)
    md5sums=('a0ba598027cd49f69f951a31342b51fd')
    build() {
    cd $startdir/src/$pkgname-$pkgver
    ./configure --prefix=/usr
    --with-mysql
    --with-lua
    make || return 1
    make prefix=$startdir/pkg/usr install

    Hello:
    I'm trying to do add a calculated variable to my view that isn't an Entity
    Attribute, its simple really but i don't know if I'm leaving something out or
    not.
    I add the "new Attribute" , call it nCompleted, type - number
    I then check off everything as is required(as documented in Help)
    for an Sql Derived Attribute, the following code is entered in the
    Expression Box :
    Select group_services.office, count(client_group_services.clnt_group_services_id) as nCompleted
    Where group_services_id=client_group_services_id(+)
    And client_group_services_id.result="Completed";
    It isn't working, what am I missing???? Sheena:
    It probably isn't working because of missing 'group by' clause. I don't know the exact detail of your query statement, but suppose you want to count number of employees in a dept, then you're query should look like:
    select dept.deptno, dept.dname, count(emp.empno) as nCount
       from dept, emp where dept.deptno = emp.deptno(+)
       group by dept.deptno, dept.dname  // This group-by is important
    OR if you want to use nested SELECT
    select dept.deptno, dept.dname,
       (select count(emp.empno) from emp where dept.deptno=emp.deptno(+)) as nCount
       from dept

  • Can I connect an external video camera to a mac book pro for viewing live video so I don't have to use the little screen on the camera?

    Can I connect an external video camera to a mac book pro for viewing live video so I don't have to use the little screen on the camera?

    Shadow30 wrote:
    Can I connect an external video camera to a mac book pro for viewing live video so I don't have to use the little screen on the camera?
    • Only if your video camera supports it.  Depending on how your camera works, you may need to add preview software to your Mac to use this feature.
    • Alternatively, your camera may also be able to record directly into your Mac while you are monitoring the Mac's display.
    • If you are using a consumer camcorder that supports HDMI monitoring, a small HDTV might be an simpler solution than your Mac.  For an example of how this is done, see http://youtu.be/GVpSkZD6qE4.
    • The retailer who sold you your video camera may have other suggestions.
    • If you need more professional results, an external preview monitor will offer more capability on compatible cameras.
    Message was edited by: EZ Jim
    Mac OSX 10.9.4

  • Best practice for viewing short home videos on AppleTV?

    Please help me find a simple way to view short home videos taken on a digital video camera, photo camera or cell phone on my Apple TV.
    I've been using AppleTV to showcase my photos for a couple months now, but all the short little videos I take along the way have been gathering dust in a general folder. None of them are significant enough to warrant building a full on iMovie, and all are in Nikon's AVI format. To date I have about 300 of them, hoping that one day they won't just gather dust.
    As I understand it these are the recommended steps that Apple encourages:
    1) Import movies from camera onto hard disk (Aperture prompts me to do this when I import photos)
    2) Import all movies into iMovie
    3) Export for AppleTV (creating new projects for each video, individually!)
    4) Import into iTunes
    5) Sync with AppleTV
    This is awful. For comparison, here is my current workflow for photos to get them to show on AppleTV...
    1) Import photos into Aperture.
    Assuming iTunes is already running (and it mostly is), there's not even a step two. iTunes is set up to sync a "Recent Import" smart album from Aperture to AppleTV so everything else is behind the scenes. A few seconds after importing I'm viewing new photos on my AppleTV.
    Since AppleTV is actually built for video, I'm hoping for a revised workflow that can showcase my movies as quickly as it does photos.
    I'm currently not running a hacked version of the AppleTV OS, but would consider it if it simplifies the process. Automator workflows, Finder Folder Actions, and AppleScripts are also fair game.

    Thanks pvonk. I get that video is more complex than photos, but Apple still wrote its photo applications to accept all sorts of photo file types (even the many proprietary RAW formats). So I don't think it's crazy to question why this workflow isn't easier for video. Especially when Apple is the biggest champion of integrated video solutions.
    Right now, here's my best guess at a workable solution. Care to weigh in?
    Setup:
    1) Attach a folder action to a folder (let's say ~/Movies/Imported/)
    2) Folder-Action runs shell script that converts videos to mp4 via HandBrake's command line tool
    3) Shell script triggers another folder action upon HandBrake completion to pushes the completed file to a new folder (let's say ~/Movies/Converted/)
    4) "Converted" folder action to import to iTunes (perhaps Applescript? Automator?)
    ~ if one could automatically add a meta tag (let's say "AppleTV") they could be added to a smart album on iTunes that is set up to sync with AppleTV
    *Workflow after Setup:*
    1) Import all movies to a folder (~/Movies/Imported/)
    Does this sound about right? My shell scripting skills are less than adequate for this, so if there is a way to accomplish this with AppleScript, that'd be ideal.
    Any other suggestions to simplify the workflow? The setup here still seems overly complex for a normal user. I can't imagine the folks at Apple really excited about the hurdles involved in this either, so I hope that they're working out a solution already.

  • Simple calculations not working in acrobat 9

    I have text form fields made in Acrobat 9 from a previously made pdf, where I need a simple calculation, but I cannot get it to work.
    The form is not for submission, only for personal tracking, so I don't even need validation.
    FieldA (a number they enter) x a number I have entered in the calculation = FieldB
    FieldB x FieldC (a number they enter) = FieldD In FieldB I have a simple javascript Calculation in the form field: FieldA * .115, which should automatically calculate answer into FieldB, when tabbed.
    In FieldD I have a Calculation in the form field: FieldB * FieldC, which should automatically calculate answer into FieldD. All fields are set as numbers.
    I have left the Trigger Action as Mouse Up.
    I don't need to validate, as this is personal use, and is not being submitted.
    I have all fields in the correct tab order.
    I have reader enabled the form. When I open the form in Reader, I can enter the numbers, but no calculations are being performed. It reads 0 in FieldB and FieldD. Any assistance would be greatly appreciated.

    Hello Everyone,
    I use the following VBS code, but to tell the truth, I don't know if it works or not. The main idea was to enable commenting from Adobe Reader. But after execution code, saving document and reopening it in Reader, commenting is still 'Not Allowed'. Is showAnnotToolsWhenNoCollab really capable to allow this and there is only error in my code? Or is the functionality different and this way can never be used for what I want?
    There is another issue that application is not closed on Exit, but is still shown.
    scriptPath = "C:\Acrobat\"
    Set gApp = CreateObject("AcroExch.App")  
    Set pdDoc = CreateObject("AcroExch.PDDoc")
    sampleFilePath = scriptPath & "AR_test_orig.pdf"
    pdDoc.Open sampleFilePath
    pdDoc.OpenAVDoc "myFile"
    gApp.Show
    Set formApp = CreateObject("AFormAut.App")
    'formApp.Fields.ExecuteThisJavascript "app.alert(""hello"");"
    formApp.Fields.ExecuteThisJavascript "Collab.showAnnotToolsWhenNoCollab = true;"
    Set formApp = Nothing
    pdDoc.Save 1, scriptPath & "AR_test.pdf"
    'pdDoc.Close
    gApp.CloseAllDocs
    gApp.Exit
    Set pdDoc = Nothing
    Set gApp = Nothing
    Thanks for any ideas.
    Jan
    PS: I use Acrobat 9.0 Pro

  • Need help with starting a simple calculator

    I have this simple calculator I just started on, and I'm having just a few problems. First of all, I don't know how to append text to a textfield. Maybe I would have to create a string buffere or something. Then, when the user clicks one of the buttons, the compiler goes crazy, and nothing is displayed.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Calculator extends JFrame implements ActionListener
         JButton[] btnNums;
         JButton btnBack;
         JButton btnClear;
         JButton btnCalculate;
         String[] strNames;
         JTextField txtDisplay;
         public Calculator()
              Container content = getContentPane();
              setSize(210,250);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              /*  construct a JPanel and the textfield that
               *  will show the inputed values and outputed
               *  results
              JPanel jpDisplay = new JPanel();
              jpDisplay.setLayout(new BorderLayout());
              txtDisplay = new JTextField(15);
              txtDisplay.setHorizontalAlignment(JTextField.RIGHT);
              jpDisplay.add(txtDisplay);
              /*  contstruct a JPanel that will contain a back
               *  button and a clear button.
              JPanel jpRow2 = new JPanel();
              btnBack = new JButton("Backspace");
              btnClear = new JButton("Clear");
              btnClear.addActionListener(this);
              jpRow2.add(btnBack);
              jpRow2.add(btnClear);
              /*  construct a string array with all the names of the
               *  buttons, then in a for loop create the new buttons
               *  and add their name and an actionListener to them.
              String[] strNames = {"7","8", "9","/", "4", "5", "6","*", "1", "2", "3","+", "0", "+/-", ".", "-"};
              btnNums = new JButton[16];
              JPanel jpButtons = new JPanel();
              jpButtons.setLayout(new GridLayout(4,4));
                for (int i = 0; i < 16; i++)
                     btnNums[i] = new JButton(strNames);
                   btnNums[i].addActionListener(this);
                   jpButtons.add(btnNums[i]);
              /* construct the final JPanel and add a
              * calculate button to it.
              JPanel jpLastRow = new JPanel();
              btnCalculate = new JButton("Calculate");
              btnCalculate.addActionListener(this);
              jpLastRow.add(btnCalculate);
              /* set the contentPane and create the layout
              * add the panels to the container
              setContentPane(content);
              setLayout(new FlowLayout());
              setResizable(false);
              content.add(jpDisplay, BorderLayout.NORTH);
              content.add(jpRow2);
              content.add(jpButtons);
              content.add(jpLastRow);
              setTitle("Mini Calculator");
              setVisible(true);
         public void actionPerformed(ActionEvent ae)
              for (int i =0; i < 16; i++)
                   if (ae.getSource() == btnNums[i])
                        txtDisplay.setText(strNames[i]);
         public static void main(String[] args)
              Calculator calc = new Calculator();

    First of all, I don't
    know how to append text to a textfield.
    textField.setText( textField.getText() + TEXT_YOU_WANT_TO_APPEND );
    Then,
    when the user clicks one of the buttons, the compiler
    goes crazy, and nothing is displayed.No, the compiler doesn't go crazy, the compiler has done it's job by then. However, you do get a NullPointerException, and the stacktrace tells you that the problem is on the following line:
    txtDisplay.setText(strNames);
    It turns out that strNames is null. I leave it to you to find out why. ;-)

  • Simple Calculations in BPS Web

    Hi,
    I am using the BPS web layouts (ALV Grid not the Excel Web Component). I would like to add a couple of very simple calculations (difference of columns/percentages etc). Is it possible to do this without using the Excel OWC ?
    Thanks
    Shailesh

    Hi
    the simplier way to achieve yor result is to use FOx formula to calculate your results at runtime .
    You should create a formula function and add FOX code to it .
    Check this link for examples
    http://help.sap.com/saphelp_nw04/helpdata/en/d3/8057f830a911d4b2be0050dadfb23f/frameset.htm
    Hope it helps
    Andr

  • Actual activity price calculation for production order

    Hi
    Can any one guide me in how many ways we can assign actual activity price calculation for production order?
    I knew only one way by assigning PPP2 costing variant?
    I have another doubt is: if we don't mention any material valuation indicator (moving average, standard) in valuation variant, how system will calculate material prices? is there any other way, to recognize the prices by system?
    regards,
    Ramesh B

    Dear,
    Costing variant PPP2 is linked to some valuation variant inn OPL1
    System will check the valuation of material and activity according to this valuation variant
    For material valuation there are many stg acceding to which system will take the price the raw material,
    Valuation strategy for material component
    Strategy sequence that determines the valuation of the materials used in the cost estimate.
    Use
    The materials are valuated using the price in the material master record or the values calculated in a material cost estimate.
    Procedure
    You can enter a single strategy, or you can enter multiple strategies in the form of a strategy sequence. If you enter multiple strategies, the priority of the strategy determines what price or what values are selected.
    Examples
    Assume that the following strategy sequence is entered for material valuation:
    1. Planned price 1
    2. Standard price
    3. Moving average price
    If the system finds a value in the Planned price 1 field (costing view), this value is taken as the value for valuating the material.
    If the system does not find a value, the value in the Standard price field (accounting view) is used.
    If the material does not have a standard price, the system uses the value from the Moving average price field.
    if you have not mentioned, then system will give error that "valuation stg not found"
    Valuation strategy for internal activities and processes-
    Strategy sequence that determines how internal activities and processes are valuated in costing.
    Use
    The activities and business processes used are valuated with the prices from Cost Center Accounting or Activity-Based Costing to determine the production costs or process costs. The prices can either be calculated iteratively through price calculation, or entered manually by the user.
    Procedure
    You can enter either a single strategy or more than one strategy in the form of a strategy sequence. If you enter more than one strategy, the priority of the strategy determines which price is selected.
    Examples
    The following strategy sequence is entered:
    1. Actual price of the previous period
    2. Plan price of the previous period
    3. The most current plan price
    If the system finds a price for the activity type, this price is used for valuating the internal activities. If no price was calculated for the previous period, the plan price from the previous period is used to valuate the activity type.
    If the system cannot find a plan price for the previous period, it looks for a future plan price, using the next price in the posting period to valuate the internal activities. For example, if plan prices have been entered for periods 2 and 3, and a plan price is calculated in period 1 for period 4, the system uses the price from period 3 in accordance with the valuation strategy Most up-to-date plan price.
    Again if you have not mentioned, then system will give error that "valuation stg not found".
    You can use any costing variant for actual (PPP2)and planned(PPP1) according to your requirement.. check in OPL1

Maybe you are looking for