Help me with a program

Hello I hope someone can help me!!!!!!!
I have made a program to make math
here it is. now it works but i want to change from "Integer" to "double" , but this don't work my compiler says always error
can someone help me!
when you can please sent me a mail [email protected]
import java.io.*;
public class Summe     {
     public static void main (String argv[]) throws IOException
     String str;
     int a,b,c;
     BufferedReader eingabe = new BufferedReader (new InputStreamReader(System.in));
     System.out.print ("geben sie die erste zahl ein:");
     str = eingabe.readLine();
     a=Integer.parseInt(str);
     System.out.print("geben sie die zweite zahl ein:");
     str = eingabe.readLine();
     b=Integer.parseInt(str);
     c=a+b;
     System.out.println ("Die Summe von " a " und " b " ist: " +c);
     System.out.println ("Programmende Summe.");

import java.io.*;
public class Summe {
public static void main (String argv[]) throws IOException
String str;
double a,b,c;
BufferedReader eingabe = new BufferedReader (new InputStreamReader(System.in));
System.out.print ("geben sie die erste zahl ein:");
str = eingabe.readLine();
a=Double.parseDouble(str);
System.out.print("geben sie die zweite zahl ein:");
str = eingabe.readLine();
b=Double.parseDouble(str);
c=a+b;
System.out.println ("Die Summe von " a " und " b " ist: " +c);
System.out.println ("Programmende Summe.");
And what was the problem, I wonder?

Similar Messages

  • Pls help me with this program - urgent

    Hi,
    I am new to Java. First time to do the program. Stuck here.
    The description of the program:
    Implement a complex number (numbers of the form a+ib, where i2 = -1, i2 is i raised to power 2 ). Recall that a complex number consists of a real part (a) and an imaginary part (b). Provide a reasonable set of constructors; the methods add, subtract, multiply and divide; as well as toString and equals.
    You are to implement a complex number as having two fields, one for the real part another for the imaginary part.
    If z = a + ib and x = c + id are two complex numbers, then their sum z+ x = (a+c) + i(b+d), quotient z/x = (ac+bd)/(c*c+d*d) + i(-ab+bc)/(c*c + d*d). two complex numbers are equal if their real and imaginary parts are equal.
    I really do not have any clues about imaginary parts and how to do it.
    Could you please help me with that.
    Thanks a lot.

    ur dboubt has nothing to do java.. its a mathematical concept..
    as the question says the complexnumbers can be represented in the form of a+ib where i=squre-root of -1 .. and as this is imaginary (ie u cant get a minus number by squring a number) the second part is called imaginay.
    so as a programmer u dont have to give more strain on this but to declare a class having to instance varaiables and inplememts the methods as said.
    and in the toString() method u can return the numbers in the reuired format like
    return ( a + "+i" +b);

  • Please help me with simple program

    Can someone please write a simple program for me that opens up a webpage in the center of the screen , with a set size, and then asks the user where they would like to click on the screen. Then once the person clicks it asks how many times they would like to click there, and then once they enter the # the program opens up the webpage (in the center at the same spot as before, with the same set size) and automatically clicks on the predesignated spot , and then closes all open internet windows, and keeps doing it for however many times the person chose. PLEASE HELP ME WITH THIS!!! If you could, please post the source code here. Thank you so much to whoever helps me!!!!!!!

    If it's not to learn, then what is the purpose of
    this project?well, if it's not HW and its not for learning java, then why the hell would anyone like to have a program that may open a webpage and then repeatedly click on predefined place...
    let me see...
    now if he had asked for program that fakes IP as well, then i would suggest that he tryes to generate unique clicks, but now... i'm not sure... maybe just voting in some polls or smthing... though, i would not create a program that clicks on the link or form element, but rather just reload url with given parameters for N times...

  • Can you help me with my program please?

