Help debugging my program, please

--------------------Configuration: <Default>--------------------
C:\Java\Java Docs\DeleteSpaces.java:18: ';' expected
^
1 error
Process completed.
import java.io.*;
public class DeleteSpaces
     public static void main (String[] args)
          FileReader inputFile = new File("Omerta.txt");
          FileReader outputFile = new File("omertaEdited.txt");
          FileReader in = new FileReader(inputFile);
          FileWriter out = new FileWriter(outputFile);
     public static void Spaces (String[] args)
     try     
          BufferedReader In = new BufferedReader(new FileReader("Omerta.txt"));
          BufferedWriter Out = new BufferedWriter(new FileWriter("OmertaEdited.txt"));
          String str;
     while ((str=in.readLine()) != null)
          while(st.indexOf("  ") > -1)
               line = line.replaceAll("  ", " ");
               out.println(line);
     in.close();
     out.close();
          catch (IOException e)
          System.err.println(e);
          System.exit(1);
}now ive been told that the "try" is confusing the compiler......but what im not sure is how i would fix this........and please give me any other tips as to fixing this up

Hi,
I hv two suggestions,
from where u hv called the function spaces from the main() ?,of course u didnt
put a open brace after
public static void Spaces (String[] args)like
public static void Spaces (String[] args)  { Regards
-John-

Similar Messages

  • Need some help with a program Please.

    Well, im new here, im new to java, so i need your help, i have to make a connect four program, my brother "Kind of" helped me and did a program for me, but the problem is i cant use some of those commands in the program and i have to replace them with what ive learned, so i will post the program and i will need your help to modify it for me.
    and for these programs, also i want help for:
    They have errors and i cant fix'em
    the commands that i've leaned:
    If statements, for loops, while loops,do while, strings, math classes, swithc statement, else if,logical operators,methods, one and two dimensional arrays.
    Thanx in advance,
    truegunner
    // Fhourstones 3.0 Board Logic
    // Copyright 2000-2004 John Tromp
    import java.io.*;
    class Connect4 {
    static long color[]; // black and white bitboard
    static final int WIDTH = 7;
    static final int HEIGHT = 6;
    // bitmask corresponds to board as follows in 7x6 case:
    // . . . . . . . TOP
    // 5 12 19 26 33 40 47
    // 4 11 18 25 32 39 46
    // 3 10 17 24 31 38 45
    // 2 9 16 23 30 37 44
    // 1 8 15 22 29 36 43
    // 0 7 14 21 28 35 42 BOTTOM
    static final int H1 = HEIGHT+1;
    static final int H2 = HEIGHT+2;
    static final int SIZE = HEIGHT*WIDTH;
    static final int SIZE1 = H1*WIDTH;
    static final long ALL1 = (1L<<SIZE1)-1L; // assumes SIZE1 < 63
    static final int COL1 = (1<<H1)-1;
    static final long BOTTOM = ALL1 / COL1; // has bits i*H1 set
    static final long TOP = BOTTOM << HEIGHT;
    int moves[],nplies;
    byte height[]; // holds bit index of lowest free square
    public Connect4()
    color = new long[2];
    height = new byte[WIDTH];
    moves = new int[SIZE];
    reset();
    void reset()
    nplies = 0;
    color[0] = color[1] = 0L;
    for (int i=0; i<WIDTH; i++)
    height[i] = (byte)(H1*i);
    public long positioncode()
    return 2*color[0] + color[1] + BOTTOM;
    // color[0] + color[1] + BOTTOM forms bitmap of heights
    // so that positioncode() is a complete board encoding
    public String toString()
    StringBuffer buf = new StringBuffer();
    for (int i=0; i<nplies; i++)
    buf.append(1+moves);
    buf.append("\n");
    for (int w=0; w<WIDTH; w++)
    buf.append(" "+(w+1));
    buf.append("\n");
    for (int h=HEIGHT-1; h>=0; h--) {
    for (int w=h; w<SIZE1; w+=H1) {
    long mask = 1L<<w;
    buf.append((color[0]&mask)!= 0 ? " @" :
    (color[1]&mask)!= 0 ? " 0" : " .");
    buf.append("\n");
    if (haswon(color[0]))
    buf.append("@ won\n");
    if (haswon(color[1]))
    buf.append("O won\n");
    return buf.toString();
    // return whether columns col has room
    final boolean isplayable(int col)
    return islegal(color[nplies&1] | (1L << height[col]));
    // return whether newboard lacks overflowing column
    final boolean islegal(long newboard)
    return (newboard & TOP) == 0;
    // return whether newboard is legal and includes a win
    final boolean islegalhaswon(long newboard)
    return islegal(newboard) && haswon(newboard);
    // return whether newboard includes a win
    final boolean haswon(long newboard)
    long y = newboard & (newboard>>HEIGHT);
    if ((y & (y >> 2*HEIGHT)) != 0) // check diagonal \
    return true;
    y = newboard & (newboard>>H1);
    if ((y & (y >> 2*H1)) != 0) // check horizontal -
    return true;
    y = newboard & (newboard>>H2); // check diagonal /
    if ((y & (y >> 2*H2)) != 0)
    return true;
    y = newboard & (newboard>>1); // check vertical |
    return (y & (y >> 2)) != 0;
    void backmove()
    int n;
    n = moves[--nplies];
    color[nplies&1] ^= 1L<<--height[n];
    void makemove(int n)
    color[nplies&1] ^= 1L<<height[n]++;
    moves[nplies++] = n;
    public static void main(String argv[])
    Connect4 c4;
    String line;
    int col=0, i, result;
    long nodes, msecs;
    c4 = new Connect4();
    c4.reset();
    BufferedReader dis = new BufferedReader(new InputStreamReader(System.in));
    for (;;) {
    System.out.println("position " + c4.positioncode() + " after moves " + c4 + "enter move(s):");
    try {
    line = dis.readLine();
    } catch (IOException e) {
    System.out.println(e);
    System.exit(0);
    return;
    if (line == null)
    break;
    for (i=0; i < line.length(); i++) {
    col = line.charAt(i) - '1';
    if (col >= 0 && col < WIDTH && c4.isplayable(col))
    c4.makemove(col);
    By the way im using Ready to program for the programming.

    You can't really believe that his brother did this
    for him...I did miss that copyright line at the beginning when
    I first looked it over, but you know, if it had been
    his brother, I'd be kinda impressed. This wasn't a
    25 line program. It actually would have required
    SOME thought. I doubt my brother woulda done that
    for me (notwithstanding the fact that I wouldn't need
    help for that program, and my brother isn't a
    programmer).I originally missed the comments at the top but when I saw the complexity of what was written then I knew that it was too advanced for a beginner and I relooked through the code and saw the comments.

  • Help with a program please

    I am very new to java and working on a program for class.... The program must take a variable x and run it through a given function and the output is a number such as 8.234141... In the end i have to take that result and have two statements print to the screen telling how many digits are on the left and how many are on the right of the decimal. I have done all except the last part the hint given is to convert the double variable into a string variable and use the indexOf() method...here is my program so far. Thanks in advance for your help
    import java.util.Scanner;
    public class Project3 {
    public static void main(String[] args)
    //Declaring my variables
    double x, result, result1, result2, result3;
    //User input of variable 'x'
    Scanner scan = new Scanner (System.in);
    System.out.println("Please enter the value for x: ");
    x = scan.nextDouble();
         //Calculations for final answer
    result1 = (Math.abs(Math.pow(x, 3)-(3 * Math.pow(x, 4))));
    result2 = result1 + (8 * Math.pow(x, 2) + 1);
    result3 = Math.sqrt(result2);
    System.out.println("Result is: " + result3);      
    }

    So let me get this straight... the program is supposed to receive user input, run some arbitrary formula on it, and print the results, and then say how many digits are on the left and right of the decimal?
    If this is the case, I'll give you a few hints:
    ~~
    1) To convert a double to a string , you can do something like this:
    String myString = "" + myDouble; // the "" is a pair of empty quotation marks.
    2) the String class contains the method indexOf(), which searches the string for another string, and returns the index. For example:
    String aString = "Hello, world!";
    int anIndex = aString.indexOf("w");
    anIndex will be equal to the number 7 because the "w" in aString is character number 7 (the first character is number 0, the second is 1, and so on.)
    3) the String class contains the method length() which returns the length of the string.
    ~~
    Think about these things, and if you still can't figure it out, let me know.
    Edited by: Arricherekk on Sep 14, 2008 12:26 PM

  • I need help with a program please

    hi, well, i am trying to make a mine searcher (the game where you have to find all the mines within an array of buttons)anyway,i got everything but i am trying to create a method that allows to unable the buttons surrounding a button that was pressed that didn�t have any mines surrounding it (i am sorry if i am being a little confusing, my english is not very good). anyway, i have the following code for that method, but it isn�t working, please if someone can see what the problem is, send me an answer.
    (alrededores is a method that returns the number of mines surrounding the position auxiliar[i][j])
    public void destapar(boolean [][] auxiliar,int ancho, int largo, int i, int j){
         if(alrededores(auxiliar,ancho,largo,i,j)!=0){
              casilla[i][j].setLabel(""+alrededores(minados,ancho,largo,aux,j));
              casilla[i][j].setEnabled(false);
              casilla[i][j].setBackground(new Color(255,255,255));
              return;}
         else{          
              casilla[i][j].setLabel("");
              casilla[i][j].setEnabled(false);
              casilla[i][j].setBackground(new Color(255,255,255));}
         if(i>0)     
              destapar(auxiliar,ancho,largo,i-1,j);
         if(i<ancho-1)
              destapar(auxiliar,ancho,largo,i+1,j);
         if(j>0)
              destapar(auxiliar,ancho,largo,i,j-1);
         if(j<largo-1)
              destapar(auxiliar,ancho,largo,i,j+1);
    }

    I programmed MineSweeper for my TI-83 back in highschool. You should be able to knock this out of the park.
    i would use a one dimensional array and transform the 2d position.
    have one one-dim array hold the "mines surrounding value" and one other one-dim array hold the state: "not hit" "hit" "exploded" etc.
    I wouldnt dar make the board out of actual buttons. Use a tiled board of .png's or draw the board. Use the mouse location and range and divide by the number of mines to find out where the use clicked.
    For example:
    Board is from x = 100 to x = 200
    Each tile is dx = 10 -> 10 tiles
    user hit mouse location x = 105;
    (105 - 100) / 10 = tilePosX
    for surrounding mines array its just brute force.
    fill the mine field at random (thats why the one-dim array helps among other reasons). Then just iterate through adding up mines surrounding it.

  • Plese help debug that program

    Please help me debugthis project... I am still working on it but don't see yet why it did not compile (with Netbeans IDE).
    It is a Java applet that allows the user to pick 3 dinner menu items
    from a choice of 3 different groups, choosing only one item from each
    group. The total will change as each selection is made.
    The user shouldn't be able to choose more than one item from the same
    group and the item prices shouldn't be visible to the user.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    /*Rulx Narcisse
      [email protected]
    public class Menu extends Applet implements ItemListener
    //All the labels of the program are here...
    Label intro=new Label("Dinner Menu");
    Label intro2=new Label("Please select one item from each category, Your total will be display below.");
    Label soups=new Label("Soups---------------");
    Label entree=new Label ("Entrees-------------");
    Label desserts=new Label("Desserts------------");
    Label dinnerPrice=new Label("Dinner Price is $");
    Label point=new Label(".");
    //Creation of Font objects
    Font bigFontIntro=new Font("Arial", Font.REGULAR, 28);
    Font fontIntro2=new Font("Arial", Font.REGULAR, 16);
    Font fontMenuItem=new Font("Arial", Font.BOLT, 14);
    //Creation of the groups for the menu
    CheckboxGroup soupsGrp = new CheckboxGroup();//Soup Group
    Checkbox clamChowder = new Checkbox("Clam Chowder", true, soupsGrp);
    Checkbox vegetableSoup = new Checkbox("Vegetabale Soup", false, soupsGrp);
    Checkbox pepperedChickenBroth = new Checkbox("Peppered Chicken Broth", false, soupsGrp);
    CheckboxGroup entreeGrp = new CheckboxGroup();//Entree Group
    Checkbox chicken = new Checkbox("Chicken", true, entreeGrp);
    Checkbox fish = new Checkbox("Fish", false, entreeGrp);
    Checkbox beef = new Checkbox("Beef", false, entreeGrp);
    CheckboxGroup dessertsGrp = new CheckboxGroup();//Desserts Group
    Checkbox vanillaIceCream = new Checkbox("Vanilla Ice Cream", true, dessertsGrp);
    Checkbox ricePudding = new Checkbox("Rice Pudding", false, dessertsGrp);
    Checkbox cheeseCake = new Checkbox("Cheese Cake", false, dessertsGrp);
    public void init()
    //Font objects are assigned to the Label objects at initialisation
    intro.setFont(bigFontIntro);
    add(intro);
    intro2.setFont(fontIntro2);
    add(intro2);
    soups.setFont(fontMenuItem);
    entree.setFont(fontMenuItem);
    desserts.setFont(fontMenuItem);
    dinnerPrice.setFont(fontMenuItem);
    point.setFont(fontMenuItem);
    //The variable for the prices
    int clamChowderPrice=279, vegetableSoupPrice=299, pepperedChickenBrothPrice=249, chickenPrice=1279, fishPrice=1099, beefPrice=1499, vanillaIceCreamPrice=279, ricePuddingPrice=299, cheeseCakePrice=429, totalPrice=0, cents, dollars;
    add(soups); //The Label object soups is added
    //Menu item for the soup group
    add(clamChowder);
    clamChowder.addItemListener(this);
    add(vegetableSoup);
    vegetableSoup.additemListener(this);
    add(pepperedChickenBroth);
    pepperedChickenBroth.addItemListener(this);
    add(entree);//The Label object entree is added
    //Menu item for the entree group
    add(chicken);
    chicken.addItemListener(this);
    add(fish);
    fish.addItemListener(this);
    add(beef);
    beef.addItemListener(this);
    add(desserts);//The Label object desserts is added
    //Menu item for the desserts group
    add(vanillaIceCream);
    vanillaIceCream.addItemListener(this);
    add(ricePudding);
    ricePudding.addItemListener(this);
    add(cheeseCake);
    cheeseCake.addItemListener(this);
    /*Here is the itemStateChanged method that will be executed
    when user change status of checkboxes of the ItemListeners*/
    public void itemStateChanged(ItemEvent check)
    totalPrice=0;
    //compute for the first group (soup)
    Checkbox soupSelection = soupsGrp.getSelectedCheckedbox();
    if(soupSelection==clamChowder)
    totalPrice +=clamChowderPrice;
    else if(soupSelection==vegetableSoup)
    totalPrice +=vegetalbeSoupPrice;
    else
    totalPrice +=pepperedChickenBrothPrice;
    //compute for the second group (entree)
    Checkbox entreeSelection = entreeGrp.getSelectedCheckedbox();
    if(entreeSelection==chicken)
    totalPrice +=chickenPrice;
    else if(entreeSelection==fish)
    totalPrice +=fishPrice;
    else
    totalPrice +=beefPrice;
    //compute for the third group (desserts)
    Checkbox dessertsSelection = dessertsGrp.getSelectedCheckedbox();
    if(dessertsSelection==vanillaIceCream)
    totalPrice +=vanillaPrice;
    else if(dessertsSelection==ricePudding)
    totalPrice +=ricePuddingPrice;
    else
    totalPrice +=cheeseCakePrice;
    cents = totalPrice MOD 100;
    repaint();//to display new figures on the screen.
    add(dinnerPrice);//The Label object dinnerprice is added
    add(totalprice);
    add(point);
    add(cents);
    }

    Try this....this still needs a LOT A LOT A LOT of work.
    But at least it runs and does what I think it should.
    import java.applet.Applet;
    import java.awt.Checkbox;
    import java.awt.CheckboxGroup;
    import java.awt.Font;
    import java.awt.Label;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    /*Rulx Narcisse
    [email protected]
    public class Morgen extends Applet implements ItemListener
        int clamChowderPrice = 279;
        int vegetableSoupPrice = 299;
        int pepperedChickenBrothPrice = 249;
        int chickenPrice = 1279;
        int fishPrice = 1099;
        int beefPrice = 1499;
        int vanillaIceCreamPrice = 279;
        int ricePuddingPrice = 299;
        int cheeseCakePrice = 429;
        int totalPrice = 0;
        int cents;
        int dollars;
        //All the labels of the program are here...
        Label intro = new Label( "Dinner Menu" );
        Label intro2 = new Label(
            "Please select one item from each category, Your total will be display below." );
        Label soups = new Label( "Soups---------------" );
        Label entree = new Label( "Entrees-------------" );
        Label desserts = new Label( "Desserts------------" );
        Label dinnerPrice = new Label( "Dinner Price is $" );
        Label point = new Label( "." );
        Label price = new Label( "." );
        //Creation of Font objects
        Font bigFontIntro = new Font( "Arial", Font.PLAIN, 28 );
        Font fontIntro2 = new Font( "Arial", Font.PLAIN, 16 );
        Font fontMenuItem = new Font( "Arial", Font.BOLD, 14 );
        //Creation of the groups for the menu
        CheckboxGroup soupsGrp = new CheckboxGroup();//Soup Group
        Checkbox clamChowder = new Checkbox( "Clam Chowder", true, soupsGrp );
        Checkbox vegetableSoup = new Checkbox( "Vegetabale Soup", false, soupsGrp );
        Checkbox pepperedChickenBroth = new Checkbox( "Peppered Chicken Broth",
            false, soupsGrp );
        CheckboxGroup entreeGrp = new CheckboxGroup();//Entree Group
        Checkbox chicken = new Checkbox( "Chicken", true, entreeGrp );
        Checkbox fish = new Checkbox( "Fish", false, entreeGrp );
        Checkbox beef = new Checkbox( "Beef", false, entreeGrp );
        CheckboxGroup dessertsGrp = new CheckboxGroup();//Desserts Group
        Checkbox vanillaIceCream = new Checkbox( "Vanilla Ice Cream", true,
            dessertsGrp );
        Checkbox ricePudding = new Checkbox( "Rice Pudding", false, dessertsGrp );
        Checkbox cheeseCake = new Checkbox( "Cheese Cake", false, dessertsGrp );
        public void init()
            //Font objects are assigned to the Label objects at initialisation
            intro.setFont( bigFontIntro );
            add( intro );
            intro2.setFont( fontIntro2 );
            add( intro2 );
            soups.setFont( fontMenuItem );
            entree.setFont( fontMenuItem );
            desserts.setFont( fontMenuItem );
            dinnerPrice.setFont( fontMenuItem );
            point.setFont( fontMenuItem );
            //The variable for the prices
            add( soups ); //The Label object soups is added
            //Menu item for the soup group
            add( clamChowder );
            clamChowder.addItemListener( this );
            add( vegetableSoup );
            vegetableSoup.addItemListener( this );
            add( pepperedChickenBroth );
            pepperedChickenBroth.addItemListener( this );
            add( entree );//The Label object entree is added
            //Menu item for the entree group
            add( chicken );
            chicken.addItemListener( this );
            add( fish );
            fish.addItemListener( this );
            add( beef );
            beef.addItemListener( this );
            add( desserts );//The Label object desserts is added
            //Menu item for the desserts group
            add( vanillaIceCream );
            vanillaIceCream.addItemListener( this );
            add( ricePudding );
            ricePudding.addItemListener( this );
            add( cheeseCake );
            cheeseCake.addItemListener( this );
            add( price );
        /*Here is the itemStateChanged method that will be executed
         when user change status of checkboxes of the ItemListeners*/
        public void itemStateChanged(ItemEvent check)
            int totalPrice = 0;
            //compute for the first group (soup)
            Checkbox soupSelection = soupsGrp.getSelectedCheckbox();
            if ( soupSelection == clamChowder )
                totalPrice += clamChowderPrice;
            else if ( soupSelection == vegetableSoup )
                totalPrice += vegetableSoupPrice;
            else
                totalPrice += pepperedChickenBrothPrice;
            //compute for the second group (entree)
            Checkbox entreeSelection = entreeGrp.getSelectedCheckbox();
            if ( entreeSelection == chicken )
                totalPrice += chickenPrice;
            else if ( entreeSelection == fish )
                totalPrice += fishPrice;
            else
                totalPrice += beefPrice;
            //compute for the third group (desserts)
            Checkbox dessertsSelection = dessertsGrp.getSelectedCheckbox();
            if ( dessertsSelection == vanillaIceCream )
                totalPrice += vanillaIceCreamPrice;
            else if ( dessertsSelection == ricePudding )
                totalPrice += ricePuddingPrice;
            else
                totalPrice += cheeseCakePrice;
            cents = totalPrice % 100;
            price.setText( totalPrice + "" );
            repaint();//to display new figures on the screen.
    }

  • Help With Java Program Please!

    Greetings,
    I am trying to figure out to write a Java program that will read n lines of text from the keyboard until a blank line is read. And as it read each line, It's suppose to keep track of
    The longest string so far
    The Longest word seen so far
    The line that contains the most words
    The total number of words seen in all lines
    I don't know where to begin. Help me please! Thank you very much.

    Man I have to say that this smells like home work.
    Since you have not asked for a cut paste code I tell you what to do
    1. Write a function which take single string as a parameter and break it down to words and return words as a array or string
    (You can use this)
    you will need several variables to keep track of
    The longest string so far
    The Longest word seen so far
    The line that contains the most words and number of words in that line
    The total number of words seen in all lines
    now read lines in a loop if the length is 0 exit (that is your exis condition right)
    otherwise check the length of input string and update "The longest string so far"
    then break down the words and update "The Longest word seen so far", "The line that contains the most words and number of words in that line" and "The total number of words seen in all lines"
    and when you are exiting display the above values

  • Help with simple program please!

    Hi. I am brand new to Java and pretty new to programming in general. I am writing a project for a class where we have to output the index at which a certain "target" string matches the "source" string. I'm stuck. I thought my code would make "compare" a string of length target.length()? Any help is greatly appreciated. Thanks!
    public static ArrayList<Integer> matches(String source, String target) {
    // check preconditions
    assert (source != null) && (source.length() > 0)
         && (target != null) && (target.length() > 0): "matches: violation of precondition";
    ArrayList<Integer> result = new ArrayList<Integer>();
    String compare = "";
    for (int i=0; i<source.length()-target.length()+1;i++){
         int count = 0;
         for (int k=i; k<i+target.length(); k++){
              compare = compare + source.charAt(k);
         for (int j=0; j<target.length(); j++){
              if (target.charAt(j) == compare.charAt(j)){
                   count ++;
         if (count == target.length()){
              result.add(i);
              return result;
    }

    I apologize, I am new to the forums and posted that code horribly. Here is the accurate code.
        public static ArrayList<Integer> matches(String source, String target) {
            // check preconditions
            assert (source != null) && (source.length() > 0)
                 && (target != null) && (target.length() > 0): "matches: violation of precondition";
            ArrayList<Integer> result = new ArrayList<Integer>();
            String compare = "";
            for (int i=0; i<source.length()-target.length()+1;i++){
                 int count = 0;
                 for (int k=i; k<i+target.length(); k++){
                      compare = compare + source.charAt(k);
                 for (int j=0; j<target.length(); j++){
                      if (target.charAt(j) == compare.charAt(j)){
                           count ++;
                 if (count == target.length()){
                      result.add(i);
              return result;
        }

  • Help debug the program

    i have write an java program that come out with this error, how to solve it?
    postageApplet.java:5: postageApplet should be declared abstract; it does not
    define itemStateChanged(java.awt.event.ItemEvent) in postageApplet
    public class postageApplet extends Applet implements ItemListener,ActionListener
    ^
    what does it mean by abstract here?

    You said the class implements ItemListener but you have not defined the methods for that interface. Abstract classes can have abstract methods, or methods that have a prototype but are not defined. If you made the class abstract it would compile because the methods for the interface would be considered abstract.
    To fix the problem implement the methods for the interfaces you are using.

  • Need help to draw a graph from the output I get with my program please

    Hi all,
    I please need help with this program, I need to display the amount of money over the years (which the user has to enter via the textfields supplied)
    on a graph, I'm not sure what to do further with my program, but I have created a test with a System.out.println() method just to see if I get the correct output and it looks fine.
    My question is, how do I get the input that was entered by the user (the initial deposit amount as well as the number of years) and using these to draw up the graph? (I used a button for the user to click after he/she has entered both the deposit and year values to draw the graph but I don't know how to get this to work?)
    Please help me.
    The output that I got looked liked this: (just for a test!) - basically this kind of output must be shown on the graph...
    The initial deposit made was: 200.0
    After year: 1        Amount is:  210.00
    After year: 2        Amount is:  220.50
    After year: 3        Amount is:  231.53
    After year: 4        Amount is:  243.10
    After year: 5        Amount is:  255.26
    After year: 6        Amount is:  268.02
    After year: 7        Amount is:  281.42
    After year: 8        Amount is:  295.49
    After year: 9        Amount is:  310.27
    After year: 10        Amount is:  325.78
    After year: 11        Amount is:  342.07
    After year: 12        Amount is:  359.17
    After year: 13        Amount is:  377.13
    After year: 14        Amount is:  395.99
    After year: 15        Amount is:  415.79
    After year: 16        Amount is:  436.57
    After year: 17        Amount is:  458.40And here is my code that Iv'e done so far:
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.Math;
    import java.text.DecimalFormat;
    public class CompoundInterestProgram extends JFrame implements ActionListener {
        JLabel amountLabel = new JLabel("Please enter the initial deposit amount:");
        JTextField amountText = new JTextField(5);
        JLabel yearsLabel = new JLabel("Please enter the numbers of years:");
        JTextField yearstext = new JTextField(5);
        JButton drawButton = new JButton("Draw Graph");
        public CompoundInterestProgram() {
            super("Compound Interest Program");
            setSize(500, 500);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            amountText.addActionListener(this);
            yearstext.addActionListener(this);
            JPanel panel = new JPanel();
            panel.setBackground(Color.white);
            panel.add(amountLabel);
            amountLabel.setToolTipText("Range of deposit must be 20 - 200!");
            panel.add(amountText);
            panel.add(yearsLabel);
            yearsLabel.setToolTipText("Range of years must be 1 - 25!");
            panel.add(yearstext);
            panel.add(drawButton);
            add(panel);
            setVisible(true);
            public static void main(String[] args) {
                 DecimalFormat dec2 = new DecimalFormat( "0.00" );
                CompoundInterestProgram cip1 = new CompoundInterestProgram();
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.getContentPane().add(new GraphPanel());
                f.setSize(500, 500);
                f.setLocation(200,200);
                f.setVisible(true);
                Account a = new Account(200);
                System.out.println("The initial deposit made was: " + a.getBalance() + "\n");
                for (int year = 1; year <= 17; year++) {
                      System.out.println("After year: " + year + "   \t" + "Amount is:  " + dec2.format(a.getBalance() + a.calcInterest(year)));
              @Override
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
    class Account {
        double balance = 0;
        double interest = 0.05;
        public Account() {
             balance = 0;
             interest = 0.05;
        public Account(int deposit) {
             balance = deposit;
             interest = 0.05;
        public double calcInterest(int year) {
               return  balance * Math.pow((1 + interest), year) - balance;
        public double getBalance() {
              return balance;
    class GraphPanel extends JPanel {
        public GraphPanel() {
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(Color.red);
    }Your help would be much appreciated.
    Thanks in advance.

    watertownjordan wrote:
    http://www.jgraph.com/jgraph.html
    The above is also good.Sorry but you need to look a bit more closely at URLs that you cite. What the OP wants is a chart (as in X against Y) not a graph (as in links and nodes) . 'jgraph' deals with links and nodes.
    The best free charting library that I know of is JFreeChart from www.jfree.org.

  • Help With Program Please

    Hi everybody,
    I designed a calculator, and I need help with the rest of the scientific actions. I know I need to use the different Math methods, but what exactly? Also, it needs to work as an applet and application, and in the applet, the buttons don't appear in order, how can I fix that?
    I will really appreciate your help with this program, I need to finish it ASAP. Please e-mail me at [email protected].
    Below is the code for the calcualtor.
    Thanks in advance,
    -Maria
    // calculator
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class calculator extends JApplet implements
    ActionListener
    private JButton one, two, three, four, five, six, seven,
    eight, nine, zero, dec, eq, plus, minus, mult, div, clear,
    mem, mrc, sin, cos, tan, asin, acos, atan, x2, sqrt, exp, pi, percent;
    private JLabel output, blank;
    private Container container;
    private String operation;
    private double number1, number2, result;
    private boolean clear = false;
    //GUI
    public void init()
    container = getContentPane();
    //Title
    //super("Calculator");
    JPanel container = new JPanel();     
    container.setLayout( new FlowLayout( FlowLayout.CENTER
    output = new JLabel("");     
    output.setBorder(new MatteBorder(2,2,2,2,Color.gray));
    output.setPreferredSize(new Dimension(1,26));     
    getContentPane().setBackground(Color.white);     
    getContentPane().add( "North",output );     
    getContentPane().add( "Center",container );
    //blank
    blank = new JLabel( " " );
    container.add( blank );
    //clear
    clear = new JButton( "CE" );
    clear.addActionListener(this);
    container.add( clear );
    //seven
    seven = new JButton( "7" );
    seven.addActionListener(this);
    container.add( seven );
    //eight
    eight = new JButton( "8" );
    eight.addActionListener(this);
    container.add( eight );
    //nine
    nine = new JButton( "9" );
    nine.addActionListener(this);
    container.add( nine );
    //div
    div = new JButton( "/" );
    div.addActionListener(this);
    container.add( div );
    //four
    four = new JButton( "4" );
    four.addActionListener(this);
    container.add( four );
    //five
    five = new JButton( "5" );
    five.addActionListener(this);
    container.add( five );
    //six
    six = new JButton( "6" );
    six.addActionListener(this);
    container.add( six );
    //mult
    mult = new JButton( "*" );
    mult.addActionListener(this);
    container.add( mult );
    //one
    one = new JButton( "1" );
    one.addActionListener(this);
    container.add( one );
    //two
    two = new JButton( "2" );
    two.addActionListener(this);
    container.add( two );
    //three
    three = new JButton( "3" );
    three.addActionListener(this);
    container.add( three );
    //minus
    minus = new JButton( "-" );
    minus.addActionListener(this);
    container.add( minus );
    //zero
    zero = new JButton( "0" );
    zero.addActionListener(this);
    container.add( zero );
    //dec
    dec = new JButton( "." );
    dec.addActionListener(this);
    container.add( dec );
    //plus
    plus = new JButton( "+" );
    plus.addActionListener(this);
    container.add( plus );
    //mem
    mem = new JButton( "MEM" );
    mem.addActionListener(this);
    container.add( mem );
    //mrc
    mrc = new JButton( "MRC" );
    mrc.addActionListener(this);
    container.add( mrc );
    //sin
    sin = new JButton( "SIN" );
    sin.addActionListener(this);
    container.add( sin );
    //cos
    cos = new JButton( "COS" );
    cos.addActionListener(this);
    container.add( cos );
    //tan
    tan = new JButton( "TAN" );
    tan.addActionListener(this);
    container.add( tan );
    //asin
    asin = new JButton( "ASIN" );
    asin.addActionListener(this);
    container.add( asin );
    //acos
    acos = new JButton( "ACOS" );
    cos.addActionListener(this);
    container.add( cos );
    //atan
    atan = new JButton( "ATAN" );
    atan.addActionListener(this);
    container.add( atan );
    //x2
    x2 = new JButton( "X2" );
    x2.addActionListener(this);
    container.add( x2 );
    //sqrt
    sqrt = new JButton( "SQRT" );
    sqrt.addActionListener(this);
    container.add( sqrt );
    //exp
    exp = new JButton( "EXP" );
    exp.addActionListener(this);
    container.add( exp );
    //pi
    pi = new JButton( "PI" );
    pi.addActionListener(this);
    container.add( pi );
    //percent
    percent = new JButton( "%" );
    percent.addActionListener(this);
    container.add( percent );
    //eq
    eq = new JButton( "=" );
    eq.addActionListener(this);
    container.add( eq );
    //Set size and visible
    setSize( 190, 285 );
    setVisible( true );
    public static void main(String args[]){
    //execute applet as application
         //applet's window
         JFrame applicationWindow = new JFrame("calculator");
    applicationWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         //applet instance
         calculator appletObject = new calculator();
         //init and start methods
         appletObject.init();
         appletObject.start();
    } // end main
    public void actionPerformed(ActionEvent ae)
    JButton but = ( JButton )ae.getSource();     
    //dec action
    if( but.getText() == "." )
    //if dec is pressed, first check to make shure there
    is not already a decimal
    String temp = output.getText();
    if( temp.indexOf( '.' ) == -1 )
    output.setText( output.getText() + but.getText() );
    //clear action
    else if( but.getText() == "CE" )
    output.setText( "" );
    operation = "";
    number1 = 0.0;
    number2 = 0.0;
    //plus action
    else if( but.getText() == "+" )
    operation = "+";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //minus action
    else if( but.getText() == "-" )
    operation = "-";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //mult action
    else if( but.getText() == "*" )
    operation = "*";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //div action
    else if( but.getText() == "/" )
    operation = "/";
    number1 = Double.parseDouble( output.getText() );
    clear = true;
    //output.setText( "" );
    //eq action
    else if( but.getText() == "=" )
    number2 = Double.parseDouble( output.getText() );
    if( operation == "+" )
    result = number1 + number2;
    else if( operation == "-" )
    result = number1 - number2;
    else if( operation == "*" )
    result = number1 * number2;
    else if( operation == "/" )
    result = number1 / number2;
    //output result
    output.setText( String.valueOf( result ) );
    clear = true;
    operation = "";
    //default action
    else
    if( clear == true )
    output.setText( "" );
    clear = false;
    output.setText( output.getText() + but.getText() );

    Multiple post:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=474370&tstart=0&trange=30

  • Help with a Program I am writing!  Please!

    Hello All,
    This is my first post...I hope to find some answers to my program I am writing! A couple things first - I am 17, and have designed a comp. science class for myself to take while a senior in high school, since there was not one offered. My end of the 2nd term project is to write a program that encompasses the information I have learned about for the past two terms. I know the very basics, if that. Please help!
    My program involves the simple dice throwing program, 'Dice Thrower' by Kevin Boone. The full text/program write out can be found at:
    http://www.kevinboone.com/PF_DiceThrower-java.html
    I am hoping to add a part to this program that basically tells the program if the dice show doubles, pop up a little GUI window that says "You are a Winner! You Got Doubles!"
    I was thinking as I finished chapter 7 in my text book, that either an 'if/else' or 'switch' statement might be the right place to start.
    Could someone please write me a start to the program text that I need to add to 'Dice Thrower', or explain what I need to do to get started! Thank you so much, I really appreciate it.
    Erick DeVore - Eroved Kcire

    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JLabel;
    import javax.swing.JFrame;
    import java.awt.FlowLayout;
    import java.awt.Color;
    public class DiceThrower extends Applet
    Die die1;
    Die die2;
    public void paint (Graphics g)
         die1.draw(g);
         die2.draw(g);
         g.drawString ("Click mouse anywhere", 55, 140);
         g.drawString ("to throw dice again", 65, 160);
    public void init()
         die1 = new Die();
         die2 = new Die();
         die1.setTopLeftPosition(20, 20);
         die2.setTopLeftPosition(150, 20);
         throwBothDice();
         // Erick's Program Insert below
         public class WinnerGui extends JFrame;
      public WinnerGui();
        super ("You Are The Winner with GUI");
        Container c = getContentPane();
        c.setBackground(Color.lightGray);
        c.setLayout(new FlowLayout());
        c.add(new JLabel("You're a Winner! You Got Doubles!"));
            //End Erick's Program insert
         DiceThrowerMouseListener diceThrowerMouseListener =
              new DiceThrowerMouseListener();
         diceThrowerMouseListener.setDiceThrower(this);
         addMouseListener(diceThrowerMouseListener);
    public void throwBothDice();
         die1.throwDie();
         die2.throwDie();
         repaint();
    class Die
    int topLeftX;
    int topLeftY;
    int numberShowing = 6;
    final int spotPositionsX[] = {0, 60,  0, 30, 60,  0,  60};
    final int spotPositionsY[] = {0,  0, 30, 30, 30,  60, 60};
    public void setTopLeftPosition(final int _topLeftX, final int _topLeftY)
         topLeftX = _topLeftX;
         topLeftY = _topLeftY;
    public void throwDie()
         numberShowing = (int)(Math.random() * 6 + 1);
    public void draw(Graphics g)
         switch(numberShowing)
              case 1:
                   drawSpot(g, 3);
                   break;
              case 2:
                   drawSpot(g, 0);
                   drawSpot(g, 6);
                   break;
              case 3:
                   drawSpot(g, 0);
                   drawSpot(g, 3);
                   drawSpot(g, 6);
                   break;
              case 4:
                   drawSpot(g, 0);
                   drawSpot(g, 1);
                   drawSpot(g, 5);
                   drawSpot(g, 6);
                   break;
              case 5:
                   drawSpot(g, 0);
                   drawSpot(g, 1);
                   drawSpot(g, 3);
                   drawSpot(g, 5);
                   drawSpot(g, 6);
                   break;
              case 6:
                   drawSpot(g, 0);
                   drawSpot(g, 1);
                   drawSpot(g, 2);
                   drawSpot(g, 4);
                   drawSpot(g, 5);
                   drawSpot(g, 6);
                   break;
    void drawSpot(Graphics g, final int spotNumber)
         g.fillOval(topLeftX + spotPositionsX[spotNumber],
              topLeftY + spotPositionsY[spotNumber], 20, 20);
    class DiceThrowerMouseListener extends MouseAdapter
    DiceThrower diceThrower;
    public void mouseClicked (MouseEvent e)
         diceThrower.throwBothDice();
    public void setDiceThrower(DiceThrower _diceThrower)
         diceThrower = _diceThrower;
    }That was what I have dwindled it down to, using my knowledge, as well as others' expertise...however I am listening to what you say, and get these messages when I try to compile in the CMD:
    line 63 - illegal start of expression (carrot at p in public)
    line 63 - ; expected (carrot at c in class)
    line 63 - { expected (carrot at ; at end of line)
    line 65 - illegal start of expression (carrot at p in public)
    line 83 - <identifier> expected (carrot as: (this) ) -- I don't even know what that means ^
    line 84 - invalid method declaration; return type required (carrot at a in add)
    line 84 - <identifier> expected (carrot like this: [see below])
    addMouseListener(diceThrowerMouseListener);
    ^
    line 84 - ) expected (carrot is one place over from previous spot [see above]
    line 93 - illegal start of expression (carrot at p in public)
    I know this seems like a lot of errors, but believe it or not, I actually had it up in the high teens and was able to fix some of them myself from going by previous examples, as well as looking things up in my text book. If anyone has any suggestions concerning the syntax errors of the code, please please let me know and I will work my hardest to fix them...thank you all so much for helping.
    Erick

  • My MacBook get's hot really quick and then discharge's quickly without opening any program, please help.

    My MacBook get's hot really quick and then discharge's quickly without opening any program, please help.
    I have checked the cooling fan, and it's working, and I took it to an IT technician and he said my hardware is allright, so is it a problem from the OS it self??
    OS X(10.8.5)

    Restart with the Option key held down and the Mac OS X install disk inserted, provide the firmware password, click on the DVD, press the button with the straight arrow, access the firmware settings, disable the password, and use FireWire Target Disk mode. If you can't do that or it doesn't work, contact Apple.
    (38384)

  • TS3276 I am not able to Mobile Me email account to connect with iCloud or my Apple Mail program. Don't know if my settings are correct or not. Can anyone help me with this please?

    I am not able to Mobile Me email account to connect with iCloud or my Apple Mail program. Don't know if my settings are correct or not. Can anyone help me with this please?

    http://support.apple.com/kb/HT5922
    If you want to mirror your desktop, see:
    http://support.apple.com/kb/HT5404
    Regards.

  • I have windows 8 and I got this error "Adobe Photoshop has stopped working" whenever I start a program. please help. how can I fix this problem? many thanks

    i have windows 8 and I got this error "Adobe Photoshop has stopped working" whenever I start a program. please help. how can I fix this problem? many thanks

    Please read these and proceed accordingly:
    http://blogs.adobe.com/crawlspace/2012/07/photoshop-basic-troubleshooting-steps-to-fix-mos t-issues.html
    http://forums.adobe.com/docs/DOC-2325

  • I need help instantly on this program please

    import java.util.*;
    public class D3
              private static int[] z = new int[100000];
    private static int first=z[0];
              private static int last=z[n-1];
              private static int n=100000;
    public static void main(String args[])
    Scanner input=new Scanner(System.in);
    for(int i=0;i<z.length;i++)
              z=2*i;
    int seqSearch(z;50000;n); //method call 4 key where key=mid
              int binSearch(z;first;last;50000);
              int seqSearch(z;35467;n); //method call 4 key where key in the left half
              int binSearch(z;first;last;35467);
              int seqSearch(z;89703;n); //method call 4 key where key in the right half
              int binSearch(z;first;last;89703);
              public int seqSearch(int z[];int key;int n)
         long start = System.currentTimeMillis();
    int count=0;
    int ans=-1;
    for(int i=0;i<n;i++)
    if z[i]=key
    count++
    {ans=i
    break;}
    return ans;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
         public int binSearch(int z[];int first;int last;int key)
         long start = System.currentTimeMillis();
         int count=0;
         if(last<first){
         count++;
         index=-1;
         else
         count++;
         int mid=(first+last)/2
         if(ket=z[mid]{
         index=mid;
         else
         if(key<z[mid]){
         index = binSearch(z[];first;mid-1;key);
         else
         index=binSearch(z[];mid+1;last;key);
         return index;
         long elapsed = System.currentTimeMillis() - start;
         System.out.print("Execution Time:" + elapsed);
         System.out.print("# of Basic Operations:" + count);
    // if anyone could tell me whats wrong with my code i'd be greatful...the program is supposed to perform binary and sequential search on a sorted array of 100000 numbers.once on an item in the middle of the array once on the right side of it and once on the left side...i also need to count the number of basic operations for the same number in both sequential and binary to see whats better.and i need to check the time...plz i need help now,,,

    "Guide to a first-time poster"
    you need to add exclamation marks to signify how urgent it is
    e.g.
    i need help instantly on this program please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    capital letters is better
    I NEED HELP INSTANTLY ON THIS PROGRAM PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    starting the italics on line 1, better again
    import java.util.*;
    public class D3
    private static int[] z = new int[100000];
    private static int first=z[0];
    private static int last=z[n-1];
    private static int n=100000;
    public static void main(String args[])
    Scanner input=new Scanner(System.in);
    for(int i=0;i<z.length;i++)
    z=2*i;
    int seqSearch(z;50000;n); //method call 4 key where key=mid
    int binSearch(z;first;last;50000);
    int seqSearch(z;35467;n); //method call 4 key where key in the left half
    int binSearch(z;first;last;35467);
    int seqSearch(z;89703;n); //method call 4 key where key in the right half
    int binSearch(z;first;last;89703);
    public int seqSearch(int z[];int key;int n)
    long start = System.currentTimeMillis();
    int count=0;
    int ans=-1;
    for(int i=0;i<n;i++)
    if z=key
    count++
    {ans=i
    break;}
    return ans;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    public int binSearch(int z[];int first;int last;int key)
    long start = System.currentTimeMillis();
    int count=0;
    if(last><first){
    count++;
    index=-1;
    else
    count++;
    int mid=(first+last)/2
    if(ket=z[mid]{
    index=mid;
    else
    if(key><z[mid]){
    index = binSearch(z[];first;mid-1;key);
    else
    index=binSearch(z[];mid+1;last;key);
    return index;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    and what about the dukes, offer 10 (never to be awarded, of course)
    do this, then sit back and watch the replies roll in.

Maybe you are looking for

  • Re: [iPlanet-JATO] Data model(Dataobject in Nd5)

    Sn, Computed columns need special attention. The migration tool creates a QueryFieldSchema for each Model (DataObject). The schema is populated with entries for each of the "data fields" needed by that query. For example: FIELD_SCHEMA.addFieldDescrip

  • GMail POP3 problem: Not getting messages with sender "me"

    HI guys, I have an account called [email protected] , I successfully sent mails to the same using javamail.In this messages,sender is marked as "me". Now I want to read all the messages in inbox,including the messages sent by same account itself.(mes

  • PayPal button in program?

    Hi, I have written a small program in Java upon which I would like to put a Donate button. There are plenty of instructions on how to add a Donate button on a web page, but I specifically want to add it to the program instead. Are there any known ref

  • FUTURE TCP 와 SQL*NET V2 사용시 PERFORMANCE

    제품 : SQL*NET 작성날짜 : 1995-05-04 Subject: Re: Know How..[ 2. Future/tcp 사용시] 두번째 항목의 경우 future/tcp 에서 Named Server를 잘못설정하면 Host의 Named Server를 다 찾고서, 없으면 Client의 host file을 뒤져서 자기 host alias로 처리하는 경우가 있었습니다.(1-2초 걸리던 connection time이 12초 까지 걸렸음) 경남은행에도

  • SC :Error in Process

    Hi All, While creating a SC with a Material relplicated from R/3 MM in EBP , the SC got stuck with Status"Error in Process ". Plz assist. Rgrds, SK