Help needed, new to java programming

hi,
I have craeted a Frame with some check boxes and button called "button1".
Can anyone tell me how can i count the number of CHECKED check boxes so that when i press the button1 in my code it should display the result as number of checked check boxes divided by total number of check boxes. It should display the result in a textfield here RESULT textfield in my code
Thanks in advance ...i am sending the code i have written so far....
public class Frame extends java.awt.Frame {
    /** Creates new form Frame */
    public Frame() {
        initComponents();
        setSize(600, 600);
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    private void initComponents() {
        buttonGroup1 = new javax.swing.ButtonGroup();
        checkbox1 = new java.awt.Checkbox();
        checkbox2 = new java.awt.Checkbox();
        checkbox3 = new java.awt.Checkbox();
        button1 = new java.awt.Button();
        textField1 = new java.awt.TextField();
        setLayout(null);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
        checkbox1.setLabel("checkbox1");
        add(checkbox1);
        checkbox1.setBounds(160, 50, 84, 20);
        checkbox2.setLabel("checkbox2");
        add(checkbox2);
        checkbox2.setBounds(160, 70, 84, 20);
        checkbox3.setLabel("checkbox3");
        add(checkbox3);
        checkbox3.setBounds(160, 90, 84, 20);
        button1.setLabel("button1");
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
        add(button1);
        button1.setBounds(150, 180, 57, 24);
        textField1.setText("Result");
        textField1.setName("Result");
        add(textField1);
        textField1.setBounds(260, 180, 44, 20);
        pack();
    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
        // Add your handling code here:
    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
     * @param args the command line arguments
    public static void main(String args[]) {
        new Frame().show();
    // Variables declaration - do not modify
    private java.awt.Button button1;
    private javax.swing.ButtonGroup buttonGroup1;
    private java.awt.Checkbox checkbox1;
    private java.awt.Checkbox checkbox2;
    private java.awt.Checkbox checkbox3;
    private java.awt.TextField textField1;
    // End of variables declaration
}

Two problems in the code you repost-ed:
1. It lacks import statements.
2. There is an extraneous } at the end of the button1ActionPerformed method.
Correct them and it'll work fine. Posting the full source code:
import java.awt.Component;
import java.awt.Checkbox;
public class Frame extends java.awt.Frame
     /** Creates new form Frame */
     public Frame()
          initComponents();
      * This method is called from within the constructor to initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is always
      * regenerated by the Form Editor.
     private void initComponents()
          checkbox1 = new java.awt.Checkbox();
          checkbox2 = new java.awt.Checkbox();
          checkbox3 = new java.awt.Checkbox();
          button1 = new java.awt.Button();
          textField1 = new java.awt.TextField();
          setLayout( null );
          addWindowListener( new java.awt.event.WindowAdapter()
               public void windowClosing( java.awt.event.WindowEvent evt )
                    exitForm( evt );
          checkbox1.setLabel( "checkbox1" );
          add( checkbox1 );
          checkbox1.setBounds( 120, 40, 84, 20 );
          checkbox2.setLabel( "checkbox2" );
          add( checkbox2 );
          checkbox2.setBounds( 120, 60, 84, 20 );
          checkbox3.setLabel( "checkbox3" );
          add( checkbox3 );
          checkbox3.setBounds( 120, 80, 84, 20 );
          button1.setLabel( "button1" );
          button1.addActionListener( new java.awt.event.ActionListener()
               public void actionPerformed( java.awt.event.ActionEvent evt )
                    button1ActionPerformed( evt );
          add( button1 );
          button1.setBounds( 50, 170, 57, 24 );
          textField1.setText( "textField1" );
          add( textField1 );
          textField1.setBounds( 240, 170, 60, 20 );
          pack();
     private void button1ActionPerformed( java.awt.event.ActionEvent evt )
          // Add your handling code here:
          Component[] components = getComponents();
          int numOfCheckBoxes = 0;
          int numChecked = 0;
          for ( int i = 0; i < components.length; i++ )
               if ( components[i] instanceof Checkbox )
                    numOfCheckBoxes++;
                    Checkbox checkBox = (Checkbox) components;
                    if ( checkBox.getState() )
                         numChecked++;
          double ratio = (double) numChecked / (double) numOfCheckBoxes;
          textField1.setText( Double.toString( ratio ) );
     /** Exit the Application */
     private void exitForm( java.awt.event.WindowEvent evt )
          System.exit( 0 );
     * @param args the command line arguments
     public static void main( String args[] )
          new Frame().show();
     // Variables declaration - do not modify
     private java.awt.Button button1;
     private java.awt.Checkbox checkbox1;
     private java.awt.Checkbox checkbox2;
     private java.awt.Checkbox checkbox3;
     private java.awt.TextField textField1;
     // End of variables declaration
I can see from the code that the GUI was generated by a tool. Since you're new to Java programming, I'd recommend ditching the tool and writing everything by hand, otherwise you're not learning much. It's just like when you're learning proofs in Maths, where you start with first principles before making use of the proofs on their own.
Also, it'll help tremendously if you could spend some time going through the Java Tutorial (http://java.sun.com/docs/books/tutorial/). It's free, and I find it very useful.
Hth.

Similar Messages

  • Help Needed on a java program

    I am very new to java and our teacher has given us a program
    that i am having quite a bit of trouble with. I was wondering if anyone could help me out.
    This is the program which i have bolded.
    {You will write a Java class to play the TicTacToe game. This program will have at least two data members, one for the status of the board and one to keep track of whose turn it is. All data members must be private. You will create a user interface that allows client code to play the game.
    The user interface must include:
    � Boolean xPlay(int num) which allows x to play in the square labeled by num. This function will return true if that play caused the game to end and false otherwise.
    � Boolean oPlay(int num) which allows o to play in the square labeled by num. This function will return true if that play caused the game to end and false otherwise.
    � Boolean isEmpty(int num) will check to see if the square labeled by num is empty.
    � Void display() which displays the current game status to the screen.
    � Char whoWon() which will return X, O, or C depending on the outcome of the game.
    � You must not allow the same player to play twice in a row. Should the client code attempt to, xPlay or oPlay should print an error and do nothing else.
    � Also calling whoWon when the game is not over should produce an error message and return a character other than X, O, or C.
    � Client code for the moment is up to you. Assume you have two human players that can enter the number of the square in which they want to play.
    Verifying user input WILL be done by the client code.}

    This is the program which i have bolded.Hmmm, that doesn't look like any programming language I've ever seen. I guess you have the wrong forum here, because it isn't Java.
    That looks like a natural-language programming language that directly understands a homework assignment. Either that, or you really did just post the assignment. You wouldn't have done that though, right?

  • Help needed new to Swing Programming

    Hi,
    I have Crated a JFrame (Frame1) with 4 textfields and a button (by name GetBarchart).
    My question is i will enter some values in 4 textfields and press the GetBarchart button it should display a new JFrame( say Frame2 ) and a Barchart with values taken form the 4 textfields should be displyed.
    NOTE: I should get the BarChart displayed in Frame2 , NOT in Frame1.
    anyhelp is appeciated .
    Thanks in advance

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;
    import org.jfree.chart.*;
    import org.jfree.chart.plot.*;
    import org.jfree.data.category.*;
    import org.jfree.ui.*;
    // Make a main window with a top-level menu: File
    public class MainWindow extends JFrame {
        public MainWindow() {
            super("Menu System Test Window");
            setSize(500, 500);
            // make a top level File menu
            FileMenu fileMenu = new FileMenu(this);
            // make a menu bar for this frame
            // and add top level menus File and Menu
            JMenuBar mb = new JMenuBar();
            mb.add(fileMenu);
            setJMenuBar(mb);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    exit();
        public void exit() {
            setVisible(false); // hide the JFrame
            dispose(); // tell windowing system to free resources
            System.exit(0); // exit
        public static void main(String args[]) {
            MainWindow w = new MainWindow();
            w.setVisible(true);
        private static MainWindow w ;
        protected JTextField t1, t2, t3, t4;
        // Encapsulate the look and behavior of the File menu
        class FileMenu extends JMenu implements ActionListener {
            private MainWindow mw; // who owns us?
            private JMenuItem itmPE   = new JMenuItem("ProductEvaluation");
            private JMenuItem itmExit = new JMenuItem("Exit");
            public FileMenu(MainWindow main) {
                super("File");
                this.mw = main;
                this.itmPE.addActionListener(this);
                this.itmExit.addActionListener(this);
                this.add(this.itmPE);
                this.add(this.itmExit);
            // respond to the Exit menu choice
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == this.itmPE) {
                    JFrame f1 = new JFrame("ProductMeasurementEvaluationTool");
                    f1.setSize(1290,1290);
                    f1.setLayout(null);
                    t1 = new JTextField("0");
                    t1.setBounds(230, 630, 50, 24);
                    f1.add(t1);
                    t2 = new JTextField("0");
                    t2.setBounds(430, 630, 50, 24);
                    f1.add(t2);
                    t3 = new JTextField("0");
                    t3.setBounds(630, 630, 50, 24);
                    f1.add(t3);
                    t4 = new JTextField("0");
                    t4.setBounds(840, 630, 50, 24);
                    f1.add(t4);
                    JLabel l1 = new JLabel("Select the appropriate metrics for Measurement Process Evaluation");
                    l1.setBounds(380, 50, 380, 20);
                    f1.add(l1);
                    JLabel l2 = new JLabel("Architecture Metrics");
                    l2.setBounds(170, 100, 110, 20);
                    f1.add(l2);
                    JLabel l3 = new JLabel("RunTime Metrics");
                    l3.setBounds(500, 100, 110, 20);
                    f1.add(l3);
                    JLabel l4 = new JLabel("Documentation Metrics");
                    l4.setBounds(840, 100, 130, 20);
                    f1.add(l4);
                    JRadioButton rb1 = new JRadioButton("Componenent Metrics",false);
                    rb1.setBounds(190, 140, 133, 20);
                    f1.add(rb1);
                    JRadioButton rb2 = new JRadioButton("Task Metrics",false);
                    rb2.setBounds(540, 140, 95, 20);
                    f1.add(rb2);
                    JRadioButton rb3 = new JRadioButton("Manual Metrics",false);
                    rb3.setBounds(870, 140, 108, 20);
                    f1.add(rb3);
                    JRadioButton rb4 = new JRadioButton("Configuration Metrics",false);
                    rb4.setBounds(190, 270, 142, 20);
                    f1.add(rb4);
                    JRadioButton rb6 = new JRadioButton("DataHandling Metrics",false);
                    rb6.setBounds(540, 270, 142, 20);
                    f1.add(rb6);
                    JRadioButton rb8 = new JRadioButton("Development Metrics",false);
                    rb8.setBounds(870, 270, 141, 20);
                    f1.add(rb8);
                    JCheckBox  c10 = new JCheckBox("Size");
                    c10.setBounds(220, 170, 49, 20);
                    f1.add(c10);
                    JCheckBox c11 = new JCheckBox("Structure");
                    c11.setBounds(220, 190, 75, 20);
                    f1.add(c11);
                    JCheckBox c12 = new JCheckBox("Complexity");
                    c12.setBounds(220, 210, 86, 20);
                    f1.add(c12);
                    JCheckBox c13 = new JCheckBox("Size");
                    c13.setBounds(220, 300, 49, 20);
                    f1.add(c13);
                    JCheckBox c14 = new JCheckBox("Structure");
                    c14.setBounds(220, 320, 75, 20);
                    f1.add(c14);
                    JCheckBox c15 = new JCheckBox("Complexity");
                    c15.setBounds(220, 340, 86, 20);
                    f1.add(c15);
                    JCheckBox c19 = new JCheckBox("Size");
                    c19.setBounds(580, 170, 49, 20);
                    f1.add(c19);
                    JCheckBox c20 = new JCheckBox("Structure");
                    c20.setBounds(580, 190, 75, 20);
                    f1.add(c20);
                    JCheckBox c21 = new JCheckBox("Complexity");
                    c21.setBounds(580, 210, 86, 20);
                    f1.add(c21);
                    JCheckBox c22 = new JCheckBox("Size");
                    c22.setBounds(580, 300, 49, 20);
                    f1.add(c22);
                    JCheckBox c23 = new JCheckBox("Structure");
                    c23.setBounds(580, 320, 75, 20);
                    f1.add(c23);
                    JCheckBox c24 = new JCheckBox("Complexity");
                    c24.setBounds(580, 340, 86, 20);
                    f1.add(c24);
                    JCheckBox c28 = new JCheckBox("Size");
                    c28.setBounds(920, 170, 49, 20);
                    f1.add(c28);
                    JCheckBox c29 = new JCheckBox("Structure");
                    c29.setBounds(920, 190, 75, 20);
                    f1.add(c29);
                    JCheckBox c30 = new JCheckBox("Complexity");
                    c30.setBounds(920, 210, 86, 20);
                    f1.add(c30);
                    JCheckBox c31 = new JCheckBox("Size");
                    c31.setBounds(920, 300, 49, 20);
                    f1.add(c31);
                    JCheckBox c32 = new JCheckBox("Structure");
                    c32.setBounds(920, 320, 75, 20);
                    f1.add(c32);
                    JCheckBox c33 = new JCheckBox("Complexity");
                    c33.setBounds(920, 340, 86, 20);
                    f1.add(c33);
                    ActionListener action = new MyActionListener(f1, t1, t2,t3,t4);
                    JButton b1  = new JButton("Button1");
                    b1.setBounds(230, 600, 120, 24);
                    b1.addActionListener(action);
                    f1.add(b1);
                    JButton b2  = new JButton("Button2");
                    b2.setBounds(430, 600, 120, 24);
                    b2.addActionListener(action);
                    f1.add(b2);
                    JButton b3  = new JButton("Button3");
                    b3.setBounds(630, 600, 120, 24);
                    b3.addActionListener(action);
                    f1.add(b3);
                    JButton b4  = new JButton("Button4");
                    b4.setBounds(840, 600, 120, 24);
                    b4.addActionListener(action);
                    f1.add(b4);
                    JButton b5  = new JButton("Generatechart");
                    b5.setBounds(1040, 600, 120, 24);
                    b5.setBounds(530, 660, 120, 24);//uhrand
                    b5.addActionListener(action);
                    f1.add(b5);
                    f1.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                            System.exit(0);
                    f1.setVisible(true);
                } else {
                    mw.exit();}
        class MyActionListener implements ActionListener {
            private JFrame     f1;
            private JTextField t1;
            private JTextField t2;
            private JTextField t3;
            private JTextField t4;
            private  final DecimalFormat result = new DecimalFormat("0.0");
            public MyActionListener(JFrame f1, JTextField tf1, JTextField tf2,JTextField tf3,JTextField tf4) {
                this.f1 = f1;
                this.t1 = tf1;
                this.t2 = tf2;
                this.t3 = tf3;
                this.t4 = tf4;
            public void actionPerformed(ActionEvent e) {
                String s = e.getActionCommand();
                if (s.equals("Button1")) {
                    Component[] components = this.f1.getContentPane().getComponents();
                    int numOfCheckBoxes = 81;
                    int numChecked = 0;
                    for (int i = 0; i < components.length; i++)
                        if (components[i] instanceof JCheckBox)
                            if (((JCheckBox)components).isSelected())
    numChecked++;
    double ratio = ((double) numChecked / (double) numOfCheckBoxes)*100;
    this.t1.setText(result.format(ratio) );
    }else if (s.equals("Button2")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+5);
    this.t2.setText(result.format(ratio) );
    }else if (s.equals("Button3")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+10);
    this.t3.setText(result.format(ratio) );
    }else if (s.equals("Button4")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+15);
    this.t4.setText(result.format(ratio) );
    }else if (s.equals("Generatechart")) {
    Bar_Chart barChart = new Bar_Chart("Bar Chart", t1.getText(),t2.getText(),t3.getText(),t4.getText());
    barChart.pack();
    RefineryUtilities.centerFrameOnScreen(barChart);
    barChart.setVisible(true);
    class Bar_Chart extends JDialog {
    String t1,t2,t3,t4;
    public Bar_Chart(String title, String t1, String t2, String t3, String t4) {
    this.t1=t1;
    this.t2=t2;
    this.t3=t3;
    this.t4=t4;
    setModal(true);
    setTitle(title);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    CategoryDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartPanel);
    private CategoryDataset createDataset() {
    String series1 = "First";
    String series2 = "Second";
    String series3 = "Third";
    String series4 = "Fourth";
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(Double.parseDouble(t1.replace(',','.')), series1, "");
    dataset.addValue(Double.parseDouble(t2.replace(',','.')), series2, "");
    dataset.addValue(Double.parseDouble(t3.replace(',','.')), series3, "");
    dataset.addValue(Double.parseDouble(t4.replace(',','.')), series4, "");
    return dataset;
    private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(
    "Bar Chart", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.VERTICAL, // orientation
    true, // include legend
    true, // tooltips?
    false // URLs?
    return chart;

  • Need help in my assignment, Java programing?

    Need help in my assignment, Java programing?
    It is said that there is only one natural number n such that n-1 is a square and
    n + 1 is a cube, that is, n - 1 = x2 and n + 1 = y3 for some natural numbers x and y. Please implement a program in Java.
    plz help!!
    and this is my code
    but I don't no how to finsh it with the right condition!
    plz heelp!!
    and I don't know if it right or wrong!
    PLZ help me!!
    import javax.swing.JOptionPane;
    public class eiman {
    public static void main( String [] args){
    String a,b;
    double n,x,y,z;
    boolean q= true;
    boolean w= false;
    a=JOptionPane.showInputDialog("Please enter a number for n");
    n=Double.parseDouble(a);
    System.out.println(n);
    x=Math.sqrt(n-1);
    y=Math.cbrt(n+1);
    }

    OK I'll bite.
    I assume that this is some kind of assignment.
    What is the program supposed to do?
    1. Figure out the value of N
    2. Given an N determine if it is the correct value
    I would expect #1, but then again this seem to be a strange programming assignment to me.
    // additions followI see by the simulpostings that it is indeed #1.
    So I will give the tried and true advice at the risk of copyright infringement.
    get out a paper and pencil and think about how you would figure this out by hand.
    The structure of a program will emerge from the mists.
    Now that I think about it that advice must be in public domain by now.
    Edited by: johndjr on Oct 14, 2008 3:31 PM
    added additional info

  • New TO JAVA Programming

    Dear Forummembers,
    I am student doing postgraduate studies in IT.i have some queries related to one of my programming staff.i am very much new into Java programming and i am finding it a bit difficult to handle this program.The synopsis of the program is given below -
    You are required to design and code an object-oriented java program to process bookings for a theatre perfomance.
    Your program will read from a data file containing specifications of the performance,including the names of the theatre, the play and its author and the layout of the theatre consisting of the number of seats in each row.
    It will then run a menu driven operation to accept theatre bookings or display the current
    status of seating in the theatre.
    The name of the file containing the details of the performance and the theatre should be
    provided at the command line, eg by running the program with the command:
    java Booking Theatre.txt
    where Theare.txt represents an example of the data file.
    A possible data file is:
    Opera
    U and Me
    Jennifer Aniston
    5 10 10 11 12 13 14
    The data provided is as follows
    Line 1
    Name of the Theatre
    Line 2
    Name of the play being performed
    Line 3
    Name of the author of the play being performed
    Line 4
    A list of the lengths (number of seats) of each row in the theatre, from front to
    back.
    The program must start by reading this file, storing all the appropriate parameters and
    establishing an object to accept bookings for this performance with all details for the theatre
    and performance.
    The program should then start a loop in which a menu is presented to the user, eg:
    Select from the following:
    B - Book seats
    T - Display Theatre bookings
    Q - Quit from the program
    Enter your choice:
    And keep performing selected operations until the user�s selects the quit option, when the
    program should terminate.
    T - Display Theatre bookings
    The Display Theatre Bookings option should display a plan of the theatre. Every available
    seat should be displayed containing its identification, while reserved seats should contain an
    Rows in each theatre are indicated by letters starting from �A� at the front. Seats are
    numbered from left to right starting from 1. A typical seat in the theatre might be designated
    D12, representing seat 12 in row D.
    B - Book seats
    The booking of seats is to offer a number of different options.
    First the customer must be asked how many adjacent seats are
    required. Then start a loop offering a further menu of choices:
    Enter one of the following:
    The first seat of a selected series, eg D12
    A preferred row letter, eg F
    A ? to have the first available sequence selected for you
    A # to see a display of all available seats
    A 0 to cancel your attempt to book seats
    Enter your selection:
    1. If the user enters a seat indentifier such B6, The program should attempt to
    reserve the required seats starting from that seat. For example if 4 seats are
    required from B6, seats B6, B7, B8 and B9 should be reserved for the customer,
    with a message confirming the reservation and specifying the seats reserved..
    Before this booking can take place, some testing is required. Firstly, the row
    letter must be a valid row. Then the seat number must be within the seats in the
    row and such that the 4 seats would not go beyond the end of the row. The
    program must then check that none of the required seats is already reserved.
    If the seats are invalid or already reserved, no reservation should be made and the
    booking menu should be repeated to give the customer a further chance to book
    seats.
    If the reservation is successful, return to the main menu.
    2. The user can also simply enter a row letter, eg B.IN this case, the program should
    first check that the letter is a valid row and then offer the user in turn each
    adjacent block of the required size in the specified row and for each ask whether
    the customer wants to take them. Using the partly booked theatre layout above, if
    the customer wanted 2 seats from row B, the customer should be offered first:
    Seats B5 to B6
    then if the customer does not want them:
    Seats B10 to B11
    and finally
    Seats B11 to B12
    If the customer selects a block of seats, then return to the main menu. If none are
    selected, or there is no block of the required size available in the row, then report
    that no further blocks of the required size are available in the row and repeat the
    booking menu.
    3. If the user enters a ? the program should offer the customer every block of seats
    of the required size in the whole theatre. This process should start from the first
    row and proceed back a row at a time. For example, again using the partially
    booked theatre shown above, if the user requested 9 seats, the program should
    offer in turn:
    Seats A1 to A9
    Seats C1 to C9
    Seats C2 to C10
    Seats E3 to E11
    Seats E4 to E12
    If the customer selects a block of seats, then return to the main menu. If none are
    selected, or there is no block of the required size available in the whole theatre,
    then report that no further blocks of the required size are available and repeat the
    booking menu.
    4. If the user enters a # the program should display the current status of the seating
    in the theatre, exactly the same as for the T option from the main menu and then
    repeat the booking menu.
    5. If the user enters a 0 (zero), the program should exit from the booking menu back
    to the main menu. If for example the user wanted 9 seats and no block of 9 was
    left in the theatre, he would need to make two separate smaller bookings.
    The program should perform limited data validation in the booking process. If a single
    character other than 0, ? and # is entered, it should be treated as a row letter and then tested
    for falling within the range of valid rows, eg A to H in the example above. Any invalid row
    letters should be rejected.
    If more than one character is entered, the first character should be tested as a valid row letter,
    and the numeric part should be tested for falling within the given row. You are NOT
    required to test for valid numeric input as this would require the use of Exception handling.
    You are provided with a class file:
    Pad.java
    containing methods that can be used for neat alignment of the seat identifiers in the theatre
    plan.
    File Processing
    The file to be read must be opened within the program and if the named file does not exist, a
    FileNotFoundException will be generated. It is desirable that this Exception be caught and
    a corrected file name should be asked for.
    This is not required for this assignment, as Exception handling has not been covered in this
    Unit. It will be acceptable if the method simply throws IOException in its heading.
    The only checking that is required is to make sure that the user does supply a file on the
    command line, containing details of the performance. This can be tested for by checking the
    length of the parameter array args. The array length should be 1. If not, display an error
    message telling the user the correct way to run the program and then terminate the program
    System.exit(0);
    The file should be closed after reading is completed.
    Program Requirements
    You are expected to create at least three classes in developing a solution to this problem.
    There should be an outer driving class, a class to represent the theatre performance and its
    bookings and a class to represent a single row within the theatre.
    You will also need to use arrays at two levels. You will need an array of Rows in the Theatre
    class.
    Each Row object will need an array of seats to keep track of which seats have been reserved.
    Your outer driving class should be called BookingOffice and should be submitted in a file named BookingOffice.java
    Your second, third and any additional classes, should be submitted in separate files, each
    class in a .java file named with the same name as the class
    I am also very sorry to give such a long description.but i mainly want to know how to approach for this program.
    also how to designate each row about it's column while it is being read from the text file, how to store it, how to denote first row as row A(second row as row B and so on) and WHICH CLASS WILL PERFORM WHICH OPERATIONS.
    pls do give a rough guideline about designing each class and it's reponsibilty.
    thanking u and looking forward for your help,
    sincerely
    RK

    yes i do know that........but can u ppl pls mention
    atleast what classes shud i consider and what will be
    the functions of each class?No, sorry. Maybe somebody else will, but in general, this is not a good question for this forum. It's too broad, and the question you're asking is an overall problem solving approach that you should be familiar with at this point.
    These forums are best suited to more specific questions. "How do I approach this homework?" is not something that most people are willing or able to answer in a forum like this.

  • Urgent help needed - new to Macs, accidently cut and paste over top of photo folder and now no sign of folder or file, no auto back-up in place, how can I restore photos pls

    Urgent help needed - new to Macs, accidently cut and paste over top of photo folder and now no sign of folder or file, no auto back-up in place, how can I restore photos pls

    Thanks for prompt reply, yes we have tried that but have now closed down the browser we where the photos were.
    We haven't sent up time machine, do you know whether there is any roll-back function on a Mac?
    Thanks

  • Need help in creating a java program

    Hi everyone.
    I'd like to say before i start about my problem, that i've only begun learning java and my teacher hasn't explained anything at all. He only showed us by doing it himself and then showing us the final version. I've searched a little on how to program but i get little success in finding a good tutorial.
    I need help creating a program which has been assigned to me due in a few days in which i can't contact my teacher for help.
    I need to write a java program which inputs 3 items. The number of kilometres you drove, the number of litres of gas you used and the price you paid for the gas. Then, the program must calculate the number of litres used per 100km driven, which is litres divided by kilometres times 100, how much it costs to drive 100km, which is the result (a) times the price per litre and the number of miles per American gallon of gas ( one American gallon = 3.785 litres, and one mile = 1.609 km.
    The program has to output my name, the inputs given, the results computed and a message saying "Program Complete".
    To give you what i've done to begin with, from what i understood, is:
    import javax.swing.JOptionPane;
    public class prog1
         public static void main(String args[])
              final double americanGallon = 3.785;
              final double mile = 1.609;
              kilometresDriven,
              gasUsed;
              priceOfLiterGas;
              System.out.println("My Name");
              System.out.println("Number of kilometres driven:");
              kilometresDriven = JOptionPane.showInputDialog ("Kilometres Driven");
              System.out.println("Number of Litres of gas used:");
              gasUsed = JOptionPane.showInputDialog ("Litres of gas used");
              System.out.println("Price of a liter of gas:");
              priceOfLiterGas = JoptionPane.showInputDialog("Price per liter");
    Up to now, that's all i've got. i know i'm wrong, but i'm not sure how to do this. Could someone give me an outline of what this program is suppose to look like?
    Thanks in advance.

    Here's an update on my program. I've worked on certain details and would need your comments whether it contains errors. I'd also want to know if it would work or not because i don't know how to check it on my computer.
    Here's the update:
    import javax.swing.JOptionPane;
    public class Prog1
    public static void main(String args[])
    String name;
    double kmDriven;
    double litresUsed;
    double pricePaidForGas;
    double priceOfALiter;
    name = JOptionPane.showInputDialog("Name");
    input = JOptionPane.showInputDialog("Number of km driven");
    kmDriven = Double.parseDouble (input);
    input = JOptionPane.showInputDialog("Number of litres of gas used");
    litresUsed = Double.parseDouble (input);
    input = JOptionPane.showInputDialog("Price paid for gas");
    pricePaidForGas = Double.parseDouble (input);
    input = JOptionPane.showInputDialog("Price of a litre of gas");
    priceOfALiter = Double.parseDouble (input);
    a = (litresUsed/kmDriven)*100;
    b = ((litresUsed/kmDriven)*100)*priceOfALiter);
    c = (kmDriven/1.609)
    System.out.println("Name:" + name);
    System.out.println("Number of litres used per 100km:" + a);
    System.out.println("Cost of driving 100km" + b);
    System.out.println("Number of miles per American Gallon of Gas:" + c);
    System.out.println("Program Complete");
    System.exit(0);
    Comments please.
    Thanks in advance

  • Desperately need some help with client-server java programming

    Hi all,
    I'm new to client server java programming. I would like to work on servlets and apache tomcat. I installed the apache tomcat v 5.5 into my machine and i have sun java 6 also. I created a java applet class to be as a client and embed it into an html index file, like this:
    <applet code="EchoApplet.class" width="300" height="300"></applet>However, when I try to run the html file on the localhost, it print this error: classNotFoundException, couldn't load "EchoApplet.class" class. On the other hand, when I open the index file on applet viewer or by right clicking, open with firefox version 3, it works.
    I thought that the problem is with firefox, but after running the applet through the directory not the server, i found that the problem is not any more with firefox.
    Can anyone help me to solve this problem. I'm working on it for 5 days now and nothing on the net helped me. I tried a lot of solutions.
    Any help?

    arun,
    If the browser is going to execute $myApplet, first it must get the $myApplet.class from the server, right?
    So it follows that:
    1. $myApplet.class must be acessible to server, and
    2. the server must know exactly where to find $myApplet.class
    So, the simplest solution is to is put the $myApplet.class in the same directory as the HTML file which uses it... then your applet tag is simple:
      <applet height="200" width="400" code="$myApplet.class" ></applet>* The height & width attributes are required
    * Note the +.class+ is required in the code attribute (a common mistake).
    * This works uniformly (AFAIK) accross all java-enabled browsers.
    * There are incompatibilities with the codebase attribute. Poo!
    Cheers. Keith.

  • Need help with running a Java program on Linux

    I am trying to get a Java program to run on a Linux machine. The program is actually meant for a Mac computer. I want to see if someone with Java experience can help me determine what is causing the program to stall. I was successful in getting it installed on my Linux machine and to partially run.
    The program is an interface to a database. I get the login screen to appear, but then once I enter my information and hit enter the rest of the program never shows, however, it does appear to connect in the background.
    Here is the error when I launch the .jar file from the command screen:
    Exception in thread "main" java.lang.IllegalArgumentException: illegal component position
    at java.awt.Container.addImpl(Unknown Source)
    at java.awt.Container.add(Unknown Source)
    I am not a programmer and I am hoping this will make some sense to someone. Any help in resolving this is greatly appreciated!

    Well, without knowing a little bit about programming, and how to run your debugger, I don't think you're going to fix it. The IllegalArgumentException is saying that some call does not like what it's getting. So you'll have to go in an refactor at least that part of the code.

  • Please help me in this tough problem in Java...im just new in Java program

    my teacher give this as a problem. so tough. we are just starting and we are now in control structures. please help me to finish this problem. And my problem is...
    Write an astrology program. The user types in his or her birthday(month,day,year),
    and the program responds with the user's zodiac sign, the traits associated with each sign
    the user's age(in years,months,day), the animal sign for the year(e.g., Year of the Pig,
    Year of the Tiger), the traits associated with each animal sign, and if the year is a leap
    year or not. The dates covered for each sign can be searched through the horoscope section
    of a newspaper or through the internet. Then enhance your program so that if the user is one
    or two days away from the adjacent sign, the program outputs the nearest adjacent sign as well
    as the traits associated with the nearest sign. The month may be entered as a number from 1 to 12
    or in words, i.e.,January to December. Limit the year of the birthday from 1900 to 2010 only.
    The program should allow the user to repeat the entire process as often as desired.
    You can use:
    import java.text.DateFormat;
    import java.util.Date;
    import java.util.Calendar;
    please...those who are genius out there in java program...help us to pass this project. Im begging! thanks!

    Frowner_Stud wrote:
    According to the second commandment: Thou shall not use the name of the Lord in vain.Is this not the definition of ironic, Mr. Morality?
    i am not cheating. And more of the same.
    we all know that an assignment is an assignment. a homework. homework means you can raise other help from somebody so that you will know the answer.You're not asking for "help" bucko, because you've been given decent help but have chosen to ignore it. No, you're asking for someone to do the work for you, and you may call it what you want, but in anyone else's book, that's cheating.
    dont be fool enough to reply if you dont know the reason why i am typing here Don't be fool enough to think that you can control who can or can't respond.
    because if you are in my part and if i know the answer there is no doubt that i will help you as soon as possible! Just because you have low morals doesn't mean that the rest of us do.
    Thanks for time of reading and God bless you including you family!and to you and yours. Have a blessed day.

  • Challange for you, help for me! java program

    I am a beginning java student and desparately (again) in help of someone who will check my java program. See below what they want from me, and try to make a program of it that works in all the ways that are asked. Thank you for helping me, i am running out of time.
    Prem Pradeep
    [email protected]
    Catalogue Manager II
    Specification:
    1.     Develop an object to represent to encapsulate an item in a catalogue. Each CatalogueItem has three pieces of information: an alphanumeric catalogue code, a name, and a price (in dollars and cents), that excludes sales tax. The object should also be able to report the price, inclusive of a 15% sales tax, and the taxed component of the price.
    2.     Data input will come from a text file, whose name is passed in as the first command-line argument to the program. This data file may include up to 30 data items (the program will need to be able to support a variable number of actual items in the array without any errors).
    3.     The data lines will be in the format: CatNo:Description:Price Use a StringTokenizer object to separate these data lines into their components.
    4.     A menu should appear, prompting the user for an action:
    a.     Display all goods: this will display a summary (in tabulated form) of all goods currently stored in the catalogue: per item the category, description, price excluding tax, payable tax and price including tax.
    b.     Dispfay cheapest/dearest goods: this will display a summary of all the cheapest and most expensive item(s) in the catalogue. In the case of more than one item being the cheapest (or most expensive), they should all be listed.
    c.     Sort the list: this will use a selection sort algorithm to sort the list in ascending order, using the catalogue number as the key.
    d.     Search the list: this will prompt the user for a catalogue number, and use a binary search to find the data. If the data has not yet been sorted, this menu option should not operate, and instead display a message to the user to sort the data before attempting a search
    5.     Work out a way to be able to support the inc tax/ex tax price accessors, and the tax component accessor, without needing to store any additional information in the object.
    6.     Use modifiers where appropriate to:
    a.     Ensure that data is properly protected;
    b.     Ensure that the accessors and mutators are most visible;
    c.     The accessors and mutators for the catalogue number and description cannot be overridden.
    d.     The constant for the tax rate is publicly accessible, and does not need an instance of the class present in order to be accessible.
    7.     The program should handle all exceptions wherever they may occur (i.e. file 1/0 problems, number formatting issues, etc.) A correct and comprehensive exception handling strategy (leading to a completely robust program) will be necessary and not an incomplete strategy (i.e. handling incorrect data formats, but not critical errors),
    Sample Execution
    C:\> java AssignmentSix mydata.txt
    Loading file data from mydata.txt ...17 item(s) OK
    CATALOGUE MANAGER: MAIN MENU
    ============================
    a) display all goods b) display cheapest/dearest goods
    c) sort the goods list d) search the goods list
    e) quit
    Option: d
    The goods cannot be searched, as the list is not yet sorted.
    CATALOGUE MANAGER: MAIN MENU
    ============================
    a) display all goods b) display cheapest/dearest goods
    c) sort the goods list d) search the goods list
    e) quit
    Option: b
    CHEAPEST GOODS IN CATALOGUE
    Cat      Description      ExTax      Tax      IncTax
    BA023      Headphones      23.00      3.45      26.45
    JW289      Tape Recorder     23.00      3.45      26.45
    MOST EXPENSIVE GOODS IN CATALOGUE
    Cat      Description      ExTax      Tax      IncTax
    ZZ338      Wristwatch      295.00 44.25      339.25
    CATALOGUE MANAGER: MAIN MENU
    ============================
    a) display all goods b) display cheapest/dearest goods
    c) sort the goods list d) search the goods list
    e) quit
    Option: c
    The data is now sorted.
    CATALOGUE MANAGER: MAIN MENU
    ============================
    a) display all goods b) display cheapest/dearest goods
    c) sort the goods list d) search the goods list
    e) quit
    Option: d
    Enter the catalogue number to find: ZJ282
    Cat Description ExTax Tax IncTax
    ZJ282 Pine Table 98.00 14.70 112.70
    CATALOGUE MANAGER: MAIN MENU
    ============================
    a) display all goods b) display cheapest/dearest goods
    c) sort the goods list d) search the goods list
    e) quit
    Option: e
    Here you have the program as far as I could get. Please try to help me make it compact and implement a sorting method.
    Prem.
    By the way: you can get 8 Duke dollars (I have this topic also in the beginnersforum)
    //CatalogueManager.java
    import java.io.*;
    import java.text.DecimalFormat;
    import java.util.StringTokenizer;
    public class CatalogueManager {
    // private static final double TAXABLE_PERCENTAGE = 0.15;
    // Require it to be publicly accessible
    // static means it is class variable, not an object instance variable.
    public static final double TAXABLE_PERCENTAGE = 0.15;
    private String catalogNumber;
    private String description;
    private double price;
    /** Creates a new instance of CatalogueManager */
    public CatalogueManager() {
    catalogNumber = null;
    description = null;
    price = 0;
    public CatalogueManager(String pCatalogNumber, String pDescription, double pPrice) {
    catalogNumber = pCatalogNumber;
    description = pDescription;
    price = pPrice;
    // the mutators must be most visible
    // the final keyword prevents overridden
    public final void setCatalogNumnber(String pCatalogNumber) {
    catalogNumber = pCatalogNumber;
    // the mutators must be most visible
    // the final keyword prevents overridden
    public final String getCatalogNumber() {
    String str = catalogNumber;
    return str;
    // the mutators must be most visible
    // the final keyword prevents overridden
    public final void setDescription(String pDescription) {
    description = pDescription;
    // the accessors must be most visible
    // the final keyword prevents overridden
    public final String getDescription() {
    String str = description;
    return str;
    // If the parameter is not a double type, set the price = 0;
    // the mutators must be most visible
    public boolean setPrice(String pPrice) {
    try {
    price = Double.parseDouble(pPrice);
    return true;
    catch (NumberFormatException nfe) {
    price = 0;
    return false;
    // the accessors must be most visible
    public double getPrice() {
    double rprice = price;
    return formatDouble(rprice);
    double getTaxAmount(){
    double rTaxAmount = price * TAXABLE_PERCENTAGE;
    return formatDouble(rTaxAmount);
    double getIncTaxAmount() {
    double rTaxAmount = price * (1 + TAXABLE_PERCENTAGE);
    return formatDouble(rTaxAmount);
    double formatDouble(double value) {
    DecimalFormat myFormatter = new DecimalFormat("###.##");
    String str1 = myFormatter.format(value);
    return Double.parseDouble(str1);
    public static void main(String[] args) throws IOException {
    final int MAX_INPUT_ALLOW = 30;
    int MAX_CURRENT_INPUT = 0;
    FileReader fr;
    BufferedReader br;
    CatalogueManager[] catalogList = new CatalogueManager[MAX_INPUT_ALLOW];
    String str;
    char chr;
    boolean bolSort = false;
    double cheapest = 0;
    double mostExpensive = 0;
    String header = "Cat\tDescription\tExTax\tTax\tInc Tax";
    String lines = "---\t-----------\t------\t---\t-------";
    if (args.length != 1) {
    System.out.println("The application expects one parameter only.");
    System.exit(0);
    try {
    fr = new FileReader(args[0]);
    br = new BufferedReader(fr);
    int i = 0;
    while ((str = br.readLine()) != null) {
    catalogList[i] = new CatalogueManager();
    StringTokenizer tokenizer = new StringTokenizer(str, ":" );
    catalogList.setCatalogNumnber(tokenizer.nextToken().trim());
    catalogList[i].setDescription(tokenizer.nextToken().trim());
    if (! catalogList[i].setPrice(tokenizer.nextToken())){
    System.out.println("The price column cannot be formatted as dobule type");
    System.out.println("Application will convert the price to 0.00 and continue with the rest of the line");
    System.out.println("Please check line " + i);
    if (catalogList[i].getPrice() < cheapest) {
    cheapest = catalogList[i].getPrice();
    if (catalogList[i].getPrice() > mostExpensive) {
    mostExpensive = catalogList[i].getPrice();
    i++;
    fr.close();
    MAX_CURRENT_INPUT = i;
    catch (FileNotFoundException fnfe) {
    System.out.println("Input file cannot be located, please make sure the file exists!");
    System.exit(0);
    catch (IOException ioe) {
    System.out.println(ioe.getMessage());
    System.out.println("Application cannot read the data from the file!");
    System.exit(0);
    boolean bolLoop = true;
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    do {
    System.out.println("");
    System.out.println("CATALOGUE MANAGER: MAIN MENU");
    System.out.println("============================");
    System.out.println("a) display all goods b) display cheapest/dearest goods");
    System.out.println("c) sort the goods list d) search the good list");
    System.out.println("e) quit");
    System.out.print("Option:");
    try {
    str = stdin.readLine();
    if (str.length() == 1){
    str.toLowerCase();
    chr = str.charAt(0);
    switch (chr){
    case 'a':
    System.out.println(header);
    System.out.println(lines);
    for (int i = 0; i < MAX_CURRENT_INPUT; i++){
    System.out.println(catalogList[i].getCatalogNumber() + "\t" +
    catalogList[i].getDescription() + "\t" +
    catalogList[i].getPrice() + "\t" +
    catalogList[i].getTaxAmount() + "\t" +
    catalogList[i].getIncTaxAmount());
    System.out.println("");
    break;
    case 'b':
    System.out.println("");
    System.out.println("CHEAPEST GOODS IN CATALOGUE");
    System.out.println(header);
    System.out.println(lines);
    for (int i = 0; i < MAX_CURRENT_INPUT; i++){
    if (catalogList[i].getPrice() == cheapest){
    System.out.println(catalogList[i].getCatalogNumber() + "\t" +
    catalogList[i].getDescription() + "\t" +
    catalogList[i].getPrice() + "\t" +
    catalogList[i].getTaxAmount() + "\t" +
    catalogList[i].getIncTaxAmount());
    System.out.println("");
    System.out.println("MOST EXPENSIVE GODS IN CATALOGUE");
    System.out.println(header);
    System.out.println(lines);
    for (int i = 0; i < MAX_CURRENT_INPUT; i++){
    if (catalogList[i].getPrice() == mostExpensive) {
    System.out.println(catalogList[i].getCatalogNumber() + "\t" +
    catalogList[i].getDescription() + "\t" +
    catalogList[i].getPrice() + "\t" +
    catalogList[i].getTaxAmount() + "\t" +
    catalogList[i].getIncTaxAmount());
    System.out.println("");
    break;
    case 'c':
    if (bolSort == true){
    System.out.println("The data has already been sorted");
    else {
    System.out.println("The data is not sorted");
    break;
    case 'd':
    break;
    case 'e':
    bolLoop = false;
    break;
    default:
    System.out.println("Invalid choice, please re-enter");
    break;
    catch (IOException ioe) {
    System.out.println("ERROR:" + ioe.getMessage());
    System.out.println("Application exits now");
    System.exit(0);
    } while (bolLoop);

    One thing you're missing totally is CatalogueItem!! A CatalogueManager manages the CatalogueItem's, and is not an CatalogueItem itself. So at least you have to have this one more class CatalogueItem.
    public class CatalogueItem {
    private String catalogNumber;
    private String description;
    private double price;
    //with all proper getters, setters.
    Then CatalogueManager has a member variable:
    CatalogueItem[] items;
    Get this straight and other things are pretty obvious...

  • Help needed with JNI -  java.lang.UnsatisfiedLinkError

    I need some help with JNI. I am running on Sun Solaris 7 using their CC compiler. I wrote a simple java program that calls a native method to get a pid. Everything work until I use cout or cerr. Can anyone help? Below is what I am working with.
    Note: The application works. The problem is when the C++ code tries to display text output.
    My error log is as follows:
    java Pid
    Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/dew/test/libPid.so: ld.so.1: /usr/j2se/bin/../bin/sparc/native_threads/java: fatal: relocation error: file /home/dew/test/libPid.so: symbol __1cDstdEcerr_: referenced symbol not found
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1382)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
    at java.lang.Runtime.loadLibrary0(Runtime.java:749)
    at java.lang.System.loadLibrary(System.java:820)
    at Pid.<clinit>(Pid.java:5)
    Pid.java
    ========
    * Pid: Obtains the pid from the jvm.
    class Pid {
    static { System.loadLibrary("Pid"); }
    public native int getPid();
    public static void main(String args[])
    System.out.println("Before construction of Pid");
    Pid z = new Pid();
    System.out.println(z.getPid());
    z = null;
    Pid.cpp
    =========
    * Native method that obtains and returns the processid.
    #include "Pid.h"
    #include "unistd.h"
    #include <iostream.h>
    JNIEXPORT jint JNICALL Java_Pid_getPid(JNIEnv *env, jobject obj) {
    /* cout << "Getting pid\n"; */
    cerr << "Getting pid\n";
    /* printf("Getting pid\n"); */
    return getpid();

    I forgot to include my build information.
    JAVA_HOME = /usr/j2se/
    LD_LIBRARY_PATH = ./:/opt/readline/lib:/opt/termcap/lib:/usr/bxpro/xcessory/lib:/${JAVA_HOME}/lib:/usr/RogueWave/workspaces/SOLARIS7/SUNPRO50/0d/lib:/usr/RogueWave/workspaces/SOLARIS7/SUNPRO50/3d/lib:/usr/sybase/lib
    javac Pid.java
    javah Pid
    CC -G -I${JAVA_HOME}/include -I${JAVA_HOME}/include/solaris Pid.cpp -o libPid.so
    Thanks again,
    Don

  • Books & Tools: Help needed for Begining Java....

    Hi,
    I am a Computer science Graduate & working. I am new to Java but not Programming. I have some knowledge on OOPS concepts, .Net, Java, C# & web development.
    I need Help To pick the Best Book/Books that can make me comfortable in programming Java & Understanding whole Java concept.
    I followed many books but found they are not following the Right approach.
    I would appreciate if someone can suggest me a Complete Book/Books, which you think have helped.
    Thanks.

    This is the starter set:
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com . A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoritative than this.

  • Need to write java program to convert english to pirate talk

    yeah i know its not original but i basically need java program that will translate english sentences into pirate talk using this user interface.
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.awt.*;
    import javax.swing.*;
    public class boy extends JFrame
    JTextArea englishtxt;
    JLabel head,privatetxtwords;
    JButton translateengtoprivatewords;
    Container c1;
    public boy()
            super("HAKIMADE");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBackground(Color.white);
            setLocationRelativeTo(null);
            c1 = getContentPane();
             head = new JLabel(" English to private talk Translator");
             englishtxt = new JTextArea("Type your text here", 10,50);
             translateengtoprivatewords = new JButton("Translate");
             privatetxtwords = new JLabel();
            JPanel headlabel = new JPanel();
            headlabel.setLayout(new FlowLayout(FlowLayout.CENTER));
            headlabel.add(head);
            JPanel englishtxtpanel = new JPanel();
            englishtxtpanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,40));
            englishtxtpanel.add(englishtxt);
             JPanel panel1 = new JPanel();
             panel1.setLayout(new BorderLayout());
             panel1.add(headlabel,BorderLayout.NORTH);
             panel1.add(englishtxtpanel,BorderLayout.CENTER);
            JPanel translateengtoprivatewordspanel = new JPanel();
            translateengtoprivatewordspanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,40));
            translateengtoprivatewordspanel.add(translateengtoprivatewords);
             JPanel panel2 = new JPanel();
             panel2.setLayout(new BorderLayout());
             panel2.add(translateengtoprivatewordspanel,BorderLayout.NORTH);
             panel2.add(privatetxtwords,BorderLayout.CENTER);
             JPanel mainpanel = new JPanel();
             mainpanel.setLayout(new BorderLayout());
             mainpanel.add(panel1,BorderLayout.NORTH);
             mainpanel.add(panel2,BorderLayout.CENTER);
             c1.add(panel1, BorderLayout.NORTH);
             c1.add(panel2);
    public static void main(final String args[])
            boy  mp = new boy();
             mp.setVisible(true);
    }here is a basic idea of what i need in javascript:
    <script LANGUAGE="JavaScript">
        PHRASES = [["hello", "ahoy"], ["hi", "yo-ho-ho"], ["pardon me", "avast"],
                   ["excuse me", "arrr"], ["yes", "aye"],
                   ["my", "me"], ["friend", "me bucko"], ["sir", "matey"],
                   ["madam", "proud beauty"], ["miss", "comely wench"],
                   ["stranger", "scurvy dog"], ["officer", "foul blaggart"],
                   ["where", "whar"], ["is", "be"], ["are", "be"], ["am", "be"],
                   ["the", "th'"], ["you", "ye"], ["your", "yer"],
                   ["tell", "be tellin'"], ["know", "be knowin'"],
                   ["how far", "how many leagues"], ["old", "barnacle-covered"],
                   ["attractive", "comely"], ["happy", "grog-filled"], ["quickly", "smartly"],
                   ["nearby", "broadside"], ["restroom", "head"], ["restaurant", "galley"],
                   ["hotel", "fleabag inn"], ["pub", "Skull & Scuppers"], ["mall", "market"],
                   ["bank", "buried treasure"], ["die", "visit Davey Jones' Locker"],
                   ["died", "visited Davey Jones' Locker"], ["kill", "keel-haul"],
                   ["killed", "keel-hauled"], ["sleep", "take a caulk"],
                   ["stupid", "addled"], ["after", "aft"], ["stop", "belay"],
                   ["nonsense", "bilge"], ["officer", "bosun"], ["ocean", "briny deep"],
                   ["song", "shanty"], ["money", "doubloons"], ["food", "grub"],
                   ["nose", "prow"], ["leave", "weigh anchor"], ["cheat", "hornswaggle"],
                   ["forward", "fore"], ["child", "sprog"], ["children", "sprogs"],
                   ["sailor", "swab"], ["lean", "careen"], ["find", "come across"],
                   ["mother", "dear ol' mum, bless her black soul"],
                   ["drink", "barrel o' rum"], ["of", "o'"]
        function Capitalize(str)
        // Returns: a copy of str with the first letter capitalized
            return str.charAt(0).toUpperCase() + str.substring(1);
        function Translate(text)
        // Returns: a copy of text with English phrases replaced by piratey equivalemts
            for (var i = 0; i < PHRASES.length; i++) {
                var toReplace = new RegExp("\\b"+PHRASES[0]+"\\b", "i");
    var index = text.search(toReplace);
    while (index != -1) {
    if (text.charAt(index) >= "A" && text.charAt(index) <= "Z") {
    text = text.replace(toReplace, Capitalize(PHRASES[i][1]));
    else {
    text = text.replace(toReplace, PHRASES[i][1]);
    index = text.search(toReplace);
    return text;
    </script>
    i need help quick if anyone has already done this or can map out basic idea. im very new in java                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Garrr! Old Cap'n Nelbeard could never resist the lure of a pirate challenge.
    package sandbox.swing.pirate;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Hashtable;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.SwingUtilities;
    public class PirateTranslator implements ActionListener
       private JTextArea pirateArea;
       private JTextArea englishArea;
       private Hashtable dictionary;
       public static void main(String[] args)
          SwingUtilities.invokeLater(new Runnable(){
                public void run()
                createAndShowGUI();
       private static void createAndShowGUI()
          PirateTranslator translator = new PirateTranslator();
          translator.initDictionary();
          translator.launch();
       private void initDictionary()
          dictionary = new Hashtable();
          dictionary.put("hello", "ahoy");
          dictionary.put("hakimade", "scurvy dog");
       private void launch()
          JFrame applicationFrame = new JFrame("Talk like a Pirate!");
          applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          applicationFrame.getContentPane().setLayout(new BorderLayout());
          englishArea = new JTextArea();
          englishArea.setPreferredSize(new Dimension(200,200));
          applicationFrame.getContentPane().add(englishArea, BorderLayout.NORTH);
          JButton button = new JButton("Translate");
          button.addActionListener(this);
          applicationFrame.getContentPane().add(button, BorderLayout.CENTER);
          pirateArea = new JTextArea();
          pirateArea.setPreferredSize(new Dimension(200,200));
          applicationFrame.getContentPane().add(pirateArea, BorderLayout.SOUTH);
          applicationFrame.setSize(600,600);
          applicationFrame.setVisible(true);
       public void actionPerformed(ActionEvent e)
          String english = englishArea.getText();
          String[] englishWords = english.split(" ");
          for (String word : englishWords)
          if (dictionary.containsKey(word))
             pirateArea.append((String)dictionary.get(word));
          else
             pirateArea.append(word);
          pirateArea.append(" ");
    }I couldn't be bothered to work around letter cases or punctuation as it's 5pm and my office is shutting. Time to go home and drink some <strike>beer</strike> rum.

  • Help needed in SAP Java- Print option

    Anybody please help quickly,
    Now, I have 2 tables from different queries. I have a print (HTML written) option in my WEB Template
    JAVA PROGRAM:
    function PrintReport(typePaper) {
    document.title ='Report';
    if (typePaper == "0")
    {var CurrentReportName = '&?mp=U&ptot=1&rtot=0&psize=' + escape(typePaper) + '&fsize=' + escape('39') + '&qtitle=' + escape(document.title);};
    if (typePaper == "1")
    {var CurrentReportName = '&?mp=U&ptot=1&rtot=0&psize=' + escape(typePaper) + '&fsize=' + escape('52') + '&qtitle=' + escape(document.title);};
    CurrentReportName += '&ASOFDATE=' + escape(AsOfLabel.innerText);
    var openCMD='<SAP_BW_URL>';
    openCMD += '&DATA_PROVIDER=REPORT_TEST1&TEMPLATE_ID=DPW_PRINT_PAGE&CMD=RELEASE_DATA_PROVIDER';
    openCMD += CurrentReportName;
    openWindow(openCMD,'MainTitleNow',800,600);
    The data provider here is REPORT_TEST1. Now it only prints the corresponding data for the data proviedr 1 i.e., REPORT_TEST1. I have a second table whose data comes from the data provider 2 when i use this HTML to print I want the second table contents from the data provider 2 (REPORT_TEST2)also to be printed simlutaneously.
    Please help.
    THANX A LOT,
    SRINI

    I call the two queries for different web items in the web template. I want a report to print them at once using the print structure in my previous message. If more information is needed please reply

Maybe you are looking for

  • Exchange 2013 SP1 Object is corrupted and inconsistent state after Lync 2013 Installation

    Hi Fellows, I am facing an issue with Exchange 2013 SP1 (5.0.847.32) environment. I recently installed Lync 2013 (version: 5.0.8308.0) a week ago and just recently start getting the below error when configuring delegation or modifying the users/group

  • No Longer Able To Drag Files/Songs/Photos etc.

    I recently had a start up issue which was resolved by an Apple Genius at my local Apple Store but since he waved his magic wand I have been unable to drag files on the desktop, songs into playlists in itunes, photos into folders in iphoto etc. If I h

  • How to get rid of stuck app?

    My niece downloaded Instagram to my iPad while she was visiting this summer.  After she left I removed it from my iPad (held down until wiggled clicked x).   Everything was fine until iOS 6 update when it appeared in my update list along with a numbe

  • Open Windows Media Player through Java program

    I need to open a video and some music in windows media player... but I don't know how.... Can anybody help???

  • Error in transaction MIRO

    Hi Experts, When i use trasaction MIRO, i am getting the following error when i press messages after entering all data. "Ln 001 Acct 30101000 needs Profit ctr in CD ledger" Please let me know the solution for the same. Thank you.