    hi all,
    I have a problem with the sellMilk function at the Milk class I don't know how to write it right I've tried everything so I need you to help me.
    this function should check the expiry date of the milk and sell the required amount if it is not expired. if it was expired just delete the milkbox.
    I have cases like if the first box has 5 kg and not expired , second box has 10 kg and expired, third box has 8 kg and not expired .. and if the required amount to sell is 6 kg for example it should work like this: first box should become zero because 5 kg has been sold and remainder is 1 .. so it should check the expiry date of the second box and it is expired so delete it. and then check the third box's expiry date and it is not expired so 8-1 = 7 .. and by that way 6 kg has been sold.
    my program it just delete the expired box if it was the first element.
    my code doesn't work well like that! here is the full program so you can check the code to help me please ..
    the problem is just with SellMilk() at the Milk Class
    Thank you
    import java.io.*;
    import java.text.*;
    import java.util.*;
    public class Market
        public static void main(String args[ ])
        { System.out.print("Enter the Market name: " );
            String name1 = Stdin.readLine();
            Market_Store mymarketstore = new Market_Store(name1);
       System.out.println("Welcome To " +name1+" Market ");
       System.out.println("");
            System.out.println("1-Stock new Milk");
            System.out.println("2-Stock new Milk Box");
            System.out.println("3-Sell");
            System.out.println("4- Display");
            System.out.println("");
            System.out.print("Enter your choice: ");
            int choice = Stdin.readInteger();
            while (choice != 5)
                switch (choice)
                case 1:
                 mymarketstore.stockNewMilk();
                    break;
                case 2:
                    mymarketstore.stockMilkBox();
                    break;
                    case 3:
             mymarketstore.sell();
                break;
                case 4:
               mymarketstore.display();
                            break;
                            case 5:
                default:
                    System.out.println("wrong Number");
                    System.out.println("Enter a number between 1 to 4 ");
                    System.out.println("Enter 5 to Exit");
                    break;
                System.out.println("");
              System.out.println("Welcome To " +name1+" Market ");
       System.out.println("");
            System.out.println("1-Stock new Milk");
            System.out.println("2-Stock new Milk Box");
            System.out.println("3-Sell");
            System.out.println("4-Display");
            System.out.println("");
             System.out.print("Enter your choice: ");
                choice = Stdin.readInteger();
    class Market_Store
            private String name;
            private Vector mymilk;
            public Market_Store(String n)
                    name=n;
                    mymilk = new Vector();
            public void stockNewMilk()
                    String N;//milk type
                    System.out.print("Enter the type of the milk: ");
                    N=Stdin.readLine();
                    Milk  m1 = new Milk (N);
                    mymilk.addElement(m1);
            public void stockMilkBox()
            System.out.println("Milk Available in stock : ");
            for (int i=0; i<mymilk.size(); i++){
            Milk m2 = (Milk)mymilk.elementAt(i);
            System.out.print(i+1+")");
            System.out.println(m2.getMilkType());  }
                    System.out.print("Enter the number of the milk to stock new box: ");
            int     ii = Stdin.readInteger();
            ((Milk)(mymilk.elementAt(ii-1))).addNewBox();
            }//end stockMilkBox
            public void sell()
                    //sell specific type of milk
                   System.out.println("Milk Available in stock : ");
            for (int i=0; i<mymilk.size(); i++){
            Milk m2 = (Milk)mymilk.elementAt(i);
            System.out.print(i+1+")");
            System.out.println(m2.getMilkType());
                                   System.out.print("Enter the number of the milk to sell:  ");
            int     ii = Stdin.readInteger();
    System.out.print("Enter the amount required in Kg:  ");
    double amount = Stdin.readDouble();
            ((Milk)(mymilk.elementAt(ii-1))).sellMilk(amount);
            public void display()
            {      System.out.println("Milk Available in stock : ");
            for (int i=0; i<mymilk.size(); i++){
            Milk m2 = (Milk)mymilk.elementAt(i);
            System.out.print(i+1+")");
            System.out.println(m2.getMilkType());
                    System.out.print("Enter the number of the milk to display:  ");
            int     ii = Stdin.readInteger();
                    ((Milk)(mymilk.elementAt(ii-1))).display();
    class MilkBox
            private Date expiredate;
            private Date date;
            private double stock;
            public MilkBox(double stck, Date ed)
                     date = new Date();
                    expiredate = ed;
            public double getStock()
             return stock;     }
            public Date getDate()
                     return date;
    public void setStock(double st)
    { stock = st;}
    public void setExDate(Date dd)
    {expiredate = dd;}
            public Date getExDate()
                     return expiredate;
      public   double sellMilkBox(double amount)
            double excessAmount = 0;
            if (amount < stock)
                double newAmount = stock - amount;
                setStock(newAmount);
            else  
                excessAmount = amount - stock;
                setStock(0);
            return excessAmount;
    public     void display()
                            System.out.println("The box of "+date+" has " +stock+" KG");
    class Milk
            private String Mtype;//milk type
            private Vector mybox;//vector of batches
            public Milk (String n)
                    Mtype =n;
            mybox = new Vector();
      public  void addNewBox()
    double stook;
    System.out.print("Enter the weight of the box: ");
    stook = Stdin.readDouble();
         Date exdate;//expirey date
    System.out.println("Enter the expirey date of the milk box:");
           int d; int m1; int y;
              System.out.println("Enter Year:" );
              y = Stdin.readInteger();
              System.out.println("Enter Month:" );
              m1 = Stdin.readInteger();
              System.out.println("Enter Day:" );
              d = Stdin.readInteger();
                   Calendar r=new GregorianCalendar(y,m1,d);
                    exdate= r.getTime();
                    //send the attributes to Box constructor
                   MilkBox newBox = new MilkBox(stook,exdate);
                    newBox.setStock(stook);
                    newBox.setExDate(exdate);
                    mybox.addElement(newBox);
       public void display()
                    System.out.println("Milk "+Mtype);
                            for (int i=0; i<mybox.size(); i++){
                    MilkBox b= (MilkBox)mybox.elementAt(i);
                    b.display();
    public double sellMilk (double amount)
       for(int i=0;i<mybox.size();i++)
               MilkBox b = (MilkBox)mybox.elementAt(i);
                double stock = b.sellMilkBox(amount);
                double value = b.getStock();
                Date ExpireyDate = b.getExDate();
      if ( ExpireyDate.before(new Date()))
    {  mybox.removeElementAt(i);
            System.out.println("it has expired date");
    if (stock >1|| value  ==  0 && ExpireyDate.after(new Date()))
    {       mybox.remove(b);  
    amount = stock;
    if ( ExpireyDate.before(new Date()))
    {  mybox.removeElementAt(i);
            System.out.println("it has expired date");
      if(amount != 0)
      System.out.println("The extra amount is "+amount+ " KG");
    return amount;}
    public String getMilkType()
    { return Mtype;}
    //set method
    void setMilkType(String n)
    { Mtype = n;}
    }//end class milk
    //STDIN FILE
    final class Stdin
       public static BufferedReader reader=new BufferedReader
        (new InputStreamReader(System.in));
       public static String readLine()
       while(true)
       try{
           return reader.readLine();
           catch(IOException ioe)
             reportError(ioe);
           catch(NumberFormatException nfe)
            reportError(nfe);
       public static int readInteger()
        while(true)
        try{
        return Integer.parseInt(reader.readLine());
        catch(IOException ioe)
        reportError(ioe);
        catch(NumberFormatException nfe)
        reportError(nfe);
       public static double readDouble()
        while(true)
        try{
        return Double.parseDouble(reader.readLine());
        catch(IOException ioe)
        reportError(ioe);
        catch(NumberFormatException nfe)
        reportError(nfe);
        public static void reportError (Exception e)
        System.err.println("Error input:");
        System.err.println("please re-enter data");
        }Edited by: mshadows on Dec 22, 2007 12:06 AM

    ok here is the code that has the problem .. what's wrong with it?
    public double sellMilk (double amount)
       for(int i=0;i<mybox.size();i++)
               MilkBox b = (MilkBox)mybox.elementAt(i);
                double stock = b.sellMilkBox(amount);
                double value = b.getStock();
                Date ExpireyDate = b.getExDate();
      if ( ExpireyDate.before(new Date()))
    {  mybox.removeElementAt(i);
            System.out.println("it has expired date");
    if (stock >1|| value  ==  0 && ExpireyDate.after(new Date()))
    {       mybox.remove(b);  
    amount = stock;
    if ( ExpireyDate.before(new Date()))
    {  mybox.removeElementAt(i);
            System.out.println("it has expired date");
      if(amount != 0)
      System.out.println("The extra amount is "+amount+ " KG");
    return amount;}

  • Can someone help me with this program?

    Can someone make this program for me?
    Make a Java-webapplication containing a few webpages (html-files and servlets, but NO jsp's). With this application you can get bankdata from a database, for example:
    page 1: html-file: Welcome on the website, type your bankaccount and password
    page 2: error if bankaccount doesn't exist or wrong password
    page 3: welcome with name and option to choose for your balance or a list with transactions from that account (the user can give a starting date)
    page 4: showing the balance or the list with transactions, name and accountnumber
    Store the information about the account and name in sessionsvariables
    the database is an access-file with two tables
    table Accounts with colums: accountnumber, name, balance and password
    table Transactions with colums: accountnumber, amount, plus/minus, date, sorttransaction and contra-account
    (when I need to send you the database by mail, you can ask me ...)
    maybe someone can help me,
    thanks in advance
    greetings Bastiaan

    Sure we can help you. Post the code you have already and explain any problems you are currently having together with any and all complete compiler error messages and/or exceptions.
    But no, we are not going to do your homework for you.

  • Could anyone help me with my program

    Hi i have a piece of code which i want to improve. The two methods are SplitTextArea and SplitGlossArea.
    SplitTextArea, looks at the black and white parts of the page and uses this to separate sentances from eachother by detecting where the sentance is by the black text.
    And the SplitGlossArea is to do with annotations and comments.
    To improve the code i have changed the value of backColor1 to 200 from 245. This increases the number of locations considered to be "on average white". But this is not perfect on different types of images.
    The program seems to struggle separating the test and the gloss and this seems to effect the text splitting. So i have looked at another method called "SetTextEdge", this works out the gap between the gloss and the text, by looking for the most common distance of first non-white from the left edge or the right edge, depending on whether it is a left or right page. The array "firstMode" records how many times each distance occurs, and the first most common distance is "posMode".
    Some possible things i have planned to try (but have not got round to wondering if anyone out there can HELP!! :D)
    1. to do some sort of rolling average as following (to print out the values in "firstMode" and adjust them so i can use them in the code to see what happened)
    2. To consider only distances near where the text edge is expected (say between 100 and 200) rather than right.
    Here are the SplitTextArea and SplitGlossArea methods::
    private static int setTextEdge(boolean leftPage)
        int[] firstMode = new int[imageWidth + 1] ;
        for (int i = 0 ; i <= imageWidth ; i++)
            firstMode[i] = 0 ;
        for (int i = 0 ; i < cropHeight ; i++)
            int mx1 = 0 ;
            if (leftPage)
                while ((mx1 <cropWidth) &&
                   (getColour(leftEdge + mx1, topEdge + i) > 200))
                    mx1++ ;
            else
                while ((mx1 <cropWidth) &&
                   (getColour(leftEdge + cropWidth - mx1, topEdge + i) > 200))
                    mx1++ ;
            if (mx1 < (cropWidth / 2))
            firstMode[mx1]++ ;
        int maxMode = -1,
            posMode = -1 ;
        for (int i = 0 ; i < imageWidth ; i++)
            if (maxMode < firstMode)
    maxMode = firstMode[i] ;
    posMode = i ;
    posMode -= 2 ;
    if (leftPage)
    message("left edge of text is at " + (leftEdge + posMode)) ;
    return leftEdge + posMode ;
    else
    message("right edge of text is at " + (leftEdge + cropWidth - posMode)) ;
    return leftEdge + cropWidth - posMode ;
    } // end of method setTextEdge
    private static void splitTextArea(boolean leftPage) throws IOException
    int left = 0,
    right = 0 ;
    if (leftPage)
    left = textEdge ;
    right = leftEdge + cropWidth ;
    else
    left = leftEdge ;
    right = textEdge ;
    int rowWidth = right - left ;
    // int backcolour1 = 253 ;
    int backcolour1 = 200,
    max_light_lines = 1,
    max_dark_lines = 15,
    lightLineCounter = 0,
    darkLineCounter = 0 ;
    boolean inLightZone = true,
    inTextZone = false ;
    int lastY = topEdge,
    descender_space = 3 ;
    // PrintWriter pout2 = new PrintWriter(new FileWriter(outDirectory1 +
    // File.separator + "xxx.txt")) ;
    noOfRows = 0 ;
    int clearance = 40 ;
    for (int i = topEdge + clearance ; i < topEdge + cropHeight - clearance ; i++)
    int colour = getRowColour(left, right, i) ;
    // pout2.println(i + ", " + colour) ;
    if (colour >= backcolour1)
    lightLineCounter++ ;
    darkLineCounter-- ;
    else
    darkLineCounter++ ;
    lightLineCounter-- ;
    if (lightLineCounter > max_light_lines)
    lightLineCounter = max_light_lines ;
    if (lightLineCounter < 0)
    lightLineCounter = 0 ;
    if (darkLineCounter > max_dark_lines)
    darkLineCounter = max_dark_lines ;
    if (darkLineCounter < 0)
    darkLineCounter = 0 ;
    if ((lightLineCounter == max_light_lines) && (inTextZone))
    inLightZone = true ;
    inTextZone = false ;
    int line = noOfRows + 1 ;
    int rowHeight = i + descender_space - lastY ;
    // message("(" + left + ", " + lastY + ", " + rowWidth + ", " +
    // rowHeight + ")") ;
    pout1.println("(" + left + ", " + lastY + ", " + rowWidth +
    ", " + rowHeight + ")") ;
    rows[noOfRows] = new IntegerQuad(left, lastY, rowWidth, rowHeight) ;
    noOfRows++ ;
    lastY = i + descender_space ;
    else if ((darkLineCounter == max_dark_lines) && (inLightZone))
    inLightZone = false ;
    inTextZone = true ;
    // pout2.close() ;
    message("no of lines = " + noOfRows) ;
    pout1.println("No of Lines = " + noOfRows) ;
    pout1.println() ;
    } // end of method splitTextArea
    private static void splitGlossArea(boolean leftPage)
    int left = 0,
    right = 0 ;
    if (leftPage)
    left = leftEdge ;
    right = textEdge ;
    else
    left = textEdge ;
    right = leftEdge + cropWidth ;
    int rowWidth = right - left ;
    if (rowWidth == 0)
    message("WARNING: no gloss area found") ;
    noOfGlossRows = 0 ;
    return ;
    // int backcolour1 = 253,
    int backcolour1 = 245,
    max_light_lines = 20,
    max_dark_lines = 10,
    lightLineCounter = 0,
    darkLineCounter = 0 ;
    boolean inLightZone = true,
    inTextZone = false ;
    int lastY = topEdge,
    descender_space = 17,
    ascender_space = 20 ;
    noOfGlossRows = 0 ;
    int clearance = 40 ;
    for (int i = topEdge + clearance ; i < topEdge + cropHeight - clearance ; i++)
    int colour = getRowColour(left, right, i) ;
    if (colour >= backcolour1)
    lightLineCounter++ ;
    darkLineCounter-- ;
    else
    darkLineCounter++ ;
    lightLineCounter-- ;
    if (lightLineCounter > max_light_lines)
    lightLineCounter = max_light_lines ;
    if (lightLineCounter < 0)
    lightLineCounter = 0 ;
    if (darkLineCounter > max_dark_lines)
    darkLineCounter = max_dark_lines ;
    if (darkLineCounter < 0)
    darkLineCounter = 0 ;
    if ((lightLineCounter == max_light_lines) && (inTextZone))
    inLightZone = true ;
    inTextZone = false ;
    int line = noOfGlossRows + 1 ;
    int rowHeight = i + descender_space - lastY ;
    // message("(" + left + ", " + lastY + ", " + rowWidth + ", " +
    // rowHeight + ")") ;
    pout1.println("(" + left + ", " + lastY + ", " + rowWidth +
    ", " + rowHeight + ")") ;
    glossRows[noOfGlossRows] = new IntegerQuad(left, lastY, rowWidth,
    rowHeight) ;
    noOfGlossRows++ ;
    lastY = i + descender_space ;
    else if ((darkLineCounter == max_dark_lines) && (inLightZone))
    inLightZone = false ;
    inTextZone = true ;
    // this overrides other values of lastY,
    // to eliminate gloss whitespace
    lastY = i - max_dark_lines - ascender_space ;
    message("no of glosses = " + noOfGlossRows) ;
    pout1.println("No of Glosses = " + noOfGlossRows) ;
    pout1.close() ;
    And here is the code for the setTextEdge method.
    private static int setTextEdge(boolean leftPage)
        int[] firstMode = new int[imageWidth + 1] ;
        for (int i = 0 ; i <= imageWidth ; i++)
            firstMode[i] = 0 ;
        for (int i = 0 ; i < cropHeight ; i++)
            int mx1 = 0 ;
            if (leftPage)
                while ((mx1 <cropWidth) &&
                   (getColour(leftEdge + mx1, topEdge + i) > 200))
                    mx1++ ;
            else
                while ((mx1 <cropWidth) &&
                   (getColour(leftEdge + cropWidth - mx1, topEdge + i) > 200))
                    mx1++ ;
            if (mx1 < (cropWidth / 2))
            firstMode[mx1]++ ;
        int maxMode = -1,
            posMode = -1 ;
        for (int i = 0 ; i < imageWidth ; i++)
            if (maxMode < firstMode)
    maxMode = firstMode[i] ;
    posMode = i ;
    posMode -= 2 ;
    if (leftPage)
    message("left edge of text is at " + (leftEdge + posMode)) ;
    return leftEdge + posMode ;
    else
    message("right edge of text is at " + (leftEdge + cropWidth - posMode)) ;
    return leftEdge + cropWidth - posMode ;
    } // end of method setTextEdge
    Hope someone can help me.
    Sorry about this being quite a long post
    Reply as soon as you can
    Thanks
    Mark

    ... and it looks like this is just a continuation (or
    a starting over again, which, if it is, is just plain
    annoying) of this:
    http://forum.java.sun.com/thread.jspa?threadID=594546
    So I'd suggest to anyone inclined to reply to just go
    there. And to the OP to continue his original topic
    rather than starting it over, which is likely to just
    duplicate some of the same replies you got before,
    thus wasting answerer's time.I'm sorry but i post my thread a few people answer and then when its old and at the back of a forum no-one bothers with the post anymore.
    And i really need help with this problem??
    I will do as you say and just post a thread asking people to look at a previous post. Thanks for the help
    Mark

  • Can anyone help me with this program using the Scanner Class?

    I have to write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time period specified by the user. Such as 1 hour will equal 40 miles traveled, 2 hours will equal 80, 3 hours will equal 120, etc. This is what I've come up with thus far. Any help is appreciated.
    import java.util.Scanner;
         public class DistanceTraveled
              public static void main(String[] args)
                   int speed;
                   int hours;
                   int distance;
                   Scanner keyboard = new Scanner(System.in);
                   System.out.print("What is the speed of the vehicle in miles-per-hour?");
                   speed = keyboard.nextInt();
                   System.out.print("How many hours has the vehicle traveled for?");
                   hours = keyboard.nextInt();
                   distance = speed*hours;
                   while (speed < 0)
                   while (hours < 1)
                   System.out.println("Hour     Distance Traveled");
                   System.out.println("------------------------");
                   System.out.println(hours + " " + distance);
    }

    When you post code, wrap it in code tags. Highlight it and click the CODE button above the text input area.
    You seem to be trying to reuse the speed and hours variables in your loop. That's probably a mistake at this point. Keep it simpler by defining a loop variable.
    Also I don't see the need for two loops. You just want to show how far the vehicle has traveled for each one-hour increment, assuming constant speed, for the number of hours it has been traveling, right? So a single for loop should be sufficient.

  • Can anyone help me with this program?

    I have to make program that asks the user for information that they would want on a business card. Then, I am supposed ot take that information that was gathered with a listener and display it on a second panel using graphicsstuff (such as g.drawString(VARIABLEHERE, int x, int y). I can get thepart of the program that would ask for the information, but I can't figure out where to go from there on how to display the information. If anyone could help I would be enternally gratefully. This assignment is due Friday morning at 9:00. Thanks!
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PanelPractice extends JPanel
         private static JButton insert;
         private static JTextField nameField, positionField, areaField, telField, faxField, emailField, add1Field, add2Field, add3Field;
         private static String nameText, positionText, areaText, telText, faxText, emailText, add1Text, add2Text, add3Text;
         public static void main (String[] args)
              //Makes two colored panels that are nested within a third.
              JFrame frame = new JFrame ("Business Card");
              frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
              //Makes the first subpanel
              JPanel subPanel1 = new JPanel();
                   JLabel nameLabel, positionLabel, areaLabel, telLabel, faxLabel, emailLabel, add1Label, add2Label, add3Label;
                   //     Sets up the GUI
                        //Creates labels for the information questions
                        nameLabel = new JLabel ("Type the name you want on the card: ");
                        positionLabel = new JLabel ("Type the person's position: ");
                        areaLabel = new JLabel ("Type the person's area of business: ");
                        telLabel = new JLabel ("Type the person's telephone number: ");
                        faxLabel = new JLabel ("Type the person's fax number: ");
                        emailLabel = new JLabel ("Type the person's e-mail address: ");
                        add1Label = new JLabel ("Type the person's place of business: ");
                        add2Label = new JLabel ("Type the business' street address: ");
                        add3Label = new JLabel ("Type the business' city, state, and zip: ");
                        //Creates a JTextField to hold the person's name
                        nameField = new JTextField (10);
                        positionField = new JTextField (10);
                        areaField = new JTextField (10);
                        telField = new JTextField (10);
                        faxField = new JTextField (10);
                        emailField = new JTextField (10);
                        add1Field = new JTextField (10);
                        add2Field = new JTextField (10);
                        add3Field = new JTextField (10);
                        //add the nameLabel and nameField to the panel
                        subPanel1.add (nameLabel);
                        subPanel1.add (nameField);
                        //add the positionLabel and positionField to the panel
                        subPanel1.add (positionLabel);
                        subPanel1.add (positionField);
                        //add the areaLabel and areaField to the panel
                        subPanel1.add (areaLabel);
                        subPanel1.add (areaField);
                        //add the telLabel and telField to the panel
                        subPanel1.add (telLabel);
                        subPanel1.add (telField);
                        //add the faxLabel and faxField to the panel
                        subPanel1.add (faxLabel);
                        subPanel1.add (faxField);
                        //add the emailLabel and emailField to the panel
                        subPanel1.add (emailLabel);
                        subPanel1.add (emailField);
                        //add the add1Label and add1Field to the panel
                        subPanel1.add (add1Label);
                        subPanel1.add (add1Field);
                        //add the add2Label and add2Field to the panel
                        subPanel1.add (add2Label);
                        subPanel1.add (add2Field);
                        //add the add3Label and add3Field to the panel
                        subPanel1.add (add3Label);
                        subPanel1.add (add3Field);
                        //Creates a button to press to insert the information onto the card
                        insert = new JButton ("Insert Information!");
                        //Creates a Listener and makes it listen for the button to be pressed
                        insert.addActionListener (new ButtonListener());
                        //add the button to the panel
                        subPanel1.add (insert);
                        //set the size of the panel to the width and height constants
                        subPanel1.setPreferredSize (new Dimension (350, 300));
                        //set the color of the panel to whatever you choose
                        subPanel1.setBackground (Color.red);
              //Makes the second subpanel
              JPanel subPanel2 = new JPanel();
              subPanel2.setPreferredSize (new Dimension(500,300));
              subPanel2.setBackground (Color.blue);
              //Makes the primary panel
              JPanel primary = new JPanel();
              primary.setBackground (Color.black);
              primary.add (subPanel1);
              primary.add (subPanel2);
              frame.getContentPane().add(primary);
              frame.pack();
              frame.setVisible(true);
                   //     Represents an action listener for the insert button.
                   private static class ButtonListener implements ActionListener
                        public void actionPerformed (ActionEvent event)
                             //get the text from the textfields
                             nameText = nameField.getText();
                             positionText = positionField.getText();
                             areaText = areaField.getText();
                             telText = telField.getText();
                             faxText = faxField.getText();
                             emailText = emailField.getText();
                             add1Text = add1Field.getText();
                             add2Text = add2Field.getText();
                             add3Text = add3Field.getText();
                   public static class CustomComponent extends JPanel
                   public void paintComponent(Graphics g)
                   super.paintComponent(g);
                   g.drawString(nameText, 5, 5);
    }

    Sorry about that...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class PanelPractice extends JPanel
    private static JButton insert;
    private static JTextField nameField, positionField, areaField, telField, faxField, emailField, add1Field, add2Field, add3Field;
    private static String nameText, positionText, areaText, telText, faxText, emailText, add1Text, add2Text, add3Text;
    public static void main (String[] args)
    //Makes two colored panels that are nested within a third.
    JFrame frame = new JFrame ("Business Card");
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    //Makes the first subpanel
    JPanel subPanel1 = new JPanel();
    JLabel nameLabel, positionLabel, areaLabel, telLabel, faxLabel, emailLabel, add1Label, add2Label, add3Label;
    // Sets up the GUI
    //Creates labels for the information questions
    nameLabel = new JLabel ("Type the name you want on the card: ");
    positionLabel = new JLabel ("Type the person's position: ");
    areaLabel = new JLabel ("Type the person's area of business: ");
    telLabel = new JLabel ("Type the person's telephone number: ");
    faxLabel = new JLabel ("Type the person's fax number: ");
    emailLabel = new JLabel ("Type the person's e-mail address: ");
    add1Label = new JLabel ("Type the person's place of business: ");
    add2Label = new JLabel ("Type the business' street address: ");
    add3Label = new JLabel ("Type the business' city, state, and zip: ");
    //Creates a JTextField to hold the person's name
    nameField = new JTextField (10);
    positionField = new JTextField (10);
    areaField = new JTextField (10);
    telField = new JTextField (10);
    faxField = new JTextField (10);
    emailField = new JTextField (10);
    add1Field = new JTextField (10);
    add2Field = new JTextField (10);
    add3Field = new JTextField (10);
    //add the nameLabel and nameField to the panel
    subPanel1.add (nameLabel);
    subPanel1.add (nameField);
    //add the positionLabel and positionField to the panel
    subPanel1.add (positionLabel);
    subPanel1.add (positionField);
    //add the areaLabel and areaField to the panel
    subPanel1.add (areaLabel);
    subPanel1.add (areaField);
    //add the telLabel and telField to the panel
    subPanel1.add (telLabel);
    subPanel1.add (telField);
    //add the faxLabel and faxField to the panel
    subPanel1.add (faxLabel);
    subPanel1.add (faxField);
    //add the emailLabel and emailField to the panel
    subPanel1.add (emailLabel);
    subPanel1.add (emailField);
    //add the add1Label and add1Field to the panel
    subPanel1.add (add1Label);
    subPanel1.add (add1Field);
    //add the add2Label and add2Field to the panel
    subPanel1.add (add2Label);
    subPanel1.add (add2Field);
    //add the add3Label and add3Field to the panel
    subPanel1.add (add3Label);
    subPanel1.add (add3Field);
    //Creates a button to press to insert the information onto the card
    insert = new JButton ("Insert Information!");
    //Creates a Listener and makes it listen for the button to be pressed
    insert.addActionListener (new ButtonListener());
    //add the button to the panel
    subPanel1.add (insert);
    //set the size of the panel to the width and height constants
    subPanel1.setPreferredSize (new Dimension (350, 300));
    //set the color of the panel to whatever you choose
    subPanel1.setBackground (Color.red);
    //Makes the second subpanel
    JPanel subPanel2 = new JPanel();
    subPanel2.setPreferredSize (new Dimension(500,300));
    subPanel2.setBackground (Color.blue);
    //Makes the primary panel
    JPanel primary = new JPanel();
    primary.setBackground (Color.black);
    primary.add (subPanel1);
    primary.add (subPanel2);
    frame.getContentPane().add(primary);
    frame.pack();
    frame.setVisible(true);
    // Represents an action listener for the insert button.
    private static class ButtonListener implements ActionListener
    public void actionPerformed (ActionEvent event)
    //get the text from the textfields
    nameText = nameField.getText();
    positionText = positionField.getText();
    areaText = areaField.getText();
    telText = telField.getText();
    faxText = faxField.getText();
    emailText = emailField.getText();
    add1Text = add1Field.getText();
    add2Text = add2Field.getText();
    add3Text = add3Field.getText();
    public static class CustomComponent extends JPanel
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    g.drawString(nameText, 5, 5);
    } No..I'm not expecting someone to do it for me. I am having trouble figuring out what to do next. I cannot get anything to show up on the second panel...the part that displays the information that the listener gathered.
    If I could figure out how to get one thing to show up...then I could probably do the rest...it's getting it started that I can't get.

  • Hi friends plz help me with dialog programming

    hi,
    i have developed a screen with flow logic.it has few mandatory fields , radiobuttons,check boxes and pushbuttons such as Create,Save,Display,Back. after entering the values and save i have no problem but when taking back or display it is asking for mandatory field i need not give values for those field to take back.plz provide me with very quick response.
    and how do i save data from selected checkboxes or from radiobuttons to ztables and how do i retrieve data back to radiobutton in selected format .
    kindly help rewarded for answers.

    Hi Sirisha,
    Goto menu painter and give given status for ur program-> go to standard tool bar and double click on BACK and select Function type = E.
    or
    double click on ur PF status  and do the same.
    once you give function type E, write one module under PAI like below.
    PROCESS AFTER INPUT.
    MODULE BACK AT EXIT-COMMAND.
    code for Module BACK
    IF ok_code = 'BACK' OR ok_code = 'EXIT'.
        CLEAR: ok_code.
        LEAVE TO SCREEN 100." This is the screen where u want to come back
      ENDIF.
    ENDMODULE.
    This module BACK is executed wherever u write under PAI when Function type E is defined for Screen Element.
    for more details on this topic. please have a look.
    [http://help.sap.com/saphelp_nw70/helpdata/en/9f/dbaa9535c111d1829f0000e829fbfe/content.htm|http://help.sap.com/saphelp_nw70/helpdata/en/9f/dbaa9535c111d1829f0000e829fbfe/content.htm]
    I hope that it helps you ..
    Regards,
    Venkat.O

  • Help needed with basic program

    I am working on an assignment for my java class, and I am stuck. This is the 1st programming class that i have taken and am a little confused. I am supposed to write a program that inputs 5 numbers and determines and prints the number of negative numbers, positive numbers, and zeros that were inputed. I have gone about this a few different ways so far... but I'm not really sure what to do...
    This is what I have so far on my latest attempt, which I think might be completely wrong..... HELP!!!
    import java.util.Scanner;
    public class test
         public static void main (String[] args)
         Scanner input = new Scanner (System.in);
         int integer
         int negative = 0;
         int positive = 0;
         int zero = 0;
         int studentCounter = 1;
         while (studentCounter <=5)
         System.out.print("Please enter an integer:");
         integer = input.nextInt();
         if (integer == 0
              zero = zero +1
    I also tried something similar using :
         int num1; //first number input     
         int num2; //second number input
         int num3; //third number input
         int num4; //forth number input
         int num5; //fifth number input
    System.out.print ("Enter first integer:"); //prompts for input
         num1 = input.nextInt();
         System.out.print ("Enter second integer:"); //prompts for input
         num2 = input.nextInt();
         System.out.print ("Enter third integer:"); //prompts for input
         num3 = input.nextInt();
         System.out.print ("Enter forth integer:"); //prompts for input
         num4 = input.nextInt();
         System.out.print ("Enter fifth integer:"); //prompts for input
         num5 = input.nextInt();
    but i didn't know what to do next.....

    import java.util.Scanner;
    ublic class test
         public static void main (String[] args)
         Scanner input = new Scanner (System.in);
    int integer
    int negative = 0;
    int positive = 0;
         int zero = 0;
    int studentCounter = 1;
    while (studentCounter <=5)
         System.out.print("Please enter an integer:");
         integer = input.nextInt();
    if (integer == 0
              zero = zero +1
    This looks more or less correct so far. Not ideal, but aside from a missing ) and the fact that you trailed off without finishing, it looks like you're on track.
    Start with this, and post details about what specific problems you're having.
    When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.

  • Help please with java programming

    ok so i need a little help on getting started on this program.
    i need to make a program where the user can enter the last names of candidates and the votes recieved by each candidate. then the program should output both the candidates names and the total votes recieved by each candidate and the perctage of votes each recieved.
    can anyone help me get started with some sample code. thanks.

    ok so this is what i have so far . . . . it goes through the array and works.
    im suppose to also have these two methods . . .
    sumVotes- Which will receive the votes array by reference.
    Calculate the total votes.- Return the calculated integral total votes.winnerIndex- Which will receive the votes array by reference.- Identify the top candidate who received more votes. - Return the identified index.
    my program is suppose to do this . . .The program should then output each candidate?s name, votes received by that candidate, and the percentage of the total votes received by the candidate. The program should also output the winner of the election.
    ok so anyone out there nice enough to tutor me through making these 2 methods i need?
    here is code of what i have so far
    package assign11942;
    import javax.swing.*;
    public class Assign11942 {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              String strLast[],strNumCand, strVotes[];
              int numCand;
              double votes[], percentage, totalVotes[];
              strNumCand = JOptionPane.showInputDialog("Enter Number of Candidates: ");
              numCand = Integer.parseInt(strNumCand);
              strLast=new String[numCand];
              strVotes=new String[numCand];
              votes=new double[numCand];
              totalVotes=new double[numCand];
              for (int i =0 ; i < numCand; i++)  {
                   strLast= JOptionPane.showInputDialog("Enter Candidates Last Name: ");
                   strVotes[i]=JOptionPane.showInputDialog("Enter Number of Votes: ");

  • Help regarding with a program that calculates change for a cashier.

    I am seeking help for a java script or program that can answer my problem:
    Write a program that calculates change for a cashier. The program requests the cost of the item. The user then types in the cost. The program then outputs the cost of the item including the sales tax (use 6% as the sales tax value). The program next request and recieves the amount tendered by the customer. Finally, the program outputs a summary of all figures, including the amount of change due to the customer. (change . java)
    change . java has the following attributes and methods:
    double costs; doublegetCosts ( ) void setCost (double x)
    double tax; doublegetTax ( ) void setTax (double x)
    double payment; doublegetPayment ( ) void setpayment (double x)
    *rite another program that will have an instance of change . java. Call the file as cashier.java
    *Public Cashier {
    public void static main (string27argc
    change x ;
    x = new change ( ) ;
    * cashier . java will use the attributes and methods stated on change java via the instance of change inside cashier.
    Please I have no idea for java, I am student who really needs help on this. If anyone knows how to do this please reply to this topic!
    Thank you

    the correct way to get help in forums like this is to post
    the specific problem you have, along with what you have tried
    and details of the output you expect Vs the output you get.
    simply posting the assignment makes it look like just another
    "do my homework for me" plea - even though it may not be.

  • When I downloaded to iPad, it removed my icons, how do I uninstall? It is not helping me with the program I need for homeschooling. Please tell me how to uninstall from my iPad. Thank you

    I downloaded firefox to my pc to sync to my iPad. However, when it downloaded to my iPad, it removed all my desktop icons and is not working with my homeschooling program. I need to uninstall it from my iPad. Please let me know how to do this. Thank you.
    Mrs. Chapman

    Michael'sgot this one covered. He has detailed the process at the link below.
    https://discussions.apple.com/thread/3653100?tstart=0

  • Help me with extended program check

    what is extended program check?
    in one of my program im getting an warning message
    field string x_sort is not statically referenced in the program
    what does it mean by statically referenced?

    Extended Syntax Check -
    Many checks are excluded from the standard syntax check for performance reasons. The extended program check performs a complete check that includes the interfaces of external procedures called from your program.
    Errors in the extended program check cause exceptions, which in turn cause runtime errors when you run the program. You must correct them. The exception to this is coding that cannot be reached. However, you should delete this to minimize the size of your program and make the source code easier to understand.
    Warnings in the extended program check should also be corrected. If your program contains statements that are definitely correct but still produce warnings in the extended program check, you can exclude them from the check using pseudocomments ( "#EC… ).
    You should always run the extended program check on a new program. You have not finished developing a new program until you can run the extended program check on it without any errors or warnings. Messages are permissible, since they are generally not critical.
    The extended program check is also only a static check. It cannot eliminate all of the circumstances that could lead to exception situations or runtime errors. For example, any statements in which you specify arguments dynamically as the contents of fields, or in which you call procedures dynamically, cannot be checked statically.
    Code Inspector -
    The Code Inspector is a tool for checking Repository objects regarding performance, security, syntax, and adherence to name conventions.
    Please have a look at below link for details of code inspector.
    [Code Inspector|http://help.sap.com/saphelp_nw04/helpdata/en/56/fd3b87d203064aa925256ff88d931b/frameset.htm]
    I hope it helps.
    Thanks,
    Vibha
    Please mark useful answers

  • -anyone can help me with my program?"Checkers"   a game java gode.

    the problem always in my program is the main.. sorry if im not perfectly good in programming, but i always try my best to understand.. so please help me..thanks
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.ArrayList;
    public class Checkers extends JApplet {
    JButton newGameButton;
    JButton resignButton;
    JLabel message;
    public void init() {
    Container content = getContentPane();
    content.setLayout(null);
    content.setBackground(new Color(0,150,0));
    Board board = new Board();
    content.add(board);
    content.add(newGameButton);
    content.add(resignButton);
    content.add(message);
    board.setBounds(20,20,164,164); // Note: size MUST be 164-by-164 !
    newGameButton.setBounds(210, 60, 120, 30);
    resignButton.setBounds(210, 120, 120, 30);
    message.setBounds(0, 200, 350, 30);
    // -------------------- Nested Classes -------------------------------
    static class CheckersMove {
    int fromRow, fromCol;
    int toRow, toCol;
    CheckersMove(int r1, int c1, int r2, int c2) {
    fromRow = r1;
    fromCol = c1;
    toRow = r2;
    toCol = c2;
    boolean isJump() {
    return (fromRow - toRow == 2 || fromRow - toRow == -2);
    class Board extends JPanel implements ActionListener, MouseListener {
    CheckersData board;
    boolean gameInProgress;
    int currentPlayer;
    int selectedRow, selectedCol;
    CheckersMove[] legalMoves;
    public Board() {
    setBackground(Color.black);
    addMouseListener(this);
    resignButton = new JButton("Resign");
    resignButton.addActionListener(this);
    newGameButton = new JButton("New Game");
    newGameButton.addActionListener(this);
    message = new JLabel("",JLabel.CENTER);
    message.setFont(new Font("Serif", Font.BOLD, 14));
    message.setForeground(Color.green);
    board = new CheckersData();
    doNewGame();
    public void actionPerformed(ActionEvent evt) {
    // Respond to user's click on one of the two buttons.
    Object src = evt.getSource();
    if (src == newGameButton)
    doNewGame();
    else if (src == resignButton)
    doResign();
    void doNewGame() {
    // Begin a new game.
    if (gameInProgress == true) {
    // This should not be possible, but it doens't
    // hurt to check.
    message.setText("Finish the current game first!");
    return;
    board.setUpGame();
    currentPlayer = CheckersData.RED;
    legalMoves = board.getLegalMoves(CheckersData.RED);
    selectedRow = -1;
    message.setText("Red: Make your move.");
    gameInProgress = true;
    newGameButton.setEnabled(false);
    resignButton.setEnabled(true);
    repaint();
    void doResign() {
    if (gameInProgress == false) {
    message.setText("There is no game in progress!");
    return;
    if (currentPlayer == CheckersData.RED)
    gameOver("RED resigns. BLACK wins.");
    else
    gameOver("BLACK resigns. RED wins.");
    void gameOver(String str) {
    message.setText(str);
    newGameButton.setEnabled(true);
    resignButton.setEnabled(false);
    gameInProgress = false;
    void doClickSquare(int row, int col) {
    for (int i = 0; i < legalMoves.length; i++)
    if (legalMoves.fromRow == row && legalMoves[i].fromCol == col) {
    selectedRow = row;
    selectedCol = col;
    if (currentPlayer == CheckersData.RED)
    message.setText("RED: Make your move.");
    else
    message.setText("BLACK: Make your move.");
    repaint();
    return;
    if (selectedRow < 0) {
    message.setText("Click the piece you want to move.");
    return;
    for (int i = 0; i < legalMoves.length; i++)
    if (legalMoves[i].fromRow == selectedRow && legalMoves[i].fromCol == selectedCol
    && legalMoves[i].toRow == row && legalMoves[i].toCol == col) {
    doMakeMove(legalMoves[i]);
    return;
    message.setText("Click the square you want to move to.");
    void doMakeMove(CheckersMove move) {
    board.makeMove(move);
    if (move.isJump()) {
    legalMoves = board.getLegalJumpsFrom(currentPlayer,move.toRow,move.toCol);
    if (legalMoves != null) {
    if (currentPlayer == CheckersData.RED)
    message.setText("RED: You must continue jumping.");
    else
    message.setText("BLACK: You must continue jumping.");
    selectedRow = move.toRow;
    selectedCol = move.toCol;
    repaint();
    return;
    if (currentPlayer == CheckersData.RED) {
    currentPlayer = CheckersData.BLACK;
    legalMoves = board.getLegalMoves(currentPlayer);
    if (legalMoves == null)
    gameOver("BLACK has no moves. RED wins.");
    else if (legalMoves[0].isJump())
    message.setText("BLACK: Make your move. You must jump.");
    else
    message.setText("BLACK: Make your move.");
    else {
    currentPlayer = CheckersData.RED;
    legalMoves = board.getLegalMoves(currentPlayer);
    if (legalMoves == null)
    gameOver("RED has no moves. BLACK wins.");
    else if (legalMoves[0].isJump())
    message.setText("RED: Make your move. You must jump.");
    else
    message.setText("RED: Make your move.");
    selectedRow = -1;
    if (legalMoves != null) {
    boolean sameStartSquare = true;
    for (int i = 1; i < legalMoves.length; i++)
    if (legalMoves[i].fromRow != legalMoves[0].fromRow
    || legalMoves[i].fromCol != legalMoves[0].fromCol) {
    sameStartSquare = false;
    break;
    if (sameStartSquare) {
    selectedRow = legalMoves[0].fromRow;
    selectedCol = legalMoves[0].fromCol;
    repaint();
    public void paintComponent(Graphics g) {
    g.setColor(Color.black);
    g.drawRect(0,0,getSize().width-1,getSize().height-1);
    g.drawRect(1,1,getSize().width-3,getSize().height-3);
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if ( row % 2 == col % 2 )
    g.setColor(Color.lightGray);
    else
    g.setColor(Color.gray);
    g.fillRect(2 + col*20, 2 + row*20, 20, 20);
    switch (board.pieceAt(row,col)) {
    case CheckersData.RED:
    g.setColor(Color.red);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    break;
    case CheckersData.BLACK:
    g.setColor(Color.black);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    break;
    case CheckersData.RED_KING:
    g.setColor(Color.red);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    g.setColor(Color.white);
    g.drawString("K", 7 + col*20, 16 + row*20);
    break;
    case CheckersData.BLACK_KING:
    g.setColor(Color.black);
    g.fillOval(4 + col*20, 4 + row*20, 16, 16);
    g.setColor(Color.white);
    g.drawString("K", 7 + col*20, 16 + row*20);
    break;
    if (gameInProgress) {
    // First, draw a cyan border around the pieces that can be moved.
    g.setColor(Color.cyan);
    for (int i = 0; i < legalMoves.length; i++) {
    g.drawRect(2 + legalMoves[i].fromCol*20, 2 + legalMoves[i].fromRow*20, 19, 19);
    if (selectedRow >= 0) {
    g.setColor(Color.white);
    g.drawRect(2 + selectedCol*20, 2 + selectedRow*20, 19, 19);
    g.drawRect(3 + selectedCol*20, 3 + selectedRow*20, 17, 17);
    g.setColor(Color.green);
    for (int i = 0; i < legalMoves.length; i++) {
    if (legalMoves[i].fromCol == selectedCol && legalMoves[i].fromRow ==
    selectedRow)
    g.drawRect(2 + legalMoves[i].toCol*20, 2 + legalMoves[i].toRow*20, 19, 19);
    public Dimension getPreferredSize() {
    return new Dimension(164, 164);
    public Dimension getMinimumSize() {
    return new Dimension(164, 164);
    public Dimension getMaximumSize() {
    return new Dimension(164, 164);
    public void mousePressed(MouseEvent evt) {
    if (gameInProgress == false)
    message.setText("Click \"New Game\" to start a new game.");
    else {
    int col = (evt.getX() - 2) / 20;
    int row = (evt.getY() - 2) / 20;
    if (col >= 0 && col < 8 && row >= 0 && row < 8)
    doClickSquare(row,col);
    public void mouseReleased(MouseEvent evt) { }
    public void mouseClicked(MouseEvent evt) { }
    public void mouseEntered(MouseEvent evt) { }
    public void mouseExited(MouseEvent evt) { }
    static class CheckersData {
    public static final int
    EMPTY = 0,
    RED = 1,
    RED_KING = 2,
    BLACK = 3,
    BLACK_KING = 4;
    private int[][] board;
    public CheckersData() {
    board = new int[8][8];
    setUpGame();
    public void setUpGame() {
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if ( row % 2 == col % 2 ) {
    if (row < 3)
    board[row][col] = BLACK;
    else if (row > 4)
    board[row][col] = RED;
    else
    board[row][col] = EMPTY;
    else {
    board[row][col] = EMPTY;
    public int pieceAt(int row, int col) {
    return board[row][col];
    public void setPieceAt(int row, int col, int piece) {
    board[row][col] = piece;
    public void makeMove(CheckersMove move) {
    makeMove(move.fromRow, move.fromCol, move.toRow, move.toCol);
    public void makeMove(int fromRow, int fromCol, int toRow, int toCol) {
    board[toRow][toCol] = board[fromRow][fromCol];
    board[fromRow][fromCol] = EMPTY;
    if (fromRow - toRow == 2 || fromRow - toRow == -2) {
    int jumpRow = (fromRow + toRow) / 2;
    int jumpCol = (fromCol + toCol) / 2;
    board[jumpRow][jumpCol] = EMPTY;
    if (toRow == 0 && board[toRow][toCol] == RED)
    board[toRow][toCol] = RED_KING;
    if (toRow == 7 && board[toRow][toCol] == BLACK)
    board[toRow][toCol] = BLACK_KING;
    public CheckersMove[] getLegalMoves(int player) {
    if (player != RED && player != BLACK)
    return null;
    int playerKing;
    if (player == RED)
    playerKing = RED_KING;
    else
    playerKing = BLACK_KING;
    ArrayList moves = new ArrayList();
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if (board[row][col] == player || board[row][col] == playerKing) {
    if (canJump(player, row, col, row+1, col+1, row+2, col+2))
    moves.add(new CheckersMove(row, col, row+2, col+2));
    if (canJump(player, row, col, row-1, col+1, row-2, col+2))
    moves.add(new CheckersMove(row, col, row-2, col+2));
    if (canJump(player, row, col, row+1, col-1, row+2, col-2))
    moves.add(new CheckersMove(row, col, row+2, col-2));
    if (canJump(player, row, col, row-1, col-1, row-2, col-2))
    moves.add(new CheckersMove(row, col, row-2, col-2));
    if (moves.size() == 0) {
    for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
    if (board[row][col] == player || board[row][col] == playerKing) {
    if (canMove(player,row,col,row+1,col+1))
    moves.add(new CheckersMove(row,col,row+1,col+1));
    if (canMove(player,row,col,row-1,col+1))
    moves.add(new CheckersMove(row,col,row-1,col+1));
    if (canMove(player,row,col,row+1,col-1))
    moves.add(new CheckersMove(row,col,row+1,col-1));
    if (canMove(player,row,col,row-1,col-1))
    moves.add(new CheckersMove(row,col,row-1,col-1));
    if (moves.size() == 0)
    return null;
    else {
    CheckersMove[] moveArray = new CheckersMove[moves.size()];
    for (int i = 0; i < moves.size(); i++)
    moveArray[i] = (CheckersMove)moves.get(i);
    return moveArray;
    public CheckersMove[] getLegalJumpsFrom(int player, int row, int col) {
    if (player != RED && player != BLACK)
    return null;
    int playerKing;
    if (player == RED)
    playerKing = RED_KING;
    else
    playerKing = BLACK_KING;
    ArrayList moves = new ArrayList();
    if (board[row][col] == player || board[row][col] == playerKing) {
    if (canJump(player, row, col, row+1, col+1, row+2, col+2))
    moves.add(new CheckersMove(row, col, row+2, col+2));
    if (canJump(player, row, col, row-1, col+1, row-2, col+2))
    moves.add(new CheckersMove(row, col, row-2, col+2));
    if (canJump(player, row, col, row+1, col-1, row+2, col-2))
    moves.add(new CheckersMove(row, col, row+2, col-2));
    if (canJump(player, row, col, row-1, col-1, row-2, col-2))
    moves.add(new CheckersMove(row, col, row-2, col-2));
    if (moves.size() == 0)
    return null;
    else {
    CheckersMove[] moveArray = new CheckersMove[moves.size()];
    for (int i = 0; i < moves.size(); i++)
    moveArray[i] = (CheckersMove)moves.get(i);
    return moveArray;
    } // end getLegalMovesFrom()
    private boolean canJump(int player, int r1, int c1, int r2, int c2, int r3, int c3) {
    if (r3 < 0 || r3 >= 8 || c3 < 0 || c3 >= 8)
    return false;
    if (board[r3][c3] != EMPTY)
    return false;
    if (player == RED) {
    if (board[r1][c1] == RED && r3 > r1)
    return false;
    if (board[r2][c2] != BLACK && board[r2][c2] != BLACK_KING)
    return false;
    return true; // The jump is legal.
    else {
    if (board[r1][c1] == BLACK && r3 < r1)
    return false;
    if (board[r2][c2] != RED && board[r2][c2] != RED_KING)
    return false;
    return true;
    private boolean canMove(int player, int r1, int c1, int r2, int c2) {
    if (r2 < 0 || r2 >= 8 || c2 < 0 || c2 >= 8)
    return false;
    if (board[r2][c2] != EMPTY)
    return false;
    if (player == RED) {
    if (board[r1][c1] == RED && r2 > r1)
    return false;
    return true;
    else {
    if (board[r1][c1] == BLACK && r2 < r1)
    return false;
    return true;
    *..please ... thanks!!*

    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the tags that appear.
    db

Maybe you are looking for

  • Apple Pro keys not working after 10.4.3 Upgrade (!?!)

    Hi All My computer is a dual processor G4 1.42 chrome drive door. I have an Apple Pro keyboard and a Macally 3 button scroll mouse. I just upgraded from 10.3.x (x=4 I think) to 10.4.3 After the upgrade the eject and volume keys on the keyboard don't

  • I am trying to install ITunes on drive D.

    i Have a new PC with a SSD drive which has limited space. When I install ITunes , it give an option to install on another drive. Despite selecting drive D, when I sync my iPhone, it store all the backup data in drive C. This fails as the drive soon r

  • How to default G/L account into Service Entry Sheets

    Hello All, I am trying to set up a Framework order with account assignment U for services. I use this for our contracted employees via infotype 0315. When I generate the service entry sheet in the background via tcode CATM, and try to release the ser

  • Can you retrieve video from iPhone 6 lost after backup?

    I took several pictures and video on new iPhone. I then plugged in iPhone to mac and restored data from previous iPhone without importing video/photos. Is there a way to retrieve this data or did the backup wipe it out for good?

  • After update 4.2.1 unable to access mobile data network

    Hello, yesterday, i have updated to 4.2.1 Today, i have activated the flight modus for a while... Then go back into the normal modus (flight modus off). Now, the access to the mobile data network is never possible. Access via WIFI is allways ok. Now,