Help with a simple array.

Hey guys. I'm a bit of a noob here, and I'm sure you can fix up my problem real quick. Ok, I'm trying to make an array where, after you enter some integers, will automatically rearrange those integers from smallest to largest for you and print them back out to the screen. Here's my code:
import cs1.Keyboard;
public class Array2
     public static void main (String[] args)
          int num;
          int count=0, step=1;
          System.out.println("Enter the length of the array");
          int arraylength = Keyboard.readInt();
          int[]Array = new int[arraylength];
          System.out.println("Enter the first value in the array:");
          Array[0] = Keyboard.readInt();
          while(count<arraylength-1)
               System.out.println("Enter the next value in the array:");
               num = Keyboard.readInt();
               if(num>Array[count])
                    Array[count+1]=num;
                    count++;
               else
                    for (int count2=count; 0 <= count2; count2--)
                         Array[count2]=Array[count2+1];
                         num = Array[count2];
               count++;
          for(int outputcount=0; outputcount<arraylength; outputcount++)
               System.out.print(Array[outputcount] + " ");
}

An assignment is yours to learn from, not ours to write for you. Try doing some debugging of the program - use System.out.println() statements to print values of various program variables and to see what the program is doing. If you get to a point that you can't solve a specific problem, then post a specific question and example of the problem. (So far, all you've done is said "the program doesn't work")

Similar Messages

  • Need help with a simple process with FTP Adapter and File Adapter

    I am trying out a simple BPEL process that gets a file in opaque mode from a FTP server using a FTP adapter and writes it to the local file system using a File Adapter. However, the file written is always empty (zero bytes). I then tried out the FTPDebatching sample using the same FTP server JNDI name and this work fine surprisingly. I also verified by looking at the FTP server logs that my process actually does hit the FTP server and seems to list the files based on the filtering condition - but it does not issue any GET or RETR commands to actually get the files. I am suspecting that the problem could be in the Receive, Assign or Invoke activities, but I am not able identify what it is.
    I can provide additional info such as the contents of my bpel and wsdl files if needed.
    Would appreciate if someone can help me with this at the earliest.
    Thanks
    Jay

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

  • Need help with a simple basketball game.

    Hi im new here and I need help with making this simple basketball game.
    Im trying to recreate this game from this video. Im not sure if he is using as2 or as3
    Or if anyone could help me make a game like this or direct me to a link on how to do it It would be greatly appreciated.

    If you couldn't tell whether it is AS2 or AS3, it is doubtful you can turn it from AS2 into AS3, at least not until you learn both languages.  There is no tool made that does it for you.

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

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

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

  • Help with a simple program.

    I need some help writing a simple program. Can anybody help??
    thanks to all.
    2. HTML Java Source Code Reserved Word Highlighter
    Write a program that inputs a Java source code file and outputs a copy of that file with Java keywords surrounded with HTML tags for bold type. For example this input:
    public class JavaSource
    public static void main ( String[] args )
    if ( args.length == 3 )
    new BigObject();
    else
    System.out.println("Too few arguments.");
    will be transformed into:
    <B>public</B> <B>class</B> JavaSource
    <B>public</B> <B>static</B> <B>void</B> main ( String[] args )
    <B>if</B> ( args.length == 3 )
    <B>new</B> BigObject();
    <B>else</B>
    System.out.println("Too few arguments.");
    In a browser the code will look like this:
    public class JavaSource
    public static void main ( String[] args )
    if ( args.length == 3 )
    new BigObject();
    else
    System.out.println("Too few arguments.");

    Here is something that may get you started...
    import java.io.*; 
    import java.util.*; 
    public class HtmlJava{
         public static void main(String arg[]){
              if(arg.length!=1){
                   System.out.println("Usage java HtmlJava sourceFile");       
              else
                   new HtmlJava(arg[0]);
         HtmlJava(String source){
              try{
                   BufferedReader sourceReader=new BufferedReader(new InputStreamReader(new FileInputStream(source)));
                   BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(source+"Html.txt")));  
                   Vector keywords=new Vector();
                   addKeywords(keywords);
                   String line;
                   StringTokenizer tokenizer=null;
                   String word;
                   while((line=sourceReader.readLine () )!=null){
                        tokenizer=new StringTokenizer(line);
                        while(tokenizer.hasMoreTokens()){
                             word=tokenizer.nextToken();
                             if(keywords.contains(word)){
                                  writer.write(""+word+" ");
                             else{
                                  writer.write(word+" ");
                        writer.write("\r\n");
                   writer.close();
                   sourceReader.close(); 
                   System.out.println("Output File written to "+source+"Html.txt"); 
              catch(Exception ex){
                   ex.printStackTrace();      
         private void addKeywords(Vector keywords){
              keywords.addElement ( "abstract");
              keywords.addElement( "boolean");
              keywords.addElement( "break");
              keywords.addElement( "byte");
              keywords.addElement( "byvalue");
              keywords.addElement( "case");
              keywords.addElement( "cast");
              keywords.addElement( "catch");
              keywords.addElement( "char");
              keywords.addElement( "class");
              keywords.addElement( "const");
              keywords.addElement( "continue");
              keywords.addElement( "default");
              keywords.addElement( "do");
              keywords.addElement( "double");
              keywords.addElement( "else");
              keywords.addElement( "extends");
              keywords.addElement( "false");
              keywords.addElement( "final");
              keywords.addElement( "finally");
              keywords.addElement( "float");
              keywords.addElement( "for");
              keywords.addElement( "future");
              keywords.addElement( "generic");
              keywords.addElement( "goto");
              keywords.addElement( "if");
              keywords.addElement( "implements");
              keywords.addElement( "import");
              keywords.addElement( "inner");
              keywords.addElement( "instanceof");
              keywords.addElement( "int");
              keywords.addElement( "interface");
              keywords.addElement( "long");
              keywords.addElement( "native");
              keywords.addElement( "new");
              keywords.addElement( "null");
              keywords.addElement( "operator");
              keywords.addElement( "outer");
              keywords.addElement( "package");
              keywords.addElement( "private");
              keywords.addElement( "protected");
              keywords.addElement( "public");
              keywords.addElement( "rest");
              keywords.addElement( "return");
              keywords.addElement( "short");
              keywords.addElement( "static");
              keywords.addElement( "super");
              keywords.addElement( "switch");
              keywords.addElement( "synchronized");
              keywords.addElement( "this");
              keywords.addElement( "throw");
              keywords.addElement( "throws");
              keywords.addElement( "transient");
              keywords.addElement( "true");
              keywords.addElement( "try");
              keywords.addElement( "var");
              keywords.addElement( "void");
              keywords.addElement( "volatile");
              keywords.addElement( "while");
    }Hope it helped

  • Help with a simple 1811 configuration

    I have a very basic level of understanding with Cisco products and I need help with what should be simple and even doable by me.
    I have a Cisco 1811 integrated router and am simply trying to use it on my home network.  I can configure the router with an enable secret password, password encryption, VTY, aux, and cons logins with no issues.  The router has 2 Ethernet interfaces, 0 and 1 and 8 switch ports.
    The idea is to bring Comcast ISP service into one of the Ethernet ports and then have three machines on the switch ports able to access the Internet.  Also I have an off-the shelf wireless router that I thought I would just plug that into an available switch port and allow a wireless AP as well. 
    This is so simply, that I can't believe I can't figure it out, but I can't.
    I set int F1 to DHCP, performed a 'no shut', and connected the ISP's router and have an up and up indication.  I have setup a static network with my three machines on the switch ports and enabled all applicable ports and have up and up indications - however, no traffic flow, even amongst my static Layer 2 switched LAN - not even a 'ping'.  By my understanding of Layer 2, this should work right now, whether the ISP service is working or not - WHAT AM I DOING WRONG?
    The addressing scheme I have ended up on is 172.16.1.0/28
    Obviously without the first hurdle cleared, of why the switched LAN doesn’t work, I haven't got any deeper.  Do I need to configure NAT?  I don't think I would need to in the scenario right?
    All of my experience, and none at the CCNA level, has been with larger Cisco equipment.  One thing I noticed on the 1811 was that when trying to create a new VLAN, it appears to work yet does not do anything and the 'sh vlans' output returns nothing, not even the VLAN1 I can see with 'sh ip int brief". 
    Anyway, if anyone has time to help a newbie out I would appreciate it; I’m lost.
    Thanks,
    Josh

    Thanks for the help Andrew!  You know, I think if this was two separate devices (switch and router) I think I would be up and running, but this integrated stuff is throwing me off, not to mention that the IOS is a much older version (I guess) than what I'm used to. 
    They were throwing this 1811 in the trash can at work, so I just emptied the trash can.  I have no documentation at all but I have since found the 1800 series documentation on Cisco.com and have tried to implement the basic configurations cited; with what seems like success, but still no joy.  I did have to recover the password and did so with 0x2142, I bypassed the setup and compared the default configuration with what is listed in the documentation and they DO NOT match; I also tried to go through setup mode with the same indications.  Additionally I've also learned that the 1800 series is pre-configured on certain options (DHCP, VLAN), which is new to me - I thought Cisco routers were not configured by default - isn't that kind of the point?  (By the way, the below port status may not be correct since I now have all the ports unplugged)
    Anyway, here is the 'show run' command, the 'sh ip int brief' command, followed by the 'sh version' command:
    Show Run
    Casino#sh run                                                                 
    Building configuration...                                                     
    Current configuration : 2006 bytes                                            
    version 12.4                                                                  
    service timestamps debug datetime msec                                        
    service timestamps log datetime msec                                          
    service password-encryption                                                   
    hostname Casino                                                               
    boot-start-marker                                                             
    boot-end-marker                                                               
    enable secret 5 $1$meWw$nsMTp6US7axi/uE0MWULK.                                
    enable password 7 06535E741C1B584C55                                          
    no aaa new-model                                                              
    ip cef                                                                        
    no ip dhcp use vrf connected                                                  
    ip dhcp excluded-address 172.16.1.1                                           
    ip dhcp pool Casino                                                           
       import all                                                                 
       network 172.16.1.0 255.255.255.240                                         
       default-router 67.165.208.1                                                
       dns-server 68.87.89.150                                                    
       domain-name hsd1.co.comcast.net                                            
    no ip domain lookup                                                           
    ip domain name GinRummy.localhost                                             
    ip name-server 68.87.85.102                                                   
    ip name-server 68.87.69.150                                                   
    ip auth-proxy max-nodata-conns 3                                              
    ip admission max-nodata-conns 3                                               
    multilink bundle-name authenticated                                           
    archive                                                                       
    log config                                                                   
      hidekeys                                                                    
    interface Loopback0                                                           
    ip address 172.16.1.1 255.255.255.240                                        
    interface FastEthernet0                                                       
    no ip address                                                                
    shutdown                                                                     
    duplex auto                                                                  
    speed auto                                                                   
    interface FastEthernet1                                                       
    ip address dhcp                                                              
    ip nat outside                                                               
    ip virtual-reassembly                                                        
    duplex auto                                                                  
    speed auto                                                                   
    pppoe enable                                                                 
    pppoe-client dial-pool-number 1                                              
    interface BRI0                                                                
    no ip address                                                                
    encapsulation hdlc                                                           
    shutdown                                                                     
    interface FastEthernet2                                                       
    interface FastEthernet3                                                       
    interface FastEthernet4                                                       
    interface FastEthernet5                                                       
    interface FastEthernet6                                                       
    interface FastEthernet7                                                       
    interface FastEthernet8                                                       
    interface FastEthernet9                                                       
    interface Vlan1                                                               
    no ip address                                                                
    ip nat inside                                                                
    ip virtual-reassembly                                                        
    interface Dialer0                                                             
    ip address negotiated                                                        
    ip mtu 1492                                                                  
    encapsulation ppp                                                            
    dialer pool 1                                                                
    ppp authentication chap                                                      
    ip forward-protocol nd                                                        
    no ip http server                                                             
    no ip http secure-server                                                      
    ip nat pool Casino 172.16.1.2 172.16.1.14 netmask 255.255.255.240             
    ip nat inside source list 1 interface Dialer0 overload                        
    access-list 1 permit 172.16.1.0 0.0.0.15                                      
    dialer-list 1 protocol ip permit                                              
    control-plane                                                                 
    line con 0                                                                    
    password 7 080E5916584B4442435E5C                                            
    login                                                                        
    line aux 0                                                                    
    password 7 013C135C0A59475A70191E                                            
    login                                                                        
    line vty 0 4                                                                  
    password 7 09635B51485756475A5954                                            
    login                                                                        
    end                                                                           
    Show IP Interface Brief
    Casino#sh ip int brief                                                        
    Interface                  IP-Address      OK? Method Status                Prl
    FastEthernet0              unassigned      YES NVRAM  administratively down do
    FastEthernet1              unassigned      YES DHCP   up                    do
    BRI0                       unassigned      YES NVRAM  administratively down do
    BRI0:1                     unassigned      YES unset  administratively down do
    BRI0:2                     unassigned      YES unset  administratively down do
    FastEthernet2              unassigned      YES unset  up                    do
    FastEthernet3              unassigned      YES unset  up                    do
    FastEthernet4              unassigned      YES unset  up                    do
    FastEthernet5              unassigned      YES unset  up                    do
    FastEthernet6              unassigned      YES unset  up                    do
    FastEthernet7              unassigned      YES unset  up                    do
    FastEthernet8              unassigned      YES unset  up                    do
    FastEthernet9              unassigned      YES unset  up                    up
    Vlan1                      unassigned      YES NVRAM  up                    up
    Loopback0                  172.16.1.1      YES manual up                    up
    Dialer0                    unassigned      YES manual up                    up
    NVI0  
    'show version'
    Casino#sh ver                                                                 
    Cisco IOS Software, C181X Software (C181X-ADVIPSERVICESK9-M), Version 12.4(15))
    Technical Support: http://www.cisco.com/techsupport                           
    Copyright (c) 1986-2008 by Cisco Systems, Inc.                                
    Compiled Thu 24-Jan-08 13:05 by prod_rel_team                                 
    ROM: System Bootstrap, Version 12.3(8r)YH12, RELEASE SOFTWARE (fc1)           
    Casino uptime is 52 minutes                                                   
    System returned to ROM by reload at 17:09:25 UTC Fri Jul 1 2011               
    System image file is "flash:c181x-advipservicesk9-mz.124-15.T3.bin"           
    This product contains cryptographic features and is subject to United         
    States and local country laws governing import, export, transfer and          
    use. Delivery of Cisco cryptographic products does not imply                  
    third-party authority to import, export, distribute or use encryption.        
    Importers, exporters, distributors and users are responsible for              
    compliance with U.S. and local country laws. By using this product you        
    agree to comply with applicable laws and regulations. If you are unable       
    to comply with U.S. and local laws, return this product immediately.          
    A summary of U.S. laws governing Cisco cryptographic products may be found at:
    http://www.cisco.com/wwl/export/crypto/tool/stqrg.html                        
    If you require further assistance please contact us by sending email to       
    [email protected].                                                             
    Cisco 1812 (MPC8500) processor (revision 0x400) with 118784K/12288K bytes of m.
    Processor board ID FHK120622J3, with hardware revision 0000                   
    10 FastEthernet interfaces                                                    
    1 ISDN Basic Rate interface                                                   
    31488K bytes of ATA CompactFlash (Read/Write)                                 
    Configuration register is 0x2102  
    Thanks again for your help,
    Josh

  • Help with some simple coding

    Hello
    I am very new to Java and am currently studying a course in the language.
    I am working through a tutorial at the moment and a question has been asked and I am struggling a bit
    I have been given the code to a program that creates a window with a ball bouncing around inside the window.
    There are 2 classes (code below) - Call class - this contains all the code need to create the ball and BallWorld Class (the main Class) this create the window and moves the ball, it also detects if the ball hits the edge of the window, whne this happens it redirects the ball. I understand how all this code works
    I have been asked the following:-
    Rather than testing whether or not the ball has hit the wall in the nmain program, we could use inhertitance to provide a specialized forom of Ball. Create a class BoundedBall that inherits from the class Ball. The constructor for this class should provide the height and width of the window, which should be maintained as data fields in the class, rewrite the move method so that the ball moves outside the bound, it automatically reflects its direction. Finally rewrite the BallWorld class to use an instance of BoundedBall rather than ordianary Ball, and elimiante the bounds test in the main program.
    I am having trouble with this and I can not get my code to work, I think I may be going in completly the wrong direction with the code can sombody please provide me with a simple working code for both the BoundedBall and ammended BallWorld class, as this will help me understand whare I am going wrong
    Ball class
    //a generic round colored object that moves
    import java.awt.*;
    public class Ball {
    public Ball (Point lc, int r) {     //constructor for new ball
         //ball centre at point loc, radius rad
         loc = lc;
         rad = r;
    protected Point loc; //position in window
    protected int rad; //radius of ball
    protected double changeInX = 0.0; //horizontal change in ball position in one cycle
    protected double changeInY = 0.0; //vertical change in ball position in one cycle
    protected Color color = Color.blue; //colour of ball
    //methods that set attributes of ball
    public void setColor(Color newColor) {color = newColor;}
    public void setMotion(double dx,double dy)
    {changeInX = dx; changeInY = dy;}
    //methods that access attributes of ball
    public int radius() {return rad;}
    public Point location() {return loc;}
    //methods to reverse motion of the ball
    public void reflectVert(){ changeInY = -changeInY; }
    public void reflectHorz(){ changeInX = -changeInX; }
    //methods to move the ball
    public void moveTo(int x, int y) {loc.move(x,y);}
    public void move(){loc.translate((int)changeInX, (int)changeInY);}
    //method to display ball
    public void paint (Graphics g) {
    g.setColor(color);
    g.fillOval(loc.x-rad, loc.y-rad, 2*rad, 2*rad);
    BallWorld class
    //A bouncing ball animation
    import java.awt.*;          //import the awt package
    import javax.swing.JFrame;     //import the JFrame class from the swing package
    public class BallWorld extends JFrame{
         public static void main (String [] args){
              BallWorld world = new BallWorld(Color.red);
              world.show();
    for(int i = 0; i < 1000; i++) world.run();
    System.exit(0);
         public static final int FrameWidth = 600;
         public static final int FrameHeight = 400;
    private Ball aBall = new Ball(new Point (50,50),20);
         private BallWorld(Color ballColor) {     //constructor for new window
              //resize frame, initialize title
         setSize(FrameWidth, FrameHeight);
         setTitle("Ball World");
    //set colour and motion of ball
         aBall.setColor(ballColor);
         aBall.setMotion(3.0, 6.0);
         public void paint (Graphics g) {
    //first draw the ball
    super.paint(g);
         aBall.paint(g);
    public void run(){
              //move ball slightly
         aBall.move();
    Point pos =aBall.location();
    if ((pos.x < aBall.radius()) ||
    (pos.x > FrameWidth - aBall.radius()))
    aBall.reflectHorz();
    if ((pos.y < aBall.radius()) ||
    (pos.y > FrameHeight - aBall.radius()))
    aBall.reflectVert();
    repaint();
    try{
    Thread.sleep(50);
    } catch(InterruptedException e) {System.exit(0);}

    Here - you can study this :0))import java.awt.*;
    import javax.swing.*;
    public class MovingBall extends JFrame {
       mapPanel map   = new mapPanel();
       public MovingBall() {
          setBounds(10,10,400,300);
          setContentPane(map);
       public class mapPanel extends JPanel {
          Ball ball  = new Ball(this);
          public void paintComponent(Graphics g) {
            super.paintComponent(g);
            ball.paint(g);
    public class Ball extends Thread {
       mapPanel map;
       int x  = 200, y = 20, xi = 1, yi = 1;
    public Ball(mapPanel m) {
       map = m;
       start();
    public synchronized void run(){
       while (true) {
          try{
            sleep(10);
          catch(InterruptedException i){
            System.out.print("Interrupted: ");
          move();
    public void move() {
        map.repaint(x-1,y-1,22,22);
           if (x > map.getWidth()-20 || x < 0)  xi = xi*-1;
           if (y > map.getHeight()-20 || y < 0) yi = yi*-1;
           x = x + xi;
           y = y + yi;
           map.repaint(x-1,y-1,22,22);
        public void paint(Graphics g) {
           Graphics2D g2 = (Graphics2D)g;
           g2.setColor(Color.red);
           g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                               RenderingHints.VALUE_ANTIALIAS_ON);
           g2.fillOval(x,y,20,20);
           g2.dispose();
    public static void main(String[] args) {
       new MovingBall().show();
    }

  • Help with a Vector Array - pppppplllllllleeeeaaasse!!!!!!!

    Hi I'm having a mare with a Vector Array that I want to contain String variables. I know you get a warning with the traditional implementation of a vector, and I have over come that using:
    private Vector <String> MyVector = new Vector<String>();
    But I also need to create a Vector Array and I am getting some very strange results - for a start in JPadPro it only comiles every second attempt, with every other failing due to the implementation of the Vector array.
    Below is a snippet of the code that I have sort of got to compile but with a compiler warning:
    private Vector<String>[] MyVector; //this is line 75
    int Array;
    public myClass()
    Array = 5;
    MyVector = new Vector[ Array ];
    for( int i = 0; i < Array; i++ )
    MyVector[ i ] = new Vector<String>();     
    The first time I complie I get:
    CreateMessage.java Line 75: Syntax Error
    The Second time I compile I get:
    CreateMessage.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Finished
    I hate complier errors - I have gotten quite a few but have managed to remove them all but this one by searching the forum. Any help on the correct implementation of my Vector Array would be great,
    Thanks in advance,
    Kris

    Mr_Bump180 wrote:
    Well you lot are a real cheery bunchDo you come here for warm and fuzzies or for Java help?
    - please accept my most humble apologies for daring to try and keep my thread light hearted. Use your brain. Nobody objects to keeping your thread lighthearted. It's that garbage like that is annoying and makes your post harder to read. If you want to get your question answered clear communication is of the essence. That should be common sense.
    I asked the question simply as I wanted to improve my code - which I write for no gain, but just in an attempt to automate processes that I cannot find software to do for me. How is that relevant?
    I find the solutions on this website invaluable, but what shines through most clearly - is the incredibly poor attitude of some of you - who are obviously java professionals - when a novice risks posting a question on what is obviously YOUR forum. Is that how you get your kicks? By jumping all over people that dare to ask a question in order to try and better themselves?Right. People jumped on your for asking a question. Get real.
    I will as I always do, read the pages you have linked to, and I will also try and implement your solution into my code - I just find it a shame that in order to obtain any help people who are posting in the "New to Java Programming" by-the-way, run the gauntlet of your abuse if the question, grammar, syntax or perhaps even title don't measure up to your high standards.Dude, if you're asking somebody to volunteer his time to help you, isn't it obvious that it's in your best interest to make it as easy as possible for him to do so?
    I will now turn the watch off this thread, and will not reply againAs if anybody cares.
    - but for those of you reading - I wonder just how many can't bare me to have the last word and have to post a replySo, anytime somebody replies to something it must be because they have to have the last word?
    with the clever little quote inserts, a greater than thou attitude, and some more brilliant humour (I was in stiches reading your rebuttals ) because I don't fully understand a concept and as such asked for help.Get over the "they teased me because I don't know Java" bullshit. It's simply not the case, and you bloody well know it.

  • Help with DIgital Output Array with 6062E DAQ CARD...

    Good morning, folks... I need some help with digital output of the 6062E PCMCIA card... I can output 1 line without problems... I need to control a 4066 with my digital outputs... I am doing this without greater problems... but there's something... I need that when one of my outputs is high, the others become low, unchangeably... so I tried to use an array to control my output and I couldn't do that... some errors showed up... can you help me please? Maybe there's any errors at my software, then I thank you if you help me... the vi is anexed...
    Best Regards...
    Attachments:
    Untitled 3.vi ‏20 KB

    See below for one of many methods. Change the "lines" string for your setup.
    Also, please explore the Examples that ship with LabVIEW, and read your card's manual.
    Richard

  • Help with comparing string array with parameters

    I've posted my code in full so hopefully everyone can see exactly what I have been doing.
    Note - my code uses the observer/observable model. The method I am having the problem with the if statement is in the class HSBC.
    Basically when the pin count reaches 4 (in the atm class) it sends the userid & pincode) over to the checkPinAndUserId(String pinCode, String userCode) method. Here the if statement should check the userid to see if the string parameter matches a string in the array. If it does it should check in the same position in the pin array to check the pin no is correct and then return true.
    * @(#)BankAssignment.java 1.0 03/04/06
    * This apllication l
    package myprojects.bankassignment;
    import java.awt.*; // import the component library
    import java.awt.event.*; // import the evnet library
    import javax.swing.*;
    import java.util.*;
    class Correct1v16 extends Frame // make a new application
         public Correct1v16() // this is the constructor method
              HSBC HSBCobj = new HSBC();
         public static void main(String args[]) // this invokes the constructor of the class and creates a runable object 'mainframe'
              Correct1v16 mainFrame = new Correct1v16(); // the constructor call of the class which creates an object of that class
    class HSBC implements Observer,  ActionListener
              Frame f5;
              JLabel refill, launch;
              TextField tRefill, tLaunch;
              JButton refillbut, launchbut;
              int count;
              String [] userId=new String [10];
              String [] pin=new String [10];
              public boolean authenticate = false;
              int i;
                   public HSBC()
                   drawFrame();
                   Atm Atmobj = new Atm(this);
                   System.out.println("Starting HSBC constructor");     
              public void drawFrame()
                   System.out.println("Start HSBC drawframe method...");
                   f5=new Frame("HSBC");
                   f5.setLayout(new FlowLayout());
                   f5.setSize(200, 200);
                   f5.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)     
                             f5.dispose();
                             System.exit(0);     
                   refill=new JLabel("Refill ATM");
                   launch=new JLabel("Launch new ATM");
                   tRefill=new TextField(20);
                   tLaunch=new TextField(10);
                   refillbut=new JButton("Refill ATM");
                   refillbut.addActionListener(this);
                   launchbut=new JButton("Launch new ATM");
                   launchbut.addActionListener(this);
                   f5.add(refill);
                   f5.add(tRefill);
                   f5.add(refillbut);
                   f5.add(launch);
                   f5.add(tLaunch);
                   f5.add(launchbut);
                   f5.setVisible(true);
    //*********** POPULATE THE ARRAYS     */
                   pin[0]="1234";
                   pin[1]="2345";
                   pin[2]="3456";
                   pin[3]="4567";
                   pin[4]="5678";
                   pin[5]="6789";
                   pin[6]="7890";
                   pin[7]="8901";
                   pin[8]="9012";
                   pin[9]="0123";
                   userId[0]="0";
                   userId[1]="1";
                   userId[2]="2";
                   userId[3]="3";
                   userId[4]="4";
                   userId[5]="5";
                   userId[6]="6";
                   userId[7]="7";
                   userId[8]="8";
                   userId[9]="9";
              }// end drawframe method
              //     public Atm atmLink = (Atm)o;
                   public void update(Observable gm1, Object o)
                        Atm atmLink = (Atm)o;
                        tRefill.setText("Refill ATM ?");
                        atmLink.refill();
                   }//end update method
                   public void actionPerformed(ActionEvent ae)
                        if(ae.getSource() == refillbut)
    //                         Atm Atmobj.refill();
                        //     tRefill.setText("text area");     
                        //     atmLink.refill();
    //                         Atmobj.refill();
    //                         setChanged();
    //                         notifyObservers();
                        if(ae.getSource() == launchbut)
                             tLaunch.setText("new ATM opened");
                             Atm Atmobj1 = new Atm(this);
    //******** THIS METHOD RECEIVES THE PARAMETERS FROM THE ATM METHOD (LINE 580) (PINCODE AND USERCODE) BUT
    //******** IT ONLY THE ARRAY CALLED USERID (WHICH HOLDS THE USER CODE MATCHES ONE OF THE USERID'S)
    //******** I DO WANT IT TO DO THIS BUT I ALSO WANT IT TO MOVE ON AND CHECK THE PINCODE WITH THE PIN ARRAY)
    //******** IF THEY ARE BOTH TRUE I WANT IT TO RETURN TRUE - ELSE FALSE.          */               
                   public boolean checkPinAndUserId(String userCode, String pinCode)
                        boolean found = false;
                        System.out.println("in checkpin method");
                        System.out.println("userCode = "+ userCode);
                        System.out.println("pinCode = " + pinCode);
                        for (int i = 0; i < userId.length; i++)
                        System.out.println("in the userid array" + userId);
                             if (userCode.equals(userId[i]))
                                  System.out.println("checking user code array");
                                  if (pinCode.equals(pin[i]))
                                       System.out.println("checking the pin array" + pinCode);
                                       System.out.println("pin[i] = "+pin[i]);
                                  found = true;
                        return found;
         }// end HSBC class
    class Atm extends Observable implements ActionListener
              Frame f1;
              TextField t3, t5;
              JTextArea display = new JTextArea("Welcome to HSBC Bank. \n Please enter your User Identification number \n", 5, 40);
              JPanel p1, p2, p3,p4;
              private JButton but1, but2, but3, but4,but5,but6,but7,but8,but9,but0,enter,
              cancel,fivepounds,tenpounds,twentypounds,fiftypounds,clearbut, refillbut;
              int state = 1;                                        
              public String pinCode ="";
              public      String userCode ="";
              int userCodeCount = 0;
              int PINCount = 0;
              String withdrawAmount = "";
              int atmBalance =200;
              private HSBC HSBCobj;     
              //ATM constructor that receives the HSBCobj g1 reference to where the HSBC class
              // in in the program
              // Calls the drawATMFrame method
              // add the observer to the HSBCobj reference so that the ATM can tell HSBC that
              // something has changed
              public Atm(HSBC g1)
                   HSBCobj = g1;
                   drawATMFrame();
                   System.out.println("Starting Atm constructor");
                   addObserver(HSBCobj);     
              // this is the method that draws the ATM interface
              // also apply the Border Layout to the frame
              public void drawATMFrame()
                   f1=new Frame("ATM");
                   f1.setLayout(new BorderLayout());
                   f1.setSize(350, 250);
                   f1.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)     
                             f1.dispose();
                             System.exit(0);     
                   // declare & instantiate all the buttons that will be used on the ATM
                   but1 =new JButton("1");
                   but1.addActionListener(this);
                   but2 =new JButton("2");
                   but2.addActionListener(this);
                   but3 =new JButton("3");
                   but3.addActionListener(this);
                   but4 =new JButton("4");
                   but4.addActionListener(this);
                   but5 =new JButton("5");
                   but5.addActionListener(this);
                   but6 =new JButton("6");
                   but6.addActionListener(this);
                   but7 =new JButton("7");
                   but7.addActionListener(this);
                   but8 =new JButton("8");
                   but8.addActionListener(this);
                   but9 =new JButton("9");
                   but9.addActionListener(this);
                   but0 =new JButton("0");
                   but0.addActionListener(this);
                   enter=new JButton("Enter");
                   enter.addActionListener(this);
                   cancel=new JButton("Cancel/ \n Restart");
                   cancel.addActionListener(this);
                   fivepounds =new JButton("?5");
                   fivepounds.addActionListener(this);
                   tenpounds = new JButton("?10");
                   tenpounds.addActionListener(this);
                   twentypounds = new JButton("?20");
                   twentypounds.addActionListener(this);
                   fiftypounds = new JButton("?50");
                   fiftypounds.addActionListener(this);
                   clearbut = new JButton("Clear");
                   clearbut.addActionListener(this);
                   refillbut = new JButton("Refill");
                   refillbut.addActionListener(this);
                   //declare & instantiate a textfield               
                   t3=new TextField(5);
                   // instantiate 4 JPanels     
                   p1=new JPanel();
                   p2=new JPanel();
                   p3=new JPanel();
                   p4=new JPanel();
                   // add some buttons to p1
                   p1.add(but1);
                   p1.add(but2);
                   p1.add(but3);
                   p1.add(but4);
                   p1.add(but5);
                   p1.add(but6);
                   p1.add(but7);
                   p1.add(but8);
                   p1.add(but9);               
                   p1.add(but0);
                   //add the text area field to p2
                   p2.add(display);
                   // apply the grid layout to p3
                   GridLayout layout3 = new GridLayout(4,1,5,5);
                   p3.setLayout(layout3);
                   p3.add(fivepounds);
                   p3.add(tenpounds);
                   p3.add(twentypounds);
                   p3.add(fiftypounds);
                   // apply grid layout to p4
                   GridLayout layout4 = new GridLayout(4,1,5, 5);
                   p4.setLayout(layout4);
                   p4.add(clearbut);
                   p4.add(enter);
                   p4.add(cancel);
                   p4.add(refillbut);
                   //add the panels to the different parts of the screen
                   f1.add("North", display);
                   f1.add("Center", p1);
                   f1.add("East", p4);
                   f1.add("West", p3);
                   f1.setVisible(true);
              }// end drawATMframe method
         public void actionPerformed(ActionEvent ae)
                   if(state == 1)
                             getUserIdNo(ae);
              else     if(state == 2)
                             doPINInput(ae);
                        else
                             withdrawCash(ae);     
         }// end action performed method               
    //******** STATE 1 events*/
    //******** USER ID INPUT*/
              public void getUserIdNo (ActionEvent ae)
                   if (ae.getSource() == but1)
                        display.append("*");
                        userCode = userCode + "1";
                        userCodeCount++;
                   if (ae.getSource() == but2)
                        display.append("*");
                        userCode = userCode + "2";
                        userCodeCount++;
                   if (ae.getSource() == but3)
                        display.append("*");
                        userCode = userCode + "3";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but4)
                        display.append("*");
                        userCode = userCode = "4";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but5)
                        display.append("*");
                        userCode = userCode + "5";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but6)
                        display.append("*");
                        userCode = userCode + "6";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but7)
                        display.append("*");
                        userCode = userCode + "7";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but8)
                        display.append("*");
                        userCode = userCode + "8";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but9)
                        display.append("*");
                        userCode = userCode + "9";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but0)
                        display.append("*");
                        userCode = userCode + "0";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == cancel)
                        display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                        userCode = "";
                        state = 2;
                   if (ae.getSource() == clearbut)
                        display.setText("Please enter your user ID number again\n");
                        userCode = "";
                        userCodeCount = 0;
                   if (ae.getSource() == refillbut)
                        refill();
                   if (ae.getSource() == enter)
                        display.setText("Please enter your PIN \n");
                        state = 2;
                        System.out.println(" User id enter button = " + userCode);
                   if (userCodeCount == 1)
                        display.setText("Please enter your PIN \n");
                        //userCode = "";
                        userCodeCount = 0;
                        state = 2;          
    //******** STATE 2               */
    //******** PIN INPUT*/
                   public void doPINInput(ActionEvent ae)
                        if (ae.getSource() == but1)
                             {      pinCode = pinCode.concat("1");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but2)
                             {      pinCode = pinCode.concat("2");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but3)
                             {      pinCode = pinCode.concat("3");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but4)
                             {      pinCode = pinCode.concat("4");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but5)
                             {      pinCode = pinCode.concat("5");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but6)
                             {      pinCode = pinCode.concat("6");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but7)
                             {      pinCode = pinCode.concat("7");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but8)
                             {      pinCode = pinCode.concat("8");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but9)
                             {      pinCode = pinCode.concat("9");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but0)
                             {      pinCode = pinCode.concat("0");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == clearbut)
                                  display.setText("Please enter your PIN number again \n");
                                  pinCode = "";     
                                  PINCount = 0;
                        if (ae.getSource() == cancel)
                                  display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                             state = 1;
                                  pinCode ="";
                                  PINCount = 0;                         
                        if (ae.getSource() == refillbut)
                                  refill();
    /// ************************ THIS BUTTON SENDS THE PIN & USER CODE OVER TO THE MAIN BANK*/
    /// ************************ (LINE 152)               */
                        if (ae.getSource() == enter)
    //                         if(HSBCobj.checkPinAndUserId(pinCode, userCode))
    //                              display.setText("How much would you like to withdraw \n");
    //                    else
    //                         display.setText("Your UserId and Pin code do not match");
                        if(PINCount ==4)
                        if(HSBCobj.checkPinAndUserId(userCode,pinCode))
                                  display.setText("Enter the amount you \n want to withdraw \n ?");
                                  PINCount=0;
                        else
                        display.setText("Your User Identification Number \n and PIN number do not match! \n please try again\n");     
    //*********** STATE 3 events*/
    //*********** withdrawCash*/
         public void withdrawCash(ActionEvent ae)
    //               if (ae.getSource() == but1)
    //                    display.append("1");
    ///                    withdrawAmount = withdrawAmount+1;
         //               pinCode = pinCode.concat("2");
         //               System.out.println("Withdrawal Amount = "+withdrawAmount);
                   if(ae.getSource( ) == but1)
                        withdrawAmount = withdrawAmount + "1";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but2)
                        withdrawAmount = withdrawAmount + "2";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but3)
                        withdrawAmount = withdrawAmount + "3";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but4)
                        withdrawAmount = withdrawAmount + "4";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but5)
                        withdrawAmount = withdrawAmount + "5";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but6)
                        withdrawAmount = withdrawAmount + "6";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but7)
                        withdrawAmount = withdrawAmount + "7";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but8)
                        withdrawAmount = withdrawAmount + "8";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but9)
                        withdrawAmount = withdrawAmount + "9";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but0)
                        withdrawAmount = withdrawAmount + "0";
                        display.setText(withdrawAmount);
                   if (ae.getSource() == fivepounds)
                        withdrawAmount = withdrawAmount + "5";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == tenpounds)
                        withdrawAmount = withdrawAmount + "10";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == twentypounds)
                        withdrawAmount = withdrawAmount + "20";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == fiftypounds)
                        withdrawAmount = withdrawAmount + "50";
                        display.setText(withdrawAmount);
                        atmBalance();
         //          if (ae.getSource() == tenpounds)
         //               display.append("10");
         //               withdrawAmount = 10;
         //               pinCode = pinCode.concat("2");
         //               System.out.println("10 pound button pressed");
         //               atmBalance();
                   if (ae.getSource() == enter)
                        atmBalance();
                   if (ae.getSource() == refillbut)
                        System.out.println("refill but pressed");
                        refill();     
                   if (ae.getSource() == clearbut)
                        System.out.println("clear but pressed");
                        display.setText("Enter the amount you want to withdraw \n ?");
                        withdrawAmount="";
                   if (ae.getSource() == cancel)
                        display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                        withdrawAmount="";
                   pinCode ="";
                        PINCount = 0;
                        userCode = "";
                        userCodeCount = 0;
                        state = 1;
         }// end withdraw cash input method
         // checks balace of atm and withdraws cash. Also notifies onserver if atm balance is low     
              public void atmBalance()
                   String s = withdrawAmount;
                   int n = Integer.parseInt(s);
                   if ( atmBalance >= n)
                        atmBalance = atmBalance - n;
                        System.out.println("atm balance = "+ atmBalance);
                        display.setText("Thankyou for using HSBC. \nYou have withdrawn ?"+n);
                        if     (atmBalance<40)
                             System.out.println("atm balance is less than 40 - notify HSBC" );
                             setChanged();
                             notifyObservers(this);
                             /// note the refil should send a message to the controller
                             // advising a refil is needed. The Bank will send an engineer
                             // out who will fill the atm up
              }// end atmBalance method
              /// note the refil should send a message to the controller
              /// then th coontroller will send a message to this method to fill machine
              /// (this is simulating a clerk filling atm)
                   public void refill()
                        System.out.println("in refill method" );
                        atmBalance = 200;
                        System.out.println("Atm has been refilled. Atm balance = " + atmBalance);
                   //     setChanged();
                   //     notifyObservers(this);
                   }// end refill method
    // NOTE SURE ABOUT THIS - DO I USE THE UPDATE METHOD TO NOTIFY HSBC THAT ATM REQUIRES FILLING
    // THIS IS THE WRONG PART OF THE PROGRAM (SHOULD BE IN HSBC) - IGNORE
                   public void update(Observable gm1, Object gameObj)
                        display.setText("Congratulations");               
                   }//end update method
         }// end Atm method
    }// end Assignment2 clas
    [\code]

    I wasn't trying to annoy anyone at all.
    I'm new to java and have been told that using the observer/observable model is not considered basic java. So that is the only reason I posted it in this section. At the same time i feel that the bit I'm struggling with is actually basic - hence posting it in the basic section. I'm not sure if people of all abilities check all forums or just the ones they feel at at their standard.
    So appologies if you've taken offence.

  • Can someone help with this simple application

    I am taking my first java class and there are limited resourses for the class as far as getting help with coding.
    Any hoo if any one can point me in the correct direction from the following information listed below I would be greatfull. I am trying to use the set and get methods on the instance veriables and then I am goign to post the results once I get them workign to a JOption pane window.
    examples are most welcome thanks
    // Invoice.java
    // Homework assignment 3.13
    // Student Arthur Clark
    public class Invoice // public class
    String partNumber;// instance veriable quantity
    String partDescription;// instance verialbe partDescription
    //constructors
    public void setpartNumber( String number, String description )
              partNumber = number; //initalize quantity
              partDescription = description; // initalize partDescription
         }// end constructors
    //method getpartNumber
    public String getpartNumber()
              return partNumber;
         }//end method getpartNumber
    public String getpartDescription()
              return partDescription;
         }// end method getpartDescription
    public void displayMessage()
         //this is the statement that calls getpartNumber
         System.out.printf(" part number # \n%s!\n the description", getpartNumber(), getpartDescription() );
    } // method displaMessage
    }// end method main
    // Fig. 3.14 InvoiceTest.java
    // Careate and manipulate an account object
    import java.util.Scanner;
    import javax.swing.JOptionPane;//import JOptionPane
    public class InvoiceTest{
         // main method begins the exciution of the program
         public static void main ( String args [] )
              // create Scanner to obtain input from mommand window
              Scanner input = new Scanner ( System.in );
              // create a Invoice object and assig it to mymethod
              Invoice myMethod = new Invoice();
              Invoice myMethod2 = new Invoice();
              // display inital value of partName, partDescriptoin
              System.out.printf( "inital partname is %s\n\n", myMethod.getpartNumber() );
              // prompt for and read part name, partDescription
              System.out.println( "please enter the Part Number:" );
              String theNumber = input.nextLine(); // read a line of text
              myMethod.setpartNumber( theNumber ); // set the part name with in the parens
              System.out.println();// outputs blank line
              myMethod.displayMessage();
              System.out.println( "please enter the Part Description" );
              String theDescription = input.nextLine(); // read a line of text
              myMethod2.setpartDescription( theDescription );// set the part description
              System.out.println();// outputs blank line
              myMethod2.displayMessage();
         }// end main mehtod
    }// end class

    //constructors
    public void setpartNumber( String number, String description )
              partNumber = number; //initalize quantity
              partDescription = description; // initalize partDescription
         }// end constructorsThe above code is not a constructor. You do not include a return type, void or anything else. Also, the constructor should be called the same as your class.
    public Invoice( String number, String description )
              partNumber = number;
              partDescription = description;
         } Another thing, comments should only be used when it isn't bleedingly obvious what your code is doing.
    P.S. is your middle initial C?

  • Help with a simple login method..!!

    HI guys, im trying to understand what each line does can sumone please explain??
    all i know is that it is a button event and something happens when the buttonn is pressed...
    private void submitButton_actionPerformed(ActionEvent e)
    String[] data = new String[2];
    data[0] = textLogin.getText();
    if(data[0].length() == 0) return;
    char[] c = textPass.getPassword();
    data[1]= new String(c);
    if(data[1].length()==0) return;
    controller.loginAction(data);

    HI guys, im trying to understand what each line does
    can sumone please explain??
    all i know is that it is a button event and something
    happens when the buttonn is pressed...
    private void submitButton_actionPerformed(ActionEvent
    e)
    String[] data = new String[2];Creates an array of two strings called data
    data[0] = textLogin.getText();assigns the first item of the data array to the login text (username??)
    if(data[0].length() == 0) return;if the length of the first object is 0 then it is supposed to return to the calling function
    char[] c = textPass.getPassword();creates a character array and assigns it the value of the password
    data[1]= new String(c);this assigns the second item of the data array the value of the char array from above
    if(data[1].length()==0) return;if the length of the password is 0 then it returns to the calling function
    controller.loginAction(data);sends the data array as a parameter to another function that seems to do something with the login information (username, and password)
    basically the author is just showing two of the many ways to create a string
    The first way assigns the string value directly. The second way assigns the string value with a char array which is just another form of the String constructor.
    In the end this button is used to verify the username and password entered into the form.

  • Im DROWNING! need help with a simple java assignment! plz someone help me!

    i need help with my java assignment, with validating a sin number. easy for must who know java. im drowning... please help!

    You will need to store each digit of the social insurance number in a field of its own. To validate the entry you will:
    1. Multiply the 2nd, 4th, 6th and 8th digit by 2.
    2. If the product of any of the four multiplications result in a value greater than 9, add the two resulting digits together to yield a single-digit response. For example 6 * 2 = 12, so you would add the 1 and the 2 to get a result of 3.
    3. Add these four calculated values together, along with the 1st, 3rd, 5th, and 7th digits of the original number.
    4. Subtract this sum from the next highest multiple of 10.
    5. The difference should be equal to the 9th digit, which is considered the check digit.
    Example of validating S.I.N. 765932546
    1st digit 7
    2nd digit (6*2 =12 1+2=) 3
    3rd digit 5
    4th digit (9*2 = 18 1+8 =) 9
    5th digit 3
    6th digit (2*2 = 4) 4
    7th digit 5
    8th digit (4*2 = 8) 8
    Total 44 next multiple of 10 is 50
    50-44 = 6 which is the 9th digit
    Therefore the S.I.N. 765932546 is Valid
    ********* SIN Validation *********
    Welcome - Please enter the first number: 120406780
    Second digit value multiplied by 2 4
    Fourth digit value multiplied by 2 8
    Sixth digit value multiplied by 2 12
    Eighth digit value multiplied by 2 16
    Value derived from 6th digit 3
    Value derived from 8th digit 7
    The total is 30
    Calculated digit is 10
    Check digit must be zero because calculated value is 10
    The SIN 120406780 is Valid
    this is my assignemtn this is what i have! i dont know where to start! please help me!
    /*     File:     sinnumber.java
         Author:     Ashley
         Date:     October 2006
         Purpose: Lab1
    import java.util.Scanner;
    public class Lab1
              public static void main(String[] args)
                   Scanner input = new Scanner(System.in);
                   int sin = 0;
                   int number0, number1, number2, number3, number4, number5, number6, number7, number8;
                   int count = 0;
                   int second, fourth, sixth, eighth;
                   System.out.print("\t\n**********************************");
                   System.out.print("\t\n**********SIN Validation**********");
                   System.out.print("\t\n**********************************");
                   System.out.println("\t\nPlease enter the First sin number: ");
                   sin = input.nextInt();
                   count = int.length(sin);     
                   if (count > 8 || count < 8)
                   System.out.print("Valid: ");
         }

  • I need help with a Object Array

    I am having trouble and this maybe really simple seeing that I am fairly new to java but I have text that is being broken down in to preset part with those parts stored in Object arrays.
    Now I also have a object array inside my object array. Within the second object array are the broken down parts of the text and I want to compare this text with another string so for example this is what I am trying
    boolean found = false;
    for (int i = 0; i < FirstObjectArray.length ;i++)
         Object[] SecondObjectArray = (Object[]) FirstObjectArray;
         if(SecondObjectArray[0] == "string")
              found = true;
              break;
         else
              found = false;
    }Help would be very appreciated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    astlanda wrote:
    Sure, you're right.
    [public boolean equals(Object obj)|http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#equals%28java.lang.Object%29]
    sharkura said all the OP needs at the moment. I just wanted to clarify a bit why You don't use == 99.999% of the time with objects, and never with String.
    I have argued elsewhere in these forums that it is inappropriate to tell anyone that you never use == to compare objects. This has not always been accepted. I have, on rare occasions, known experienced developers to blindly compare two objects with equals(), and cite the professor that taught them, 15 years iin the past, that object references are never compared using ==, but always with equals().
    However, the cases where == is appropriate and equals() is not are indeed rare, but not, in my experience, non-existent. In my statement, I probably exaggerated. And String is a case where I can probably accept that you will probably never go wrong with equals(). If the String has been pooled (see String::intern()), you can actually use either. From the javadocs: "*It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true.*"
    ¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Newbie help with a "simple" VI.

    Hi all,
    I need to write a VI with the following specifications:
    Input: An integer
    Output:  Two integers mapping the input integer to a coordinate system based on the following mapping system:
     22 23 24 25 ..
     21 06 07 08 09 
     20 05 00 01 10 
     19 04 03 02 11 
     18 44 45 46 12 
     17 16 15 14 13 
    For instance, an input of 0 would be an output of (0,0). An input of 5 would be an output of (-1, 0)  and an input of 23 would be an output of (-1, 2).
     As you can see it is just a clockwise rectangular coordinate system starting with 0 in the middle.
    I am new to LabVIEW and am having trouble visualizing how to do this. If I were in a text based language, I would do something like create a 2d array of booleans representing my coordinate system, and travel around in a clockwise circle marking each as true until I reached the input number, then output my current row and column. Does anyone have any suggestions of the best way to do it in LabVIEW? (In case you were curious why I don't stick with a language I know-- LabVIEW has the drivers for the motion controller I am using).
    I know this is not as complex as many of the questions here, but any help or tips would be appreciated! 

    22 23 24 25 ..
     21 06 07 08 09 
     20 05 00 01 10 
     19 04 03 02 11 
     18 44 45 46 12 
     17 16 15 14 13 
     As you can see it is just a clockwise rectangular coordinate system starting with 0 in the middle.
    --- Actually, I'm having trouble seeing that, as the "44 45 46" seems out of place.
    --- I'll assume that is an error in your table, not an error in your words.
     I know this is not as complex as many of the questions here, but any help or tips would be appreciated! 
    --- Actually, this sort of thing is fun for me, because I get to be creative.
    Consider the rules for generating a spiral pattern like that. 
    Let's use a complex number to represent a position: Imag = row, Real = column
    Let's use a complex number to represent a DIRECTION: 0-1i = up, 1+0i = right, 0+1i = down, -1+0i = left
    Let's remember that multiplying a complex number by 0+1i is a turn of 90 degrees.
    Let's start out with a position and a direction:
    POSITION = 2+2i
    DIRECTION = 0-1i  (up)
    Let's start out with an array of -1 numbers (meaning empty cells)
    To generate the array is then simple:
    FOR i = 0 to N-1  // however many cells needed
        CellArray[POSITION.imag, POSITION.real] = i  // put a number into the cell.
        TURNRIGHT = DIRECTION * 0+1i //  look 90 degrees right
        if CellArray[TURNRIGHT.imag, TURNRIGHT.real] < 0  // if that cell is empty
            DIRECTION = TURNRIGHT         // turn right
        end if
        POSITION = POSITION + DIRECTION // move to next cell
     end for
    The upper FOR loop in the code demonstrates this.
    The lower WHILE  loop in the code is basically the same, but it:
    stops when it reaches the input number
    Subtracts the starting position from the current position
    Converts the complex number to X and Y values
    I believe your third example ("an input of 23 would be an output of (-1, 2).") is wrong, because of the 44-46 problem.
    Here is the code, attached is a VI.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    Spiral.vi ‏11 KB

Maybe you are looking for

  • Help with cutting a whole in an image/clipping mask

    Hello. I am needing to cut out circles in an image so that the background shows through. Sort of like an inverse clipping mask..but I don't know if those exist..  And once I cut holes in the image I am needing to put a clipping mask on the whole thin

  • How do import footage off of a DVD into Premiere?

    I'm helping a lady do a project that involves capturing video and importing pictures, etc. It's just like a little home video for her grandkids and family, for the intro of the video she wants to put in footage from a "Blues Clues" kids DVD (basciall

  • PCA report rolling figure

    we are extending S_alr_87013326  and create a new ABAP report to include  rolling 6 months of actual number. can we use GRR3 or report painter, which library is S_alr_87013326 belonging to? if we use ABAP code, then which table we should use to get r

  • Running 8.1 64 bit and sql server 5 32bit keeps installing on my brand new HP

    My old laptop has sql server 5 32bit on it and I just bought a HP Pavilion 500-200t.  As soon as I connect to the internet, the sql 5 comes back on my 64bit computer and makes it very slow.  I want to uninstall the 5 because I can't update it to run

  • The scrollbar won't move when I click the up and down arrows or try to drag the bar, why is that?

    I just updated to version 4.0.1. After I updated and got the browser up again, I tried to scroll by clicking the bar and trying to drag it. This didn't work. So then I tried clicking the up and down arrows. This did not work either. The only way I am