Results 1 to 20 of 20
  1. #1
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Cool Code for Project

    Hi guys,

    I have this code that I want to put into my project...

    Java Code:
      String[][] Circuit ={{"Circuit One","Circuit Two", "Circuit Three", "Circuit Four", "Circuit Five"}};
            
            if(Circuit == "Circuit One")
            {
                System.out.println("Box Jumps");
                System.out.println("Squat");
                System.out.println("Jerk");
                System.out.println("Deadlift"); 
                System.out.println("Russian Twists");
      
            }
            else if(Circuit == "Circuit Two")
            {
                System.out.println("One Arm Clean");
                System.out.println("Around the Body Pass");
                System.out.println("One Arm Swing");
                System.out.println("Alternating Kettlebell Row");
                System.out.println("Double Bottoms Up Press");
                 
            }
            else if(Circuit == "Circuit Three")
            {
                System.out.println("Windmill");
                System.out.println("One Arm Clean");
                System.out.println("Around the Body Pass");
                System.out.println("Clean and Press");
                System.out.println("One Arm Snatch");
            }
            else if(Circuit == "Circuit Four")
            {
                System.out.println("Two Arm Swings"); 
                System.out.println("Squat with Two Bells");
                System.out.println("Double Kettlebell Press");
                System.out.println("Floor Press");
                System.out.println("Farmers Walk");
      
            }
            else
            {
                System.out.println("Overhead Squat"); 
                System.out.println("Farmers Walk");
                System.out.println("Kettlebell Pistol Squat");
                System.out.println("Superman Squat");
                System.out.println("Military Press");
                     
                 
            }
        }
    The Project code is this:

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * KettleCircuit.java
     *
     * Created on 12-Nov-2014, 09:03:53
     */
    
    package javaproject;
    
    /**
     *
     * @author User
     */
    public class KettleCircuit extends javax.swing.JFrame {
    
        /** Creates new form KettleCircuit */
        public KettleCircuit() {
            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.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jColorChooser1 = new javax.swing.JColorChooser();
            jColorChooser2 = new javax.swing.JColorChooser();
            jFrame1 = new javax.swing.JFrame();
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
            jComboBox1 = new javax.swing.JComboBox();
            jComboBox3 = new javax.swing.JComboBox();
            jButton1 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
    
            javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
            jFrame1.getContentPane().setLayout(jFrame1Layout);
            jFrame1Layout.setHorizontalGroup(
                jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 400, Short.MAX_VALUE)
            );
            jFrame1Layout.setVerticalGroup(
                jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 300, Short.MAX_VALUE)
            );
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 100, Short.MAX_VALUE)
            );
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Circuits", "Circuit One (Beginner)", "Circuit Two (Novice)", "Circuit Three (Amateur)", "Circuit Four (Intermediate", "Circuit Five (Expert)" }));
            jComboBox1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jComboBox1ActionPerformed(evt);
                }
            });
    
            jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Minutes", "5 Minutes", "8 Minutes ", "10 Minutes ", "12 Minutes ", "15 Minutes", "20 Minutes " }));
    
            jButton1.setText("GO");
    
            jLabel1.setText("Twitter");
    
            jLabel2.setText("Facebook");
    
            jTextField1.setText("Test Yourself Today");
            jTextField1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField1ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton1)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(26, 26, 26)
                                .addComponent(jLabel2))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox3, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.Alignment.TRAILING, 0, 335, Short.MAX_VALUE)
                                    .addComponent(jTextField1)))))
                    .addContainerGap(37, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2))
                    .addGap(31, 31, 31)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(31, 31, 31)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(35, 35, 35)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(32, 32, 32)
                    .addComponent(jButton1)
                    .addContainerGap(63, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
            
            
        }                                          
    
        private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
          
    
        }                                           
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new KettleCircuit().setVisible(true);
                    
                   
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JColorChooser jColorChooser1;
        private javax.swing.JColorChooser jColorChooser2;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JComboBox jComboBox3;
        private javax.swing.JFrame jFrame1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                   
    
    }
    Where do i put the first code segment in the second code segment?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Code for Project

    Somewhere else.
    In its own class, implementing some interface that allows you to access the circuits by name.
    This will allow you to entirely replace the current hard coded implementation with another one that (say) reads from a file.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Code for Project

    So, two classes in the one package file that call each other or one from the other.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Code for Project

    b.t.w. a two dimensional array of Strings can never be equal to a String.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Code for Project

    Quote Originally Posted by aboyse1990 View Post
    So, two classes in the one package file that call each other or one from the other.
    The one I am suggesting will be your data source, or Data Access Object (DAO) if you prefer.
    Your controlling code will access that to get the circuit data (including the values to populate your drop downs, IMO).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Code for Project

    SO two classes that reference one another.

    like circuit.java and kettlecircuit.java

    with kettlecircuit.circuit references or pointing to each other.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Code for Project

    In the first code in post#1 change the 2Dim array to have the circuit name in the first column and the details in rest of the columns.
    Java Code:
      String[][] circuits = {{"cn1", "d1", "d2", "d3"},{"cn2",  "d1", "d2"}, ...};
    There would be not need for the list of if tests. Given the row, the details would be from the second column to the end of the row.
    Last edited by Norm; 11-14-2014 at 04:49 PM.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Code for Project

    Quote Originally Posted by aboyse1990 View Post
    SO two classes that reference one another.

    like circuit.java and kettlecircuit.java

    with kettlecircuit.circuit references or pointing to each other.
    Well, the DAO (Circuit class) won't need to know about the class calling it.
    Why would it?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Code for Project

    Also, the following logical if
    Java Code:
    if(Circuit == "Circuit One")
    is wrong for another reason besides not using arrays correctly. So when you fix it
    use equals and not == to compare strings (assuming that is what you wanted to do).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Code for Project

    String[][] Circuit ={{"Circuit One","Circuit Two", "Circuit Three", "Circuit Four", "Circuit Five"}};

    if(Circuit.equals("Circuit One"))
    {
    System.out.println("Box Jumps");
    System.out.println("Squat");
    System.out.println("Jerk");
    System.out.println("Deadlift");
    System.out.println("Russian Twists");

    }
    else if(Circuit.equals("Circuit Two"))
    {
    System.out.println("One Arm Clean");
    System.out.println("Around the Body Pass");
    System.out.println("One Arm Swing");
    System.out.println("Alternating Kettlebell Row");
    System.out.println("Double Bottoms Up Press");

    }
    else if(Circuit.equals("Circuit Three"))
    {
    System.out.println("Windmill");
    System.out.println("One Arm Clean");
    System.out.println("Around the Body Pass");
    System.out.println("Clean and Press");
    System.out.println("One Arm Snatch");
    }
    else if(Circuit.equals("Circuit Four"))
    {
    System.out.println("Two Arm Swings");
    System.out.println("Squat with Two Bells");
    System.out.println("Double Kettlebell Press");
    System.out.println("Floor Press");
    System.out.println("Farmers Walk");

    }
    else
    {
    System.out.println("Overhead Squat");
    System.out.println("Farmers Walk");
    System.out.println("Kettlebell Pistol Squat");
    System.out.println("Superman Squat");
    System.out.println("Military Press");


    }
    }

    Something like this, but with a little tweek here and there. What exactly is wrong with this though...

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Code for Project

    Please edit your post and wrap the code in code tags.
    The posted code doesn't need a 2 dim array. All the Strings are in the first row.

    I suggested a way to use a 2 dim array in post#7 that would eliminate the requirements for all the if/else if statements. A row for each circuit with the name in the first column and the details in the rest of the columns.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Code for Project

    Java Code:
    String[][] Circuit ={{"Circuit One","Circuit Two", "Circuit Three", "Circuit Four", "Circuit Five"}};
    
     if(Circuit.equals("Circuit One"))
     {
     System.out.println("Box Jumps");
     System.out.println("Squat");
     System.out.println("Jerk");
     System.out.println("Deadlift"); 
     System.out.println("Russian Twists");
    
     }
     else if(Circuit.equals("Circuit Two"))
     {
     System.out.println("One Arm Clean");
     System.out.println("Around the Body Pass");
     System.out.println("One Arm Swing");
     System.out.println("Alternating Kettlebell Row");
     System.out.println("Double Bottoms Up Press");
    
     }
     else if(Circuit.equals("Circuit Three"))
     {
     System.out.println("Windmill");
     System.out.println("One Arm Clean");
     System.out.println("Around the Body Pass");
     System.out.println("Clean and Press");
     System.out.println("One Arm Snatch");
     }
     else if(Circuit.equals("Circuit Four"))
     {
     System.out.println("Two Arm Swings"); 
     System.out.println("Squat with Two Bells");
     System.out.println("Double Kettlebell Press");
     System.out.println("Floor Press");
     System.out.println("Farmers Walk");
    
     }
     else
     {
     System.out.println("Overhead Squat"); 
     System.out.println("Farmers Walk");
     System.out.println("Kettlebell Pistol Squat");
     System.out.println("Superman Squat");
     System.out.println("Military Press");
    
    
     }
     }
    But, it's a drop-down menu, with no columns or rows...

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Code for Project

    What goes onto each item in the drop-down menu?
    I'm suggesting that col 1 in the array's row goes to first item in the menu, col 2 goes to the second item, etc
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Code for Project

    So like, CIrcuit One would be the column and each exercise would be the row...

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Code for Project

    Quote Originally Posted by aboyse1990 View Post
    So like, CIrcuit One would be the column and each exercise would be the row...
    Arrays are so 1960s; think classes and objects: a Circuit object has exercises ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Code for Project

    See post#7. The circuit is in the first col, the exercises are in the rest of the columns.

    As Jos said: Classes are more OOP
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Code for Project

    Java Code:
    package JavaProject;
    
    public class Exercises{
        
        public static void main(String[] args){
            
            String[][] Circuit = {{"Circuit One", "Jerk", "Russian Twists", "Squats",
                "Squat Jumps", "Deadlift"},
                
                {"Circuit Two", "Pull Ups", "Around the Body Pass", "Two Arm Swings",
                    "One Arm Swings", "Snatch"},
                
                {"Circuit Three", "Long Cycle", "One Arm Clean", "Alternating Kettlebell Row",
                    "Two Arm Swings", "Double Jerks"},
                
                {"Circuit Four", "Bottoms Up Clean", "Bottoms Up Clean and Press", 
                    "One Arm Row", "Squat Jumps", "Turkish Get-Ups"},
                
                {"Circuit Five", "Floor Press", "One Arm Push Press", "Military Press",
                    "Double Kettlebell Press", "Superman Squats"}}
         }
    }
    It says, it is expecting a ;, but exactly where, I don't know.

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Code for Project

    Strange. Normally the compiler puts a ^ beneath the line at the place of the error.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Code for Project

    I'm using Netbeans does it make a difference...

  20. #20
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Code for Project

    does it make a difference
    Yes. It doesn't show the errors the same way that the javac compiler does.
    You should be able to have NB show you exactly where the error is and possibly fix it.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. need help with java project code
    By reignman in forum New To Java
    Replies: 2
    Last Post: 07-25-2014, 10:09 AM
  2. Replies: 1
    Last Post: 12-17-2013, 11:10 AM
  3. Assistance with my coding project? (Morse Code)
    By playtodie in forum New To Java
    Replies: 5
    Last Post: 04-04-2013, 06:05 AM
  4. Replies: 5
    Last Post: 08-07-2012, 05:30 PM
  5. Project Code Name: Sentry
    By mox27 in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-18-2008, 02:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •