Writing a program, need help.

Okay i have this program that is object-oriented and using the vector class, etc. I want to change it so the program uses arrays and it isn't object-oriented at all.
I have my public static void main(). Then i want to have 2 other methods. gettingInput() and displayInput()
in the main i will call these other two methods, but I don't want to send them anything, and I want the two methods to use my variables. How can i do this or is it not possible.

Arrays are objects too -:) The OO way to change your program with minimal effort would be to replace the Vector class with your own class, lets say VectorArray. Within this new class you use arrays to implement the same functionality as Vector. Or rather reduced functionality. You only have to supply the parts of Vector you have actually used.

Similar Messages

  • Facing a problem in writing textfile, badly need help.

    I am already close to finishing this. Just that the problem i'm facing is that i can't seem to log the data into the textfile.
    It says that the concatenate has an error or something. That's the problem because i can't seem to find it.
    Do i have to use "Format string" to convert the numbers to string first? Because i've tried it before, it can't work too.
    Please help. Thank you in advance.
    Attachments:
    test1.vi ‏68 KB

    atiikah12 wrote:
    I want to write the datas into 2 separate files.
    that's fine, though you do not need 2 loops to do so....and it looks like you have data flow dependent loops
    Spoiler (Highlight to read)

  • Error from using ANT program, need help, Thanks

    Hello,
    I tried to run J2ee tutorial sample code. Following the instruction, I tried to ues ant to build a sample ConverterAPP but get some error message. I would preciate if somebody could give me some help.
    Thanks.
    Hui Lu
    [email protected]
    Following is the command I entered from an CMD window and the exception I got:
    C:\j2sdkee1.3\j2eetutorial\examples\src>ant converter
    ***Warning: I am here start runAnt.
    Exception in thread "main" java.lang.NoClassDefFoundError: Connectors\classes;C:
    \javacode\classes;C:\eGate\client\classes;C:\eGate\client\classes\egate/jar;C:\eGate\client\JRE\1/1/7B\lib\rt/jar;C:\PROGRA~1\MQSeries\java\lib\COMIBM~2/JAR;C:\
    PROGRA~\MQSeries\java\lib\COMIBM~1/JAR;C:\PROGRA~\MQSeries\java\lib\COMIBM~3/JAR;C:\PROGRA~\MQSeries\tools\javaclnt\samples\en_us;
    Warning: I am here end runAnt.
    Following is the command line in the batch file which raised Exception
    C:\jdk1.3.1_01\bin\java -classpath "C:\jdk1.3.1_01\lib\tools.jar";"C:\j2sdkee1.3\jakarta-ant-1.3\lib\parser.jar";"C:\j2sdkee1.3\jakarta-ant-1.3\lib\jaxp.jar";"C:\j2sdkee1.3\jakarta-ant-1.3\lib\ant.jar";C:\javacode\classes;C:\j2sdkee1.3\jaka
    rta-ant-1.3\bin;C:\j2sdkee1.3\bin;C:\jdk1.3.1_01\bin;C:\IBMCON~\CICS\Classes\CTGCLI~1.JAR;C:\IBMConnectors\classes;C:\javacode\classes;C:\eGate\client\classes;C:\eGate\client\classes\egate.jar;C:\eGate\client\JRE\1.1.7B\lib\rt.jar;C:\PROGRA~\MQSeries\java\lib\COMIBM~2.JAR;C:\PROGRA~\MQSeries\java\lib\COMIBM~1.JAR;C:\PROGRA~\MQSeries\java\lib\COMIBM~3.JAR;C:\PROGRA~\MQSeries\tools\javaclnt\samples\en_us;
    -Dant.home="C:\j2sdkee1.3\jakarta-ant-1.3" org.apache.tools.ant.Ma
    in converter
    ****************************************

    Obviously you have the IBM java tools installed on your PC, and your classpath starts with IBM Connectors\...
    What you need to do is to edit your classpath environment variable in control panel->systems, and use quotation marks for any long directory/file names, or directory names with spaces in them. For example, change C:\IBM Connectors\classes to "C:\IBM Connectors\classes". Then it will work.

  • How to use (to program) a Scheme in Xcode? (novice programer needs help!)

    How to use (to program) a Scheme in Xcode?
    i have been using Aquaemacs (GNU emacs) with Guile extensions. but i really would like to do all that in Xcode. is it possible? thanks.

    I believe that Scheme is not a language natively supported by Xcode. Maybe there is a way to write a plugin for it, but I don't really think so and in particular I haven't seen one for LISP or Scheme.

  • NEW to Programming- Need help with this

    Ok this is what I have so far, and Im very noob at programming so bare with me.. I get one error when trying to run , it says " ; expected instead of this token "
    Here is my code
    import java.awt.*;
    import hsa.Console;
    public class Cs
    static Console c; // The output console
    public static void main (String [] args)
    c = new Console ();
    String name;
    String answer;
    c.clear ();
    c.println ("Please enter your name.");
    name = c.readLine ();
    c.println ("Hello " + name + " Welcome to Counter-Strike (text) current map, de_dust");
    c.println ("Which team would you like to join, t or ct (terrorist or counter-terrorist).");
    answer = c.readLine ();
    if (answer.equals ("t"))
    c.println ("Welcome to the Terrorist team, you spawn with an AK-47, Glock 18 and full armor and helmet. You have maximum capacity of ammo.");
    c.println ("You run to the top of the steps and you have 2 choices");
    c.println ("Choice 1: You go straight ahead towards the underpass to the Counter-Terrorist side.");
    c.println ("Choice 2: You decide to go left and make your way to the halls in the middle of the map.");
    c.println ("Type 1 or 2 depending on your choice");
    answer = c.readLine ();
    if (answer.equals ("1"))
    c.println ("You are now on top of the underpass, you have a decision to make.");
    c.println ("Choice 1: You go down the ramp and head for the Counter-Terrorist base.");
    c.println ("Choice 2: You feel somthing bad about the ramp, and head back up the steps towards the halls.");
    c.println ("Type 1 or 2 depending on your choice");
    answer = c.readLine ();
    if (answer.equals ("1"))
    c.println ("You head down the ramp towards the CT Side");
    c.println ("As you reach the middle of the area , you look up and see a Sniper");
    c.println ("Just as you begin to shoot a few bullets from your AK, you are killed in one shot");
    c.println ("Your team rushed left through the halls and almost took over the site, but failed");
    c.println ("Counter-Terrorists Win");
    c.println ("You can restart the game by typing retry");
    else
    c.println ("You head into the halls with your team");
    c.println ("You now have 2 choices");
    c.println ("Choice 1: You take the backhall to your right");
    c.println ("Choice 2: You walk with your team down the halls to the left");
    c.println ("Type 1 or 2 depending on your decision");
    else
    c.println ("Welcome to the Counter-Terrorist team, you spawn with a Colt-M4A1, USP and full armor and helmet. You have maximum capacity of ammo.");
    c.println ("You are standing on the top ramp at the CT base, you have to defend the 2 bombsites. You are currently in bombsite A.");
    c.println ("Your 4 other teamates are going to defend bombsite A, You must make a decision!");
    c.println ("Choice 1: Go into the bombsite with the rest of your team.");
    c.println ("Choice 2: Go to the left and setup in the snipers nest or go towards the back entrance to the halls");
    answer = c.readLine ();
    if (answer.equals ("1"))
    c.println ("You have decided to go with your team in the bombsite, everyone is setup watching both entrances to the site");
    c.println ("You hear lots of footsteps , it sounds like at least 4 guys comming, you see a nade blow away a teammate");
    c.println ("All of a sudden 4 flashbangs come flying into the site through both doors, the screen goes white, you cant see a thing");
    c.println ("You can slowly start to see again but your team is already dead, and so are you.");
    c.println ("Terrorists Win, You may retry the game by typing retry.");
    }

    else
    c.println ("Welcome to the Counter-Terrorist team, you spawn with a Colt-M4A1, USP and full armor and helmet. You have maximum capacity of ammo.");
    c.println ("You are standing on the top ramp at the CT base, you have to defend the 2 bombsites. You are currently in bombsite A.");
    c.println ("Your 4 other teamates are going to defend bombsite A, You must make a decision!");
    c.println ("Choice 1: Go into the bombsite with the rest of your team.");
    c.println ("Choice 2: Go to the left and setup in the snipers nest or go towards the back entrance to the halls");
    answer = c.readLine ();
    This part... else without if... no if statement...cannot use else.. For IDE, try Jcreator... www.jcreator.com.. i recommend using the 2.5 instead of the 3.0

  • My sister installed page rage on my laptop, tried rmeoving it frodm add and delete programs and it is not there, tried looking for extensions and its not there, but the page rage web search is ther and i cant remove it. need help asap

    find it under add on and extensions, it doesnt appear on add or remove programs. need help asap

    Hi there -
    Thank you for your feedback. If you wish to uninstall our app, you can do so via our official uninstall page: http://www.pagerage.com/uninstall-pagerage.aspx
    If you still need assistance, please feel free to reach out to us by email: [email protected], thanks!

  • Need help for writing extract program

    hi
    i need help for writing extract program to retriew data from legacy system.
    i already developed bdc programs for me31k and me21.
    my requirement is to write extract program s for those t.codes.
    to retriew data from legacy system and stored in flat file.

    i need help with a java program. it is a program that allows the user to enter a student's GPA, number of extracurricular activities, and number of service activities. The user can not enter a gpa above 4.0 or below 0. The user can not enter a negative number for the number of both activities. If the student meets the following criteria: 1) GPA of 3.8 or above and at least one extracurricular activity and one service activity, 2) GPA below 3.8 but at least 3.4 and a total of at least three extracurricular and service activities, 3) GPA below 3.4 but at least 3.0 and at least two extracurricular activities and three service activities, the message "Scholarship candidate" should display. If the student does not meet the criteria above, then the message"not a candidate" should display. Can you help me, please?
    You haven't posted ANY 'java program' for us to help with.
    The forum is NOT a coding service. It is to help you with YOUR code.
    Post the code you have written and SHOW us (don't just tell us) how you compile it and execute it and the results you get. Then we can help you with any problems you are are having.
    If you need help understanding just what the program should be doing you need to ask your instructor to clarify the assignment.

  • Need help writing host program using LabView.

    Need help writing host program using LabView.
    Hello,
    I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
    I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
    eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
    My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
    I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
    Any help would be appreciated.
    Regards, George
    George Dorian
    Sutter Instruments
    51 Digital DR.
    Novato, CA 94949
    USA
    [email protected]
    m
    (415) 883-0128
    FAX (415) 883-0572

    George may not answer you.  He hasn't been online here for almost eight years.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Need help writing small program!

    Hi. I'm learning Java programming, and I need help writing a small program. Please someone help me.
    Directions:
    Create a program called CerealCompare using an if-then-else structure that obtains the price and number of ounces in a box for two boxes of cereal. The program should then output which box costs less per ounce.

    class CerealCompare {
        public static void main(String[] args) {
            // your code goes here
    }Hope that helps.
    P.S. Java does not have an if-then-else statement.

  • Need help writing Labview Program!!!!!

    I have a labview project that needs to be finished. I was not the original creator of the program and the guy who created no longer is involved with the project and I am left to finish it. Could you make the final adjustment so I can turn this into my professor and get the final grade. Thanks! Willing to pay! Negeotiable price!!!!!!!!

    Need help completing assignment! Could anyone assist me in this project!
    Attachments:
    dial tone detection.zip ‏1253 KB

  • Need Help writing program

    very new to java, i conceptually know what i want to do, but it is hard to apply that to writing the program. this is very introductory so i'd appreciate all and any help.
    i am trying to write a program such that if I select an integer, n, as in input, the program can convert that integer into it's binary representation. for example, if the integer is 4, then the program would output 001 as the binary representation of 4.
    that is the first part, the second part is to have the binary representation go from most significan bit to least significant bit, so for the integer 4 it will come out as 100 (or 000100 or 00100).
    ok basically i know i want the program to divide the chosen integer by 2 and take the remainder (n%2), which will be 1 or 0. i then want the program to take the value (n/2) and have that be the new n value, then repeat the steps over and over till my n just becomes 0. i am trying to do this with a while loop, but if there is an easier way to do this, please let me know. so far wha ti have is below, kinda stuck on how to write this program, please help. the output just keeps giving me 0 and doesn't end.
    import java.util.*;
    class Q3a{
    static Scanner console = new Scanner (System.in);
         public static void main(String args[]){
              int n;
              n = console.nextInt();
              System.out.print("Choose an integer value :");
              while (true) {
              System.out.println("Remainder on dividing " + n + " by 2 is " + n%2);
              n = n/2;}
              System.out.println("New value of n is n/2 which is " + n);
              System.out.println("Remainder on dividing " + n + " by 2 is " + n%2);
              n = n/2;
              System.out.println("New value of n is n/2 which is " + n);
              System.out.println("Remainder on dividing " + n + " by 2 is " + n%2);
              n = n/2;
              System.out.println("New value of n is n/2 which is " + n);Message was edited by:
    kribraider414

    consider
    while (n != 0){
      System.out.println(n%2);
      n = n/2;
    }put the reverse of the stoping condition in the parens for the loop
    This loop will run while n is NOT zero. It wil stop when n is zero. Try it for a few numbers and see what it does.
    Pay particular attention to what it does if the number you supplied is zero (which is the one binary number that does not have a single one in it.)
    Also take a look at what it does for negative numbers and decide what you want to do in that case.

  • Really need help on how to write this program some 1 plz help me out here.

    i am new to java and i confused on how to be writing this program.
    i have completed the Part 1 but i am stuck on Part 2 & 3 so it would would be really great if any 1 could help me out on how to write the program.
    Part I
    An algorithm describes how a problem is solved in terms of the actions to be executed, and it specifies the order in which the actions should be executed. An algorithm must be detailed enough so that you can "walk" through the algorithm with test data. This means the algorithm must include all the necessary calculations.
    Here is an algorithm that calculates the cost of a rectangular window. The
    total cost of a window is based on two prices; the cost of the glass plus the cost of the metal frame around the glass. The glass is 50 cents per
    square inch (area) and the metal frame is 75 cents per inch (perimeter).
    The length and width of the window will be entered by the user. The
    output of the program should be the length and width (entered by the user)
    and the total cost of the window.
    FORMULAS:
    area = length times width perimeter = 2 times (length plus width)
    Here is the corresponding algorithm:
    read in the length of the window in inches
    read in the width of the window in inches
    compute the area
    compute the cost of the glass (area times 50 cents)
    compute the perimeter
    compute the cost of the frame (perimeter times 75 cents)
    compute the total cost of the window (cost of glass plus cost of frame)
    display the length, width and total cost
    The next step would be to "desk check" the algorithm. First you would need to make up the "test data". For this algorithm, the test data would involve making up a length and a width, and then calculating the cost of the window based on those values. The results are computing by hand or using a calculator. The results of your test data are always calculated before translating your algorithm into a programming language. Here is an example of the test data for the problem given:
    length = 10
    width = 20
    area = 200, glass cost= 100.00 (area times 50 cents)
    perimeter = 60, frame cost = 45.00 (perimeter times 75 cents)
    total cost =145.00
    Once the test data is chosen, you should "walk" through the algorithm using the test data to see if the algorithm produces the same answers that you obtained from your calculations.
    If the results are the same, then you would begin translating your algorithm into a programming language. If the results are not the same, then you would attempt to find out what part of the algorithm is incorrect and correct it. It is also
    necessary to re-check your hand calculations.
    Each time you revise your algorithm, you should walk through it with your test data again. You keep revising your algorithm until it produces the same answers as your test data.
    ?Now write and submit a Java program that will calculate the cost of a rectangular window according to the algorithm explained. Be sure to prompt for input and label your output.?
    Part II
    Write, compile and execute a Java program that displays the following prompts:
    Enter an integer.
    Enter a second integer
    Enter a third integer.
    Enter a fourth integer.
    After each prompt is displayed, your program should use the nextint method of the Scanner class to accept a number from the keyboard for the displayed
    prompt. After the fourth integer has been entered, your program should calculate and display the average of the four integers and the value of the first integer entered raised to the power of the second integer entered. The average and result of raising to a power should be included in an appropriate messages
    (labels).
    Sample Test Data:
    Set 1: 100 100 100 100
    Set 2: 100 0 100 0
    Be sure to write an algorithm first before attempting to write the Java code. Walk through your algorithm with test data to be sure it works as anticipated.
    Part III
    Repeat Part lI but only calculate the average, not the power. This time, make sure to use the same variable name, number, for each of the four numbers input. Also use the variable sum for the sum of the numbers. (Hint: To do this, you may use the statement sum = sum + number after each number is read.)
    For Part 1 this is what i got
    import java.util.Scanner;
    public class Window
         public static void main(String[] args)
              double length, width, glass_cost, perimeter, frame_cost, area, total;
              Scanner keyboard = new Scanner (System.in);
              System.out.println("Enter the length of the window in inches");
              length = keyboard.nextInt();
              System.out.println("Enter the width of the window in inches");
              width = keyboard.nextInt();
              area = length * width;
              glass_cost = area * .5;
              perimeter = 2 * (length + width);
              frame_cost = perimeter * .75;
              total = glass_cost + frame_cost;
                   System.out.println("The Length of the window is " + length + "inches");
                   System.out.println("The Width of the window is " + length + "inches");
                   System.out.println("The total cost of the window is $ " + total);
         Enter the length of the window in inches
         5
         Enter the width of the window in inches
         8
         The Length of the window is 5.0inches
         The Width of the window is 5.0inches
         The total cost of the window is $ 39.5
    Press any key to continue . . .
    Edited by: Adhi on Feb 24, 2008 10:33 AM

    Adhi wrote:
    i am new to java and i confused on how to be writing this program.
    i have completed the Part 1 but i am stuck on Part 2 & 3 so it would would be really great if any 1 could help me out on how to write the program.Looks like homework to me.
    What have you written so far? Post it.
    Part I
    An algorithm describes how a problem is solved in terms of the actions to be executed, and it specifies the order in which the actions should be executed. An algorithm must be detailed enough so that you can "walk" through the algorithm with test data. This means the algorithm must include all the necessary calculations.
    Here is an algorithm that calculates the cost of a rectangular window. The
    total cost of a window is based on two prices; the cost of the glass plus the cost of the metal frame around the glass. The glass is 50 cents per
    square inch (area) and the metal frame is 75 cents per inch (perimeter).
    The length and width of the window will be entered by the user. The
    output of the program should be the length and width (entered by the user)
    and the total cost of the window.
    FORMULAS:
    area = length times width perimeter = 2 times (length plus width)
    Here is the corresponding algorithm:
    read in the length of the window in inches
    read in the width of the window in inches
    compute the area
    compute the cost of the glass (area times 50 cents)
    compute the perimeter
    compute the cost of the frame (perimeter times 75 cents)
    compute the total cost of the window (cost of glass plus cost of frame)
    display the length, width and total cost
    The next step would be to "desk check" the algorithm. First you would need to make up the "test data". For this algorithm, the test data would involve making up a length and a width, and then calculating the cost of the window based on those values. The results are computing by hand or using a calculator. The results of your test data are always calculated before translating your algorithm into a programming language. Here is an example of the test data for the problem given:
    length = 10
    width = 20
    area = 200, glass cost= 100.00 (area times 50 cents)
    perimeter = 60, frame cost = 45.00 (perimeter times 75 cents)
    total cost =145.00
    Once the test data is chosen, you should "walk" through the algorithm using the test data to see if the algorithm produces the same answers that you obtained from your calculations.
    If the results are the same, then you would begin translating your algorithm into a programming language. If the results are not the same, then you would attempt to find out what part of the algorithm is incorrect and correct it. It is also
    necessary to re-check your hand calculations.
    Each time you revise your algorithm, you should walk through it with your test data again. You keep revising your algorithm until it produces the same answers as your test data.
    “Now write and submit a Java program that will calculate the cost of a rectangular window according to the algorithm explained. Be sure to prompt for input and label your output.”
    Part II
    Write, compile and execute a Java program that displays the following prompts:
    Enter an integer.
    Enter a second integer
    Enter a third integer.
    Enter a fourth integer.
    After each prompt is displayed, your program should use the nextint method of the Scanner class to accept a number from the keyboard for the displayed
    prompt. After the fourth integer has been entered, your program should calculate and display the average of the four integers and the value of the first integer entered raised to the power of the second integer entered. The average and result of raising to a power should be included in an appropriate messages
    (labels).
    Sample Test Data:
    Set 1: 100 100 100 100
    Set 2: 100 0 100 0
    Be sure to write an algorithm first before attempting to write the Java code. Walk through your algorithm with test data to be sure it works as anticipated.So this is where you actually have to do something. My guess is that you've done nothing so far.
    Part III
    Repeat Part lI but only calculate the average, not the power. This time, make sure to use the same variable name, number, for each of the four numbers input. Also use the variable sum for the sum of the numbers. (Hint: To do this, you may use the statement sum = sum + number after each number is read.)Man, this specification writes itself. Sit down and start coding.
    One bit of advice: Nobody here takes kindly to lazy, stupid students who are just trying to con somebody into doing their homework for them. If that's you, better have your asbestos underpants on.
    %

  • Need help with method... wrote an addition program... have most of it

    Writing an addition program... have most of it below. Need help in getting the program to work.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Ch10program2 extends JFrame implements ActionListener
    private static final int FRAME_WIDTH = 750;
    private static final int FRAME_HEIGHT = 150;
    private static final int BUTTON_HEIGHT = 50;
    private static final int BUTTON_WIDTH = 50;
    private static final int BUTTON_Y_POSITION = 50;
    private static final String EMPTY_STRING = "";
    private int XbuttonPosition = 15;
    private JButton[] button;
    private String[] buttonLabels = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "=", "c"};
    private JTextField mytextfield;
    private int[] numberOne;
    private int[] numberTwo;
    private int[] sum;
    private int numberCounter = 0;
    private boolean adding = false;
    public static void main (String[] args)
    Ch10program2 frame = new Ch10program2 ();
    frame.setVisible (true);
    public Ch10program2 ()
    Container contentPane = getContentPane ();
    // set the frame properties
    setSize (FRAME_WIDTH, FRAME_HEIGHT);
    setLocation (200, 200);
    setTitle ("Big Integer Adder");
    setResizable (false);
    //set the content pane properties
    contentPane.setLayout (null);
    //creating each button
    button = new JButton [13];
    for (int i = 0 ; i < button.length ; i++)
    button = new JButton (buttonLabels [i]);
    button [i].setBounds (XbuttonPosition, BUTTON_Y_POSITION, BUTTON_WIDTH, BUTTON_HEIGHT);
    XbuttonPosition += 55;
    button [i].setForeground (Color.blue);
    if (i > 9)
    button [i].setForeground (Color.red);
    contentPane.add (button [i]);
    button [i].addActionListener (this);
    //set the arrays
    numberOne = new int [50];
    numberTwo = new int [50];
    //set the needed textfield
    mytextfield = new JTextField ("");
    mytextfield.setBounds (10, 10, 720, 25);
    mytextfield.setBorder (BorderFactory.createLoweredBevelBorder ());
    mytextfield.setHorizontalAlignment (JTextField.RIGHT);
    contentPane.add (mytextfield);
    setDefaultCloseOperation (EXIT_ON_CLOSE);
    public void actionPerformed (ActionEvent event)
    JButton clickedButton = (JButton) event.getSource ();
    String oldText = mytextfield.getText ();
    if ((event.getActionCommand ()).equals ("+"))
    mytextfield.setText (oldText + " + ");
    adding = true;
    numberCounter = 0;
    else if ((event.getActionCommand ()).equals ("="))
    mytextfield.setText (oldText + " = ");
    addArrays ();
    displayArray ();
    else if ((event.getActionCommand ()).equals ("c"))
    clearText ();
    else if (adding == false)
    mytextfield.setText (oldText + event.getActionCommand ());
    if (numberCounter == 0)
    numberOne [numberCounter] = Integer.parseInt (event.getActionCommand ());
    else
    for (int i = numberOne.length - 1 ; i > 0 ; i--)
    numberOne [i] = numberOne [i - 1];
    numberOne [0] = Integer.parseInt (event.getActionCommand ());
    numberCounter++;
    else
    mytextfield.setText (oldText + event.getActionCommand ());
    if (numberCounter == 0)
    numberTwo [numberCounter] = Integer.parseInt (event.getActionCommand ());
    else
    for (int i = numberTwo.length - 1 ; i > 0 ; i--)
    numberTwo [i] = numberTwo [i - 1];
    numberTwo [0] = Integer.parseInt (event.getActionCommand ());
    numberCounter++;
    oldText = mytextfield.getText ();
    public void addArrays ()
    int temp = 0;
    int carriedDigit = 0;
    for (int i = 0 ; i < 50 ; i++)
    temp = carriedDigit + numberOne [i] + numberTwo [i];
    if (temp > 10)
    sum [i] = (temp - 10);
    carriedDigit = 1;
    else
    sum [i] = temp;
    public void displayArray ()
    private void clearText ()
    mytextfield.setText (EMPTY_STRING);

    I don't know what you want to do
    but i have taken your program to get the GUI then the logic is your's
    You try solving it.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Ch10program2 extends JFrame implements ActionListener
    private static final int FRAME_WIDTH = 750;
    private static final int FRAME_HEIGHT = 150;
    private static final int BUTTON_HEIGHT = 50;
    private static final int BUTTON_WIDTH = 50;
    private static final int BUTTON_Y_POSITION = 50;
    private static final String EMPTY_STRING = "";
    private int XbuttonPosition = 15;
    private JButton[] button;
    private String[] buttonLabels = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "=", "c"};
    private JTextField mytextfield;
    private int[] numberOne;
    private int[] numberTwo;
    private int[] sum;
    private int numberCounter = 0;
    private boolean adding = false;
    public static void main (String[] args)
    Ch10program2 frame = new Ch10program2 ();
    frame.setVisible (true);
    public Ch10program2 ()
    Container contentPane = getContentPane ();
    // set the frame properties
    setSize (FRAME_WIDTH, FRAME_HEIGHT);
    setLocation (200, 200);
    setTitle ("Big Integer Adder");
    setResizable (false);
    //set the content pane properties
    contentPane.setLayout (null);
    //creating each button
    button = new JButton [13];
    for (int i = 0 ; i < button.length ; i++)
    button[i] = new JButton (buttonLabels);
    button[i].setBounds (XbuttonPosition, BUTTON_Y_POSITION, BUTTON_WIDTH, BUTTON_HEIGHT);
    XbuttonPosition += 55;
    button[i].setForeground (Color.blue);
    if (i > 9)
    button[i].setForeground (Color.red);
    contentPane.add (button[i]);
    button[i].addActionListener (this);
    //set the arrays
    numberOne = new int [50];
    numberTwo = new int [50];
    //set the needed textfield
    mytextfield = new JTextField ("");
    mytextfield.setBounds (10, 10, 720, 25);
    mytextfield.setBorder (BorderFactory.createLoweredBevelBorder ());
    mytextfield.setHorizontalAlignment (JTextField.RIGHT);
    contentPane.add (mytextfield);
    setDefaultCloseOperation (EXIT_ON_CLOSE);
    public void actionPerformed (ActionEvent event)
    JButton clickedButton = (JButton) event.getSource ();
    String oldText = mytextfield.getText ();
    if ((event.getActionCommand ()).equals ("+"))
    mytextfield.setText (oldText + " + ");
    adding = true;
    numberCounter = 0;
    else if ((event.getActionCommand ()).equals ("="))
    mytextfield.setText (oldText + " = ");
    addArrays ();
    displayArray ();
    else if ((event.getActionCommand ()).equals ("c"))
    clearText ();
    else if (adding == false)
    mytextfield.setText (oldText + event.getActionCommand ());
    if (numberCounter == 0)
    numberOne [numberCounter] = Integer.parseInt (event.getActionCommand ());
    else
    for (int i = numberOne.length - 1 ; i > 0 ; i--)
    numberOne[i] = numberOne [i - 1];
    numberOne [0] = Integer.parseInt (event.getActionCommand ());
    numberCounter++;
    else
    mytextfield.setText (oldText + event.getActionCommand ());
    if (numberCounter == 0)
    numberTwo [numberCounter] = Integer.parseInt (event.getActionCommand ());
    else
    for (int i = numberTwo.length - 1 ; i > 0 ; i--)
    numberTwo[i] = numberTwo [i - 1];
    numberTwo [0] = Integer.parseInt (event.getActionCommand ());
    numberCounter++;
    oldText = mytextfield.getText ();
    public void addArrays ()
    int temp = 0;
    int carriedDigit = 0;
    for (int i = 0 ; i < 50 ; i++)
    temp = carriedDigit + numberOne[i] + numberTwo[i] ;
    if (temp > 10)
    sum[i] = (temp - 10);
    carriedDigit = 1;
    else
    sum[i] = temp;
    public void displayArray ()
    private void clearText ()
    mytextfield.setText (EMPTY_STRING);
    All The Best

  • New Java Programming Student Needs Help

    Hey everyone,
    I've just started taking a Java programming class at Penn State University, and I have had some prior experience with programming, i.e. C, C++, HTML, SQL. However, this will be my first attempt at Java. I know there are a lot of similarities between C++ and Java, but I'm still a little lost on some methodology.
    To get myself going, I've been looking through the textbook a little and came across a problem that gave me some difficulty. I'll write out the outline:
    A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and time and a half (i.e. 1.5 times their hourly wage) for overtime hours worked, commission workers (who receive $250 plus 5.7% of their gross weekly sales), and pieceworkers (who receive a fixed amount of money per item for each of the items they produce � each pieceworker in this company works on only one type of item).
    +Define a Java class named EmployeePayment that includes functionality to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code: Managers have paycode 1, hourly workers have paycode 2, commission workers have paycode 3 and pieceworkers have paycode 4.+
    +Define a main method that creates an instance of the EmployeePayment class, and calls the setManagerPay method to set the managers weekly salary to $625.00. The main method should then prompt the user for the paycode ��Enter paycode (-1 to end): �, validate the input and perform the associated processing for that paycode. Your program should allow the user to process employees until a paycode of -1 has been entered. Use a switch structure to compute each employee�s pay, based on the employee�s paycode. Within the switch, prompt the user (i.e. the payroll clerk) to enter the appropriate facts your program needs to calculate each employee�s pay based on that employee�s paycode, invoke the respective method (defined below) to perform the calculations and return the weekly pay for each type of employee, and print the returned weekly pay for each employee.+
    +Define a setManagerPay method that accepts and stores the fixed weekly salary value for managers.+
    +A private instance variable weeklyManagerPay should be defined in the EmployeePayment class to support these accessor and mutator methods.+
    +Define a calcManagerPay method that has no parameters and returns the fixed weekly salary.+
    +Define a calcHourlyWorkerPay method that accepts the hourly salary and total hours worked as input parameters and returns the weekly pay based on the hourly worker pay code description.+
    +Define a calcCommWorkerPay method that accepts the gross weekly sales as an input parameter and returns the weekly pay based on the commission worker pay code description.+
    +Define a calcPieceWorkerPay method that accepts the number of pieces and wage per piece as input parameters and returns the weekly pay based on the piece worker pay code description.+
    +Once all workers have been processed, the total number of each type of employee processed should be printed. Define and manage the following private instance variables (*numManager*, numHourlyWorker, numCommWorker, and numPieceWorker) within the EmployeePayment class. What are the ways in which these variables can be updated?+
    Sorry for the length, but I wanted this to be thorough. Basically, I'm having the most trouble writing the switch statement, and outputting the total number of each type of employee...
    Any help and pointers will be greatly appreciated...thanks all.

    You said you've written C and C++ code before. I don't have an excellent memory but from the little code that I wrote in C, I believe the switch statement is exactly the same.
    Read this: [http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html]
    If you're having trouble understanding something post what your specific problem is. No one is going to write your homework for you, but many, myself included, would be more than willing to help if you're really stumped. Just post your concise problem.
    Edited by: sheky on Mar 12, 2008 9:52 PM

  • Need help with a simple program (should be simple anyway)

    I'm (starting to begin) writing a nice simple program that should be easy however I'm stuck on how to make the "New" button in the file menu clear all the fields. Any help? I'll attach the code below.
    ====================================================
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Message extends JFrame implements ActionListener {
         public void actionPerformed(ActionEvent evt) {
         text1.setText(" ");
         text2.setText("RE: ");
         text3.setText(" ");
         public Message() {
         super("Write a Message - by Kieran Hannigan");
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setSize(370,270);
         FlowLayout flo = new FlowLayout(FlowLayout.RIGHT);
         setLayout(flo);
         //Make the bar
         JMenuBar bar = new JMenuBar();
         //Make "File" on Menu
         JMenu File = new JMenu("File");
         JMenuItem f1 = new JMenuItem("New");f1.addActionListener(this);
         JMenuItem f2 = new JMenuItem("Open");
         JMenuItem f3 = new JMenuItem("Save");
         JMenuItem f4 = new JMenuItem("Save As");
         JMenuItem f5 = new JMenuItem("Exit");
         File.add(f1);
         File.add(f2);
         File.add(f3);
         File.add(f4);
         File.add(f5);
         bar.add(File);
         //Make "Edit" on menu
         JMenu Edit = new JMenu("Edit");
         JMenuItem e1 = new JMenuItem("Cut");
         JMenuItem e2 = new JMenuItem("Paste");
         JMenuItem e3 = new JMenuItem("Copy");
         JMenuItem e4 = new JMenuItem("Repeat");
         JMenuItem e5 = new JMenuItem("Undo");
         Edit.add(e5);
         Edit.add(e4);
         Edit.add(e1);
         Edit.add(e3);
         Edit.add(e2);
         bar.add(Edit);
         //Make "View" on menu
         JMenu View = new JMenu("View");
         JMenuItem v1 = new JMenuItem("Bold");
         JMenuItem v2 = new JMenuItem("Italic");
         JMenuItem v3 = new JMenuItem("Normal");
         JMenuItem v4 = new JMenuItem("Bold-Italic");
         View.add(v1);
         View.add(v2);
         View.add(v3);
         View.addSeparator();
         View.add(v4);
         bar.add(View);
         //Make "Help" on menu
         JMenu Help = new JMenu("Help");
         JMenuItem h1 = new JMenuItem("Help Online");
         JMenuItem h2 = new JMenuItem("E-mail Programmer");
         Help.add(h1);
         Help.add(h2);
         bar.add(Help);
         setJMenuBar(bar);
         //Make Contents of window.
         //Make "Subject" text field
         JPanel row2 = new JPanel();
         JLabel sublabel = new JLabel("Subject:");
         row2.add(sublabel);
         JTextField text2 = new JTextField("RE:",24);
         row2.add(text2);
         //Make "To" text field
         JPanel row1 = new JPanel();
         JLabel tolabel = new JLabel("To:");
         row1.add(tolabel);
         JTextField text1 = new JTextField(24);
         row1.add(text1);
         //Make "Message" text area
         JPanel row3 = new JPanel();
         JLabel Meslabel = new JLabel("Message:");
         row3.add(Meslabel);
         JTextArea text3 = new JTextArea(6,22);
         messagearea.setLineWrap(true);
         messagearea.setWrapStyleWord(true);
         JScrollPane scroll = new JScrollPane(text3,
                                  JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
         //SpaceLine
         JPanel spaceline = new JPanel();
         JLabel spacer = new JLabel(" ");
         spaceline.add(spacer);
         row3.add(scroll);
         add(row1);
         add(row2);
         add(spaceline);
         add(spaceline);
         add(row3);
         setVisible(true);
         public static void main(String[] arguments) {
         Message Message = new Message();
    }

    persiandude wrote:
    Topic: Need help with if, else, and which statements and loops.
    How would I display 60 < temp. <= 85 in java
    System.out.println("60 < temp. <= 85 in java");
    another question is how do I ask a question like want to try again (y/n) after a output and asking that everytime I type in yes after a output and terminate when saying No.Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
    Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    [http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
    Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
    Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
    James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806].

Maybe you are looking for

  • Help with a update query

    This query only works if it return one row. But sometimes it returns more than one row, then I get error: "ORA-01427: single-row subquery returns more than one row" How can I solve that? If it reurns more than one row, it should update all rows. UPDA

  • Ipad synchronisation?

    I have just re installed itunes on my HP laptop (Windows XP) because initially, my itunes could not access itunes store. Now, when I connect my ipad to my laptop, it gives me this message. ' This ipad cannot be used because the required software is n

  • HR-ABAP Need ful documents

    HI Guru's, I have expirence in Normal ABAP . Now I looking to move to HR-ABAP side . can please send any documents regarding HR-ABAP. I mean to say  From whare i need to start and which topics I need to strong..... Regards, Raju.

  • DVCPROHD Audio Plugin Failure

    I couldn't find a place where this really fit-it's an audio plugin question, but I don't use the Pro Software-so I put it in the general OSX category; feel free to move it. My issue is with the DVC PRO HD Audio plugin (/Library/Audio/Plug-Ins/HAL/DVC

  • IPod as recorder

    Is tunetalk as good as the real recorder? I wanna buy iPod+tunetalk as recorder so that I can record large amount of lecutres without deleting the old ones. Is it a good idea? thx