Help with creating own classes then manipulating with an array

import java.util.Scanner;
public class Booking {
    private String bookingId;
    private String bookingName;
    private int numberOfPassengers;
    public Booking(String bookingId, String bookingName, int numberOfPassengers) {
        bookingId = bookingId;
        bookingName = bookingName;
        numberOfPassengers = 0;
    public static final double BASIC_RATE = 80;
    public String getBookingId() {
        return bookingId;
    public String getBookingName() {
        return bookingName;
    public int getNumberOfPassengers() {
        return numberOfPassengers;
    public double calculateBookingPrice() {
        return (BASIC_RATE * numberOfPassengers);
    public void summary() {
        System.out.println("Booking Number: " + bookingId);
        System.out.println("Booking made for: " + bookingName);
        System.out.print("Booking Price: $");
        System.out.printf("%6.2f", calculateBookingPrice());
public class CabinBooking extends Booking {
    private String cabinNumber;
    private boolean dinner;
    public CabinBooking(String cabinNumber, boolean dinner) {
        super(bookingId, bookingName, numberOfPassengers);
        cabinNumber = cabinNumber;
        dinner = false;
    public String getCabinNumber() {
        return cabinNumber;
    public void upgradeBooking(boolean status) {
        dinner = false;  
    public double calculateBookingPrice() {
        double dinnerCost;
        dinnerCost = 40;
        return(300 + ((numberOfPassengers - 2) * 100) +
            (numberOfPassengers * dinnerCost));
    public void summary() {
        super.summary();
        System.out.println("Cabin Number: " + cabinNumber);
        if (dinner = false)
            System.out.println("Dinner Included: No");
        else
            System.out.println("Dinner Included: Yes");
            System.out.print("Dinner Booking Fee: $");
            System.out.printf("%6.2f", calculateBookingPrice());
public class Booking {
public static void main (String[] args) {
    String bookingId, bookingName;
    int i;
    Scanner keyboard = new Scanner(System.in);
    Booking[] bookings = new Booking[5];
        bookings[0] = new Booking("C001", "Dorothy the Dinosaur", 1, "C23");
        bookings[1] = new Booking("B001", "Bob the Builder", 1);
        bookings[2] = new Booking("C002", "Donald Duck", 4, "B10");
        bookings[3] = new Booking("C003", "The Wiggles", 4, "D14");
        bookings[4] = new Booking("B002", "Mickey Mouse", 2);
        bookings[5] = new Booking("B003", "Hi Five (Minus One)", 4);
    for (i=0; i<5; i++) {
        System.out.println("List of booking ID's and names:");
        System.out.println();
        System.out.println("Booking Number: " + (i+1) + "Booking made for: " + (i+1));
        bookings[i] = new Booking(bookingId, bookingName);
}

import java.util.Scanner;
public class Booking {
    private String bookingId;
    private String bookingName;
    private int numberOfPassengers;
    public Booking(String bookingId, String bookingName, int numberOfPassengers) {
        bookingId = bookingId;
        bookingName = bookingName;
        numberOfPassengers = 0;
    public static final double BASIC_RATE = 80;
    public String getBookingId() {
        return bookingId;
    public String getBookingName() {
        return bookingName;
    public int getNumberOfPassengers() {
        return numberOfPassengers;
    public double calculateBookingPrice() {
        return (BASIC_RATE * numberOfPassengers);
    public void summary() {
        System.out.println("Booking Number: " + bookingId);
        System.out.println("Booking made for: " + bookingName);
        System.out.print("Booking Price: $");
        System.out.printf("%6.2f", calculateBookingPrice());
class CabinBooking extends Booking {
    private String cabinNumber;
    private boolean dinner;
    public CabinBooking(String cabinNumber, boolean dinner) {
        super(bookingId, bookingName, numberOfPassengers);
        cabinNumber = cabinNumber;
        dinner = false;
    public String getCabinNumber() {
        return cabinNumber;
    public void upgradeBooking(boolean status) {
        dinner = false;  
    public double calculateBookingPrice() {
        double dinnerCost;
        dinnerCost = 40;
        return(300 + ((numberOfPassengers - 2) * 100) +
            (numberOfPassengers * dinnerCost));
    public void summary() {
        super.summary();
        System.out.println("Cabin Number: " + cabinNumber);
        if (dinner = false)
            System.out.println("Dinner Included: No");
        else
            System.out.println("Dinner Included: Yes");
            System.out.print("Dinner Booking Fee: $");
            System.out.printf("%6.2f", calculateBookingPrice());
public static void main (String[] args) {
    String bookingId, bookingName;
    int i;
    Scanner keyboard = new Scanner(System.in);
    Booking[] bookings = new Booking[5];
        bookings[0] = new Booking("C001", "Dorothy the Dinosaur", 1, "C23");
        bookings[1] = new Booking("B001", "Bob the Builder", 1);
        bookings[2] = new Booking("C002", "Donald Duck", 4, "B10");
        bookings[3] = new Booking("C003", "The Wiggles", 4, "D14");
        bookings[4] = new Booking("B002", "Mickey Mouse", 2);
        bookings[5] = new Booking("B003", "Hi Five (Minus One)", 4);
    for (i=0; i<5; i++) {
        System.out.println("List of booking ID's and names:");
        System.out.println();
        System.out.println("Booking Number: " + (i+1) + "Booking made for: " + (i+1));
        bookings[i] = new Booking(bookingId, bookingName);
   }fixed that but still won't compile

Similar Messages

  • Help with parallel arrays of different data types

    Hello all, I am having an issue with parallel arrays. My program requires me to read information from a text file into 4 parallel arrays (2 String and 2 double). My text file needs to look something like this:
    John Johnson
    0000004738294961
    502.67
    1000.000
    Jane Smith
    0000005296847913
    284.51
    1000.000
    ...and so on
    Where the first thing is the name (obviously), an account number, the balance in the account, and the credit limit. I just cant figure out how to read everything into the arrays. We havent learned anything too heavy, and this seems a little too advanced for my class, but I guess we will manage. Any help will be appreciated. Thanks guys.
    Casey

    Man this is a dumb homework assignment. The requirements scream out for a class along the lines of
    public class Account{
      private String name, number;
      private double balance,creditlimit;
       // more code here
    }and then to use a List of Account objects.
    Anyway what's your actual problem. There's nothing very hard about it. A loop. So....
    You should consider posting (formatted) code showing what you have done and where exactly you are stuck.

  • Help with an array program

    I can't see how to calculate the lowest hours, highest hours, and average hours worked.
    These three values should be outputted each on a seperate line.
    I just can't figure this out.
    Any help please.
    This program will show the employees
    hours. It will have one
    class.It will use an array to keep
    track of the number of hours the employee
    has worked with the output to the monitor
    of the employees highest, lowest, and the
    average of all hours entered. */
    import java.util.*;
    import java.text.DecimalFormat;
    /*** Import Decimal Formating hours to format hours average. ***/
    public class cs219Arrays
         public static void main(String[] args)
              Scanner scannerObject = new Scanner(System.in);
              int[] employees ={20, 35, 40};
              int employeesHighest = 40;
              int employeesLowest = 20;
              double employeesAverage = 35;
              int[] firstEmployee = new int[1];
              int[] secondEmployee = new int[2];
              int[] thirdEmployee = new int[3];
              System.out.println("This program will accept hours worked for 3 employees.");
              System.out.println("Enter hours worked for employee #: ");
              System.out.println(".\n");
              employeesAverage = scannerObject.nextInt();
              for(int count =20; count <= 40; count++)
                             DecimalFormat df = new DecimalFormat("0.00");
                             System.out.println("pay: " employeesAverage " lowest " employeesHighest " Highest hours " employeesLowest " Lowest hours "+df.format(employeesAverage));
                             System.out.print("\n");
                             employeesAverage++;
    }/* end of body of first for loop */
              for(int count =20; count <= 40; count++)
                                       employeesAverage = employeesAverage + employeesHighest + employeesLowest;
                                       DecimalFormat df = new DecimalFormat("0.00");
                                       System.out.println("pay: $" employeesAverage " lowest " employeesHighest " Highest hours $" +df.format(employeesAverage));
                                       System.out.print("\n");
                                       employeesAverage++;
    }/* end of body of second for loop */
              for(int count =20; count <= 40; count++)
                                       employeesAverage = employeesAverage + employeesHighest + employeesLowest;
                                       DecimalFormat df = new DecimalFormat("0.00");
                                       System.out.println("pay: $" employeesAverage " lowest " employeesHighest " Highest hours $" +df.format(employeesAverage));
                                       System.out.print("\n");
                                       employeesAverage++;
    }/* end of body of third for loop */
              System.out.println("\n");
              DecimalFormat twoDigits = new DecimalFormat("0.00");
              /*** Create new DecimalFormat object named twoDigits ***/
              /*Displays number of hours, employees hours and average hours.*/
              System.out.println("You entered " + employeesAverage + " number of hours.");
              System.out.println("Your number of hours are " + twoDigits.format(employeesAverage));
              System.out.println("\n\n");
    }     /*End of method for data.*/
    {     /*Main method.*/
    }     /*End of main method.*/
    }     /*End of class cs219Arrays.*/

    Want help?
    Use the code formatting tags for starters. http://forum.java.sun.com/help.jspa?sec=formatting

  • I need help with 2 arrays

    I need help with this portion of my program, it's supposed to loop through the array and pull out the highest inputted score, currently it's only outputting what is in studentScoreTF[0].      
    private class HighScoreButtonHandler implements ActionListener
               public void actionPerformed(ActionEvent e)
              double highScore = 0;
              int endScore = 0;
              double finalScore = 0;
              String tempHigh;
              String tempScore;
              for(int score = 0; score < studentScoreTF.length; score++)
              tempHigh = studentScoreTF[score].getText();
                    tempScore = studentScoreTF[endScore].getText();
              if(tempHigh.length() <  tempScore.length())
                   highScore++;
                   finalScore = Double.parseDouble(tempScore);
             JOptionPane.showMessageDialog(null, "Highest Class Score is: " + finalScore);This is another part of the program, it's supposed to loop through the student names array and pull out the the names of the students with the highest score, again it's only outputting what's in studentName[0].
         private class StudentsButtonHandler implements ActionListener
               public void actionPerformed(ActionEvent e)
              int a = 0;
              int b = 0;
              int c = 0;
              double fini = 0;
              String name;
              String score;
              String finale;
              String finalName = new String();
              name = studentNameTF[a].getText();
              score = studentScoreTF.getText();
              finale = studentScoreTF[c].getText();
              if(score.length() < finale.length())
                   fini++;     
                   name = finalName + finale;
         JOptionPane.showMessageDialog(null, "Student(s) with the highest score: " + name);
                   } Any help would be appreciated, this is getting frustrating and I'm starting to get a headache from it, lol.
    Edited by: SammyP on Oct 29, 2009 4:18 PM
    Edited by: SammyP on Oct 29, 2009 4:19 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Heres a working example:
    class Compare {
        public int getHighest(int[] set) {
            int high = set[0];
            for(int i = 0; i < set.length; i++) {
                if(set[i] > high) {
                    high = set;
    return high;

  • HELP WITH CHAR ARRAY

    Here is the go folks this is a pice of code which I was helped with by a member of this forum, THANX HEAPS DUDE. What has happened now is the criteria is changed, previously it would search for a string in the vector. But now I have to have searches with wildcards, so it needs to utilize a char array methinks. So it will go through change the parameter to a char array, then go through the getDirector() method to return a director string, then it needs to loop through the char array and check if the letters are the same. then exit on the wild card. Now all this needs to be happening while this contruct down the bottom is looping through all the different elements in the moviesVector :s if anyone could give me a hand it is verry welcome. I must say also that this forum is very well run. 5 stars
    public void searchMovies(java.lang.String searchTerm) {
    Iterator i = moviesVector.iterator();
    while (i.hasNext()) {
    Movie thisMovie = (Movie)i.next();
    //Now do what you want with thisMovie. for instanse:
    if (thisMovie.getDirector().equals(searchTerm))
    foundMovies.add(thisMovie);
    //assumes foundMovies is some collection that we will
    //return later... or if you just want one movie, you can:
    //return thisMovie; right here.
    }

    Sorry, I clicked submit, but i didnt enable to wtch it, so i stoped it before it had sent fully. Evidently that didnt work.

  • HELP: Import my own class in JSP ???

    Hi, all!
    I read many previous topics in this forum but no one works for me!
    Please someone help me!
    I'm using Tomcat 4.1.12 and my JSP scripts work just fine, but I need to import my own .class file. I just don't know where to put it so Tomcat can find it!?
    I have this environment variable:
    JAVA_HOME=.;c:\jdk1.3.1
    And in my code I'want to place something like this:
    <%@ page import="myClass" %>
    But I get a "can not resolve symbol" exception.
    Thanks for readind this, and please help if you can!
    Bye.
    adriano

    Within the Tomcat directory, under your application directory place the class file/s into the WEB-INF/classes directory. If your classes are part of a package place the entire directory structure of the package under the WEB-INF/classes directory.
    The import in the JSP is the same as for any Java class.
    Hope this solves your problem.

  • Help with PHP array code

    Not sure what's going on here, but hopefully someone can spot where I'm going wrong.
    Its especially weird, as I'm using the same code, with the same database table names etc but on a different site.
    Basically, I've set up a database table to store customer feedback on products.
    Its all working fine on this site :
    http://www.mye-reader.co.uk/customerreviews.php
    But on the site I'm working on, its only showing the first record. There are only a couple of records at the moment, but I've tried changing the query from ASC to DESC, and it swaps the one it shows, so it looks like the issue is with the array. Even though its the same code.
    http://www.mybabymonitors.co.uk/reviews.php
    Anyway, my query looks like :
    mysql_select_db($database_connPixelar, $connPixelar);
    $query_rsReviews = "SELECT * FROM feedback WHERE Approved = 'Yes' ORDER BY Product DESC";
    $rsReviews = mysql_query($query_rsReviews, $connPixelar) or die(mysql_error());
    $row_rsReviews = mysql_fetch_assoc($rsReviews);
    $totalRows_rsReviews = mysql_num_rows($rsReviews);
    And the array code looks like :
    <table cellpadding="0" cellspacing="0" width="100%" border="0">
           <?php
         $groups = array();
    while ($row = mysql_fetch_assoc($rsReviews)) {
        $groups[$row['Product']][] = $row;
    foreach ($groups as $product_name => $rows) {
        echo "<tr><td class=\"product\">$product_name</td></tr>";
        foreach ($rows as $row) {
            echo "<tr><td class=\"review\">".$row['Review']."</td></tr>";
            echo "<tr><td class=\"name\">".$row['CustomerName']."</td></tr>";
            echo "<tr><td class=\"date\">".$row['Date']."</td></tr>";
    ?>
    </table>
    Any ideas what's going on here?

    Its OK - I figured it out - it was the
    $row_rsReviews = mysql_fetch_assoc($rsReviews);
    line in the query.
    Turns out it wasn't that one was working, and the other not - they were both starting from the second record.

  • Help on creating Java Classes from WSDL in JDev 10.1.3

    Hi all,
    I am creating Java Web Service Class in JDev 10.1.3 based on my WSDL file, but I am getting a JAVA class for each Element in my WSDL, and each class has its own methods. But what I need is to have Only ONE Class with the Elements wrapped as methods in this class (this is the result I had when I was using JDev 9.0.2 but I had Datatype conversion issue, so now I am trying to do the same with JDev 10.1.3)
    My WSDL file is as follows:
    - <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
    - <s:element name="Connect">
    <s:complexType />
    </s:element>
    - <s:element name="ConnectResponse">
    <s:complexType />
    </s:element>
    - <s:element name="Disconnect">
    <s:complexType />
    </s:element>
    - <s:element name="DisconnectResponse">
    <s:complexType />
    </s:element>
    - <s:element name="GetPIValue">
    - <s:complexType>
    - <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="piTAG" type="s:string" />
    <s:element minOccurs="0" maxOccurs="1" name="piTS" type="s:string" />
    </s:sequence>
    </s:complexType>
    </s:element>
    - <s:element name="GetPIValueResponse">
    - <s:complexType>
    - <s:sequence>
    <s:element minOccurs="1" maxOccurs="1" name="GetPIValueResult" type="s:double" />
    </s:sequence>
    </s:complexType>
    </s:element>
    <s:element name="double" type="s:double" />
    </s:schema>
    When creating the JAVA Classes in JDev, I am getting the following:
    Connect.java
    ConnectResponse.java
    Disconnect.java
    DisconnectResponse.java
    GetPIValue.java
    GetPIValueResponse.java
    But what I actually need is to have a Method GetPiValue that should take in 2 paramters as strings and return a Double Value. Now the GetPIValue looks like this:
    package ConnecttoPI;
    public class GetPIValue implements java.io.Serializable {
    protected java.lang.String piTAG;
    protected java.lang.String piTS;
    public GetPIValue() {
    public java.lang.String getPiTAG() {
    return piTAG;
    public void setPiTAG(java.lang.String piTAG) {
    this.piTAG = piTAG;
    public java.lang.String getPiTS() {
    return piTS;
    public void setPiTS(java.lang.String piTS) {
    this.piTS = piTS;
    With this class Generated, how can I call the Class Methods and get the response?
    Do I have to change the way/settings when I am creating the Java Classes using the Wizard? Why is the Wrapper wrapping the WSDL in multiple classes?
    Thanks to anyone's help in advance.
    Regards,
    Baz

    An update to my previous Post:
    After creating the Web Service proxy based on my WSDL file, I tested the Web Service Call from the Java Class (Service1SoapClient) and it is properly Calling the Web Service passing in String Paramters (2 Strings) and returning a Double Datatype. The Class is as below:
    package project1.proxy;
    import oracle.webservices.transport.ClientTransport;
    import oracle.webservices.OracleStub;
    import javax.xml.rpc.ServiceFactory;
    import javax.xml.rpc.Stub;
    public class Service1SoapClient {
    private project1.proxy.Service1Soap _port;
    public Service1SoapClient() throws Exception {
    ServiceFactory factory = ServiceFactory.newInstance();
    _port = ((project1.proxy.Service1)factory.loadService(project1.proxy.Service1.class)).getService1Soap();
    * @param args
    public static void main(String[] args) {
    try {
    project1.proxy.Service1SoapClient myPort = new project1.proxy.Service1SoapClient();
    System.out.println("calling " + myPort.getEndpoint());
    // Add your own code here
    double testResponse = myPort.getPIValue("A3LI004.pv", "9/9/2007 9:20 am");
    System.out.println("response from PI " + testResponse);
    } catch (Exception ex) {
    ex.printStackTrace();
    * delegate all operations to the underlying implementation class.
    Connect to PI Server
    public void connect() throws java.rmi.RemoteException {
    _port.connect();
    Disconnect from PI Server
    public void disconnect() throws java.rmi.RemoteException {
    _port.disconnect();
    Retrieve PI Values
    public double getPIValue(String piTAG, String piTS) throws java.rmi.RemoteException {
    return _port.getPIValue(piTAG, piTS);
    Now I am trying to IMPORT this class into Oracle Forms, but I am getting the following Error:
    Importing Class project1.proxy.Service1SoapClient...
    Exception occurred: java.lang.NoClassDefFoundError: oracle/webservices/transport/ClientTransport
    First, is this the Correct Class that should be Imported into Oracle Forms in order to Trigger the Java Class to Call the Web Service? Why am I getting this Error? I have read that this could be because of my CLASSPATH environment variable or the J2SE version compiling the java class???
    Can someone help me to IMPORT this Java Class properly into Oracle Forms and Call the Web Service?
    Many thanks for your help,
    Baz

  • Need help with adding arrays to invoice.java please willing to pay?

    Using your Invoice class created in lab02, write a client program that allows the user to input three Invoice objects into an array of Invoice objects. After you have inputted all of the invoices, print a heading and then output all of the array elements (Invoice objects) by calling the method from your Invoice class that displays all of the data members on a single line using uniform field widths to insure that all Invoice objects will line up in column format (created in Lab04). At the end of the loop, display the calculated total retail value of all products entered in the proper currency format.
    Example of possible program execution:
    Part Number : WIDGET
    Part Description : A fictitious product
    Quantity : 100
    Price          : 19.95
    (etc.)
    Example of possible output
    Part Number          Part Description          Quantity          Price     Amount
    WIDGET          A fictitious product     100          19.95     199.95
    Hammer               9 pounds          10          5.00     50.00
    (etc.)
    Total Retail Value:                                   249.95
    This is what i have so far Invoice Test
    //Lab 2 InvoiceTest.java
    //Application to test class Invoice.
    //By Morris Folkes
    public class InvoiceTest
    public static void main( String args[] )
    Invoice invoice1 = new Invoice( "1234", "Hammer", 2, 14.95 );
    // display invoice1
    System.out.println( "Original invoice information" );
    System.out.printf( "Part number: %s\n", invoice1.getPartNumber() );
    System.out.printf( "Description: %s\n",
    invoice1.getPartDescription() );
    System.out.printf( "Quantity: %d\n", invoice1.getQuantity() );
    System.out.printf( "Price: %.2f\n", invoice1.getPricePerItem() );
    System.out.printf( "Invoice amount: %.2f\n",
    invoice1.getInvoiceAmount() );
    // change invoice1's data
    invoice1.setPartNumber( "001234" );
    invoice1.setPartDescription( "Blue Hammer" );
    invoice1.setQuantity( 3 );
    invoice1.setPricePerItem( 19.49 );
    // display invoice1 with new data
    System.out.println( "\nUpdated invoice information" );
    System.out.printf( "Part number: %s\n", invoice1.getPartNumber() );
    System.out.printf( "Description: %s\n",
    invoice1.getPartDescription() );
    System.out.printf( "Quantity: %d\n", invoice1.getQuantity() );
    System.out.printf( "Price: %.2f\n", invoice1.getPricePerItem() );
    System.out.printf( "Invoice amount: %.2f\n",
    invoice1.getInvoiceAmount() );
    Invoice invoice2 = new Invoice( "5678", "PaintBrush", -5, -9.99 );
    // display invoice2
    System.out.println( "\nOriginal invoice information" );
    System.out.printf( "Part number: %s\n", invoice2.getPartNumber() );
    System.out.printf( "Description: %s\n",
    invoice2.getPartDescription() );
    System.out.printf( "Quantity: %d\n", invoice2.getQuantity() );
    System.out.printf( "Price: %.2f\n", invoice2.getPricePerItem() );
    System.out.printf( "Invoice amount: %.2f\n",
    invoice2.getInvoiceAmount() );
    // change invoice2's data
    invoice2.setQuantity( 3 );
    invoice2.setPricePerItem( 9.49 );
    // display invoice2 with new data
    System.out.println( "\nUpdated invoice information" );
    System.out.printf( "Part number: %s\n", invoice2.getPartNumber() );
    System.out.printf( "Description: %s\n",
    invoice2.getPartDescription() );
    System.out.printf( "Quantity: %d\n", invoice2.getQuantity() );
    System.out.printf( "Price: %.2f\n", invoice2.getPricePerItem() );
    System.out.printf( "Invoice amount: %.2f\n",
    invoice2.getInvoiceAmount() );
    } // end main
    } // end class InvoiceTest

    i suck in java There are 2 possible reasons for this:
    1. you haven't studied
    2. you aren't cut out for programming
    and there r hardly any tutors at my school. plus i work 2 jobs day n night. Please, I'm only want help thats allYou have the help of the ENTIRE WORLD COMMUNITY right here, right now. But you're not willing to make any effort whatsoever. You think people will help or even respect you? You may fail your class and you may fail in life!
    Cheaters don't win and winners don't cheat!

  • Need Help with simple array program!

    Hi, I have just recently started how to use arrays[] in Java and I'm a bit confused and need help designing a program.
    What this program does, it reads in a range of letters specified by the user. The user then enters the letters (a, b or c) and stores these characters into an array, which the array's length is equal to the input range the user would enter at the start of the program. The program is then meant to find how many times (a,b and c) appears in the array and the Index it first appears at, then prints these results.
    Here is my Code for the program, hopefully this would make sense of what my program is suppose to do.
    import B102.*;
    class Letters
         static int GetSize()
              int size = 0;
              boolean err = true;
              while(err == true)
                   Screen.out.println("How Many Letters would you like to read in?");
                   size = Keybd.in.readInt();
                   err = Keybd.in.fail();
                   Keybd.in.clearError();
                   if(size <= 0)
                        err = true;
                        Screen.out.println("Invalid Input");
              return(size);
         static char[] ReadInput(int size)
              char input;
              char[] letter = new char[size];
              for(int start = 1; start <= size; start++)
                   System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                   input = Keybd.in.readChar();
                   while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#'))
                        Screen.out.println("Invalid Input");
                        System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                        input = Keybd.in.readChar();
                                    while(input == '#')
                                                 start == size;
                                                 break;
                   for(int i = 0; i < letter.length; i++)
                        letter[i] = input;
              return(letter);
         static int CountA(char[] letter)
              int acount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'a')
                        acount++;
              return(acount);
         static int CountB(char[] letter)
              int bcount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'b')
                        bcount++;
              return(bcount);
         static int CountC(char[] letter)
              int ccount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'c')
                        ccount++;
              return(ccount);
         static int SearchA(char[] letter)
              int ia;
              for(ia = 0; ia < letter.length; ia++)
                   if(letter[ia] == 'a')
                        return(ia);
              return(ia);
         static int SearchB(char[] letter)
              int ib;
              for(ib = 0; ib < letter.length; ib++)
                   if(letter[ib] == 'b')
                        return(ib);
              return(ib);
         static int SearchC(char[] letter)
              int ic;
              for(ic = 0; ic < letter.length; ic++)
                   if(letter[ic] == 'c')
                        return(ic);
              return(ic);
         static void PrintResult(char[] letter, int acount, int bcount, int ccount, int ia, int ib, int ic)
              if(ia <= 1)
                   System.out.println("There are "+acount+" a's found, first appearing at index "+ia);
              else
                   System.out.println("There are no a's found");
              if(ib <= 1)
                   System.out.println("There are "+bcount+" b's found, first appearing at index "+ib);
              else
                   System.out.println("There are no b's found");
              if(ic <= 1)
                   System.out.println("There are "+ccount+" c's found, first appearing at index "+ic);
              else
                   System.out.println("There are no c's found");
              return;
         public static void main(String args[])
              int size;
              char[] letter;
              int acount;
              int bcount;
              int ccount;
              int ia;
              int ib;
              int ic;
              size = GetSize();
              letter = ReadInput(size);
              acount = CountA(letter);
              bcount = CountB(letter);
              ccount = CountC(letter);
              ia = SearchA(letter);
              ib = SearchB(letter);
              ic = SearchC(letter);
              PrintResult(letter, acount, bcount, ccount, ia, ib, ic);
              return;
    }     Some errors i get with my program are:
    When reading in the letters to store into the array, I get the last letter I entered placed into the entire array. Also I believe my code to find the Index is incorrect.
    Example Testing: How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): b
    Enter letter (a, b or c) (# to quit): c
    It prints "There are no a's'" (there should be 1 a at index 0)
    "There are no b's" (there should be 1 b at index 1)
    and "There are 3 c's, first appearing at index 0" ( there should be 1 c at index 2)
    The last thing is that my code for when the user enters "#" that the input of letters would stop and the program would then continue over to the counting and searching part for the letters, my I believe is correct but I get the same problem as stated above where the program takes the character "#" and stores it into the entire array.
    Example Testing:How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): #
    It prints "There are no a's'" (should have been 1 a at index 0)
    "There are no b's"
    and "There are no c's"
    Can someone please help me??? or does anyone have a program simular to this they have done and would'nt mind showing me how it works?
    Thanks
    lou87.

    Without thinking too much...something like this
    for(int start = 0; start < size; start++) {
                System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                input = Keybd.in.readChar();
                while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#')) {
                    Screen.out.println("Invalid Input");
                    System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                    input = Keybd.in.readChar();
                if(input == '#') {
                        break;
                letter[start] = input;
            }you dont even need to do start = size; coz with the break you go out of the for loop.

  • Need help with an array

    I'm working on creating an array that is basically a deck of cards, this is the problem.
    I'm getting this error:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
      void main()
        final int ARRAY_SIZE = 52;
        String[] deck = new String[ARRAY_SIZE];
        String[] cardValue = new String[]{"A","2","3","4","5","6","7","8","9","T","J","Q","K"};
        String[] cardSuit = new String[]{"C","H","D","S"};
        for (int count = 0; count < ARRAY_SIZE; count++)
          deck[count]= cardValue[count] + cardSuit[count];
        }I Know that this is because cardSuit is reaching the end of the array, but how do I keep this from happening and make it start from the beginning until i reach the end of the cardValue array?

    By the way thanks for the help guys, I'm in a pinch for this assignment and I appreciate all of the help.
      void main()
        final int ARRAY_SIZE = 52;
        String[] deck = new String[ARRAY_SIZE];
        String[] cardValue = new String[]{"A","2","3","4","5","6","7","8","9","T","J","Q","K"};
        String[] cardSuit = new String[]{"C","H","D","S"};
        for (int count = 0; count < ARRAY_SIZE; count++)
          deck[count]= cardValue[count % 13] + cardSuit[count % 4];
          showCards(deck);
      void showCards(String [] list)
        String cards = ("card");
        for (int count = 0; count < list.length; count++)
          print (cards);
      This is what I'm talking about. I need to be able to call the showCards method and have it display whatever cards are currently in the players hand regardless of how many cards there are. I believe that I'm right when I used the void declaration because I don't want it the method to return anything to itself.
    Right now with the code as is, i get "card" typed out 52 times.
    First how do I go about having it print out the complete deck and the order that they are in?
    Is there a way to create the deck in pre-sorted like I have below?
    This was the assignment:
    Write a ConsoleProgram to create a deck of playing cards, shuffle them, and deal out 5 cards to the player. To do this:
    � You will need an array of 52 cards. In the basic version of this program, each card is a string in the form �XY�, where X is the rank (A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A) and Y is a letter designating the suite (C, H, D, S).
    � You will need to shuffle the cards by swapping the positions of two randomly selected cards in the array. For this, you should write and use three methods:
    o randRange � a method which takes 2 parameters: a minimum integer and a maximum integer. It creates a random integer in this range and returns it.
    o swap � a method which takes 3 parameters: an array of cards and two subscripts. It swaps the array elements with the given subscripts and returns nothing in its name.
    o shuffle � a method which takes 2 parameters: an array of cards and a number of times to swap cards. It shuffles by swapping two randomly selected cards the desired number of times (a possibly different pair each time). It returns nothing in its name (so it is a void method).
    � You will need an array of 5 cards for the player�s hand. After shuffling the deck, you will fill this array with the first 5 cards from the deck.
    � Display the unshuffled deck, then the shuffled deck, and finally the player�s hand. Indicate which is which in the output. For example, the output of one program run might look like this: Unshuffled: 2C, 3C, 4C, 5C, 6C, 7C, 8C, 9C, TC, JC, QC, KC, AC, 2D, 3D, 4D, 5D, 6D, 7D, 8D, 9D, TD, JD, QD, KD, AD, 2H, 3H, 4H, 5H, 6H, 7H, 8H, 9H, TH, JH, QH, KH, AH, 2S, 3S, 4S, 5S, 6S, 7S, 8S, 9S, TS, JS, QS, KS, AS Shuffled: 2C, QC, 3S, 9C, 9S, 6C, 6H, 3C, QH, 2H, 8C, 9H, AH, 4S, AS, TH, 6D, 3D, 2S, 8S, 5C, TC, 4C, 4D, 7C, AD, 9D, JD, 4H, 5S, KH, 7H, JS, 8D, TD, KC, 3H, 2D, KD, AC, KS, JC, 5H, JH, 8H, 5D, 7S, TS, QD, 7D, 6S, QS Your Hand: 2C, QC, 3S, 9C, 9S

  • Help with my array problem.

    Here I have 3 class. One main class, a class to add passengers and a class to display the seating chart.
    A blank seat represented by a "-" is turned into "x". When that is done it goes back to the main class to ask the user if if another passenger wants to be added, display seating chart or quit.
    The problem I have is if the user wants to add passengers after the first time then the array is set back to all blanks "-". I need help how on how to use the changed array after the first time so I can build onto existing seats that are already full, but initially the array has to be filled with "-". Also this changed array needs to be sent to the SeatingChart class to display the changed seating chart if the user selects that.
    I tried some stuff with tempArray[] but can't figure it out. Any help would be appreciated, thanks.
    Main class
    import java.util.*;
    public class Airline {
      public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int mainOption = 0, passengers = 0;
        String seatingClass;
        Reservation reserveSeat;
        SeatingChart displaySeat = new SeatingChart();
        while (mainOption != 3){
          mainOption = 0;
          // Menu loop
          while (mainOption < 1 || mainOption > 3) {
            System.out.println("Welcome to the Airline. Please choose an option.\n");
            System.out.println(
                "Press 1 to add passengers. \nPress 2 to display the " +
                "seating chart. \nPress 3 to Quit.");
            mainOption = scan.nextInt();
        // if statement when 1 is chosen to add passengers
        if (mainOption == 1) {
          Scanner input = new Scanner(System.in);
          // User chooses first or economy class
          do {
            System.out.println("Type E for economy or F for first class:");
            seatingClass = input.nextLine();
          while (!seatingClass.equalsIgnoreCase("e") &&
                 !seatingClass.equalsIgnoreCase("f"));
          // If statement to get number of passengers for economy class
          if (seatingClass.equalsIgnoreCase("e")) {
            do {
              System.out.println("Enter the numbers of passengers: ");
              passengers = scan.nextInt();
            while (passengers < 1 || passengers > 3);
          // If statment to get number of passengers for first class
          if (seatingClass.equalsIgnoreCase("f")) {
            do {
              System.out.println("Enter the numbers of passengers: ");
              passengers = scan.nextInt();
            while (passengers < 1 || passengers > 2);
          // Passes info to Reservation class
          reserveSeat = new Reservation(seatingClass, passengers);
          // Prints out seating chart
          System.out.println(reserveSeat);
        // if statement when 2 is chosen to display seating chart
        if (mainOption == 2) {
          System.out.println(displaySeat);
        // if statement when 3 is chosen to quit
        if (mainOption == 3) {
          System.exit(0);
    }  reservation class for adding passengers.
    [codepublic class Reservation {
      private String seatClass;
      private int numPassengers;
      // First class has 8 seats (2 rows of 4 seats each)
      String[] firstClassSeat = new String[8];
    // Economy class has 24 seats (4 rows of 6 seats each)
    String[] economyClassSeat = new String[18];
    // Temp array for first class
    String[] tempArrayF = new String[8];
    // Temp array for economy class
    String[] tempArrayE = new String[18];
    public Reservation(){
    for (int i = 0; i < firstClassSeat.length; i++)
    firstClassSeat[i] = "-";
    for (int i = 0; i < economyClassSeat.length; i++)
    economyClassSeat[i] = "-";
    public Reservation(String c, int p) {
    seatClass = c;
    numPassengers = p;
    for (int i = 0; i < firstClassSeat.length; i++)
    firstClassSeat[i] = "-";
    for (int i = 0; i < economyClassSeat.length; i++)
    economyClassSeat[i] = "-";
    for (int i = 0; i < tempArrayF.length; i++){
    tempArrayF[i] = firstClassSeat;
    for (int i = 0; i < tempArrayE.length; i++){
    tempArrayE[i] = economyClassSeat[i];
    // First class statements
    if (seatClass.equalsIgnoreCase("f")) {
    if (numPassengers == 1){
    int countF = 0;
    for (int i = 0; i < firstClassSeat.length; i++){
    if (countF < 1){
    // If seat is blank - then fill seat with x
    if (firstClassSeat[i] == "-"){
    firstClassSeat[i] = "x";
    countF++;
    // Economy class statements
    if (seatClass.equalsIgnoreCase("e")) {
    if (numPassengers == 1){
    int countE = 0;
    for (int i = 0; i < economyClassSeat.length; i++) {
    if (countE < 1){
    // If seat is blank - then with seat with x
    if (economyClassSeat[i] == "-"){
    economyClassSeat[i] = "x";
    countE++;
    for (int i = 0; i < tempArrayF.length; i++){
    tempArrayF[i] = firstClassSeat[i];
    for (int i = 0; i < tempArrayE.length; i++){
    tempArrayE[i] = economyClassSeat[i];
    Getter Methods
    public String getSeatingClass() {
    return seatClass;
    public int getNumPassengers() {
    return numPassengers;
    public String[] getFirstClassSeat(){
    return firstClassSeat;
    public String[] getEconomyClassCeat(){
    return economyClassSeat;
    public String toString(){
    int f = 0, e = 0, count1;
    String text = "";
    while (f < 8) {
    if (f == 0 || f == 4 || f == 2 || f == 6) {
    text += firstClassSeat[f];
    f++;
    if (f == 1 || f == 5) {
    text += firstClassSeat[f] + "\t";
    f++;
    if (f == 3 || f == 7) {
    text += firstClassSeat[f] + "\n";
    f++;
    while (e < 18) {
    if (e == 0 || e == 1 || e == 3 || e == 4 || e == 6 || e == 7 ||
    e == 9 || e == 10 || e == 12 || e == 13 || e == 15 || e == 16) {
    text += economyClassSeat[e];
    e++;
    if (e == 2 || e == 8 || e == 14) {
    text += economyClassSeat[e] + "\t";
    e++;
    if (e == 5 || e == 11 || e == 17) {
    text += economyClassSeat[e] + "\n";
    e++;
    return text;
    Display Seating chart class
    public class SeatingChart extends Reservation{
      String seatClass;
      int numPassengers;
      // First class has 8 seats (2 rows of 4 seats each)
      String[] firstClassDisplay = new String[8];
      // Economy class has 24 seats (4 rows of 6 seats each)
      String[] economyClassDisplay = new String[24];
      public SeatingChart(){
      public SeatingChart(String[] f, String[] e) {
        firstClassDisplay = f;
        economyClassDisplay = e;
                   Getter Methods
      public String[] getFirstClassDisplay(){
        return firstClassDisplay;
      public String[] getEconomyClassDisplay(){
        return economyClassDisplay;

    Then how do I pass the information and keep the same object and not let it get set skip over the initialation part in Class Reservation so it doesn't go back too "-".
    Heres some updated since we can't edit. But it still doesn't work.
    Main Airline class
    import java.util.*;
    public class Airline {
      public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int mainOption = 0, passengers = 0;
        String seatingClass;
        Reservation reserveSeat;
        SeatingChart displaySeat = new SeatingChart();
        while (mainOption != 3){
          mainOption = 0;
          // Menu loop
          while (mainOption < 1 || mainOption > 3) {
            System.out.println("Welcome to the Airline. Please choose an option.\n");
            System.out.println(
                "Press 1 to add passengers. \nPress 2 to display the " +
                "seating chart. \nPress 3 to Quit.");
            mainOption = scan.nextInt();
        // if statement when 1 is chosen to add passengers
        if (mainOption == 1) {
          Scanner input = new Scanner(System.in);
          // User chooses first or economy class
          do {
            System.out.println("Type E for economy or F for first class:");
            seatingClass = input.nextLine();
          while (!seatingClass.equalsIgnoreCase("e") &&
                 !seatingClass.equalsIgnoreCase("f"));
          // If statement to get number of passengers for economy class
          if (seatingClass.equalsIgnoreCase("e")) {
            do {
              System.out.println("Enter the numbers of passengers: ");
              passengers = scan.nextInt();
            while (passengers < 1 || passengers > 3);
          // If statment to get number of passengers for first class
          if (seatingClass.equalsIgnoreCase("f")) {
            do {
              System.out.println("Enter the numbers of passengers: ");
              passengers = scan.nextInt();
            while (passengers < 1 || passengers > 2);
          // Passes info to Reservation class
          reserveSeat = new Reservation(seatingClass, passengers);
          // Prints out seating chart
          System.out.println(reserveSeat);
        // if statement when 2 is chosen to display seating chart
        if (mainOption == 2) {
          System.out.println(displaySeat);
        // if statement when 3 is chosen to quit
        if (mainOption == 3) {
          System.exit(0);
    }Reservation class
    public class Reservation extends Airline{
      private String seatClass;
      private int numPassengers, count;
      // First class has 8 seats (2 rows of 4 seats each)
      String[] firstClassSeat = new String[8];
      // Economy class has 24 seats (4 rows of 6 seats each)
      String[] economyClassSeat = new String[18];
      // Temp array for first class
      String[] tempArrayF = new String[8];
      // Temp array for economy class
      String[] tempArrayE = new String[18];
      public Reservation(){
        for (int i = 0; i < firstClassSeat.length; i++)
          firstClassSeat[i] = "-";
        for (int i = 0; i < economyClassSeat.length; i++)
          economyClassSeat[i] = "-";
      public Reservation(String c, int p) {
        seatClass = c;
        numPassengers = p;
        if (count < 1){
          for (int i = 0; i < firstClassSeat.length; i++)
            firstClassSeat[i] = "-";
          for (int i = 0; i < economyClassSeat.length; i++)
            economyClassSeat[i] = "-";
        if (count > 0){
          for (int i = 0; i < tempArrayF.length; i++) {
            firstClassSeat[i] = tempArrayF;
    for (int i = 0; i < tempArrayE.length; i++) {
    economyClassSeat[i] = tempArrayE[i];
    // First class statements
    if (seatClass.equalsIgnoreCase("f")) {
    if (numPassengers == 1){
    int countF = 0;
    for (int i = 0; i < firstClassSeat.length; i++){
    if (countF < 1){
    // If seat is blank - then fill seat with x
    if (firstClassSeat[i] == "-"){
    firstClassSeat[i] = "x";
    countF++;
    // Economy class statements
    if (seatClass.equalsIgnoreCase("e")) {
    if (numPassengers == 1){
    int countE = 0;
    for (int i = 0; i < economyClassSeat.length; i++) {
    if (countE < 1){
    // If seat is blank - then with seat with x
    if (economyClassSeat[i] == "-"){
    economyClassSeat[i] = "x";
    countE++;
    for (int i = 0; i < tempArrayF.length; i++){
    tempArrayF[i] = firstClassSeat[i];
    for (int i = 0; i < tempArrayE.length; i++){
    tempArrayE[i] = economyClassSeat[i];
    count++;
    Getter Methods
    public String getSeatingClass() {
    return seatClass;
    public int getNumPassengers() {
    return numPassengers;
    public String[] getFirstClassSeat(){
    return firstClassSeat;
    public String[] getEconomyClassCeat(){
    return economyClassSeat;
    public String toString(){
    int f = 0, e = 0, count1;
    String text = "";
    while (f < 8) {
    if (f == 0 || f == 4 || f == 2 || f == 6) {
    text += firstClassSeat[f];
    f++;
    if (f == 1 || f == 5) {
    text += firstClassSeat[f] + "\t";
    f++;
    if (f == 3 || f == 7) {
    text += firstClassSeat[f] + "\n";
    f++;
    while (e < 18) {
    if (e == 0 || e == 1 || e == 3 || e == 4 || e == 6 || e == 7 ||
    e == 9 || e == 10 || e == 12 || e == 13 || e == 15 || e == 16) {
    text += economyClassSeat[e];
    e++;
    if (e == 2 || e == 8 || e == 14) {
    text += economyClassSeat[e] + "\t";
    e++;
    if (e == 5 || e == 11 || e == 17) {
    text += economyClassSeat[e] + "\n";
    e++;
    return text;
    display seat class
    public class SeatingChart extends Reservation{
      String seatClass;
      int numPassengers;
      // First class has 8 seats (2 rows of 4 seats each)
      String[] firstClassDisplay = new String[8];
      // Economy class has 24 seats (4 rows of 6 seats each)
      String[] economyClassDisplay = new String[24];
      public SeatingChart(){
      public SeatingChart(String[] f, String[] e) {
        firstClassDisplay = f;
        economyClassDisplay = e;
                   Getter Methods
      public String[] getFirstClassDisplay(){
        return firstClassDisplay;
      public String[] getEconomyClassDisplay(){
        return economyClassDisplay;

  • Help with 2D array input using a text file

    I'm writing a JAva program using BlueJ, which requires me to read info from a text file and put them into an 2D array. I got this error msg and I couldn't gifure out how to fix it. Please help me. Thanks a lot. The program is due tomorrow, please help.
    Error message:
    NoSuchElementException:
    null(in Java.util.StringTokenizer)
    Here's the program with the line where the problem is highlighted
    import java.io.*;
    import java.util.StringTokenizer;
    public class ***
    // Reads students' test scores from a file and calculate their final grade
    public static void main (String[] args) throws IOException
    String file1 = "C:/Temp/scores.txt";
    int[][] input = new int[25][5];
    StringTokenizer tokenizer;
    String line;
    FileReader fr = new FileReader (file1);
    BufferedReader inFile = new BufferedReader (fr);
    line = inFile.readLine();
    tokenizer = new StringTokenizer (line);
    for (int row = 0; row < 25; row++)
    for (int col = 0; col < 5; col++)
    input[row][col] = Integer.parseInt(tokenizer.nextToken()); --> porblem
    This is what the text file looks like:
    1 74 85 98
    2 97 76 92
    3 87 86 77
    4 73 85 93
    5 99 99 83
    6 82 84 95
    7 78 83 91
    8 84 79 84
    9 83 77 90
    10 75 78 87
    11 98 79 92
    12 70 73 95
    13 69 80 88
    14 81 77 93
    15 86 72 80
    16 70 76 89
    17 71 71 96
    18 97 81 89
    19 82 90 96
    20 95 85 95
    21 91 82 88
    22 72 94 94

    Try this code..(I've tested this code in my machine and it works fine)
              try {
                   FileReader fileReader = new FileReader("Z:\\fileInput.txt");
                   BufferedReader reader = new BufferedReader(fileReader);
                   int[][] fileData = new int[22][4];
                   StringTokenizer tokenizer = null;
                   String line = reader.readLine();
                   int rowCount = 0;
                   while(line != null) {
                        tokenizer = new StringTokenizer(line, " ");
                        int columnCount = 0;
                        while(tokenizer.hasMoreTokens()) {
                             fileData[rowCount][columnCount] = Integer.valueOf(tokenizer.nextToken()).intValue();
                             columnCount++;
                        line = reader.readLine();
                        rowCount++;
                   fileReader.close();
                   System.out.println("Done");
              } catch (FileNotFoundException fnfe) {
                   System.out.println("File not found " + fnfe);
              } catch (IOException ioe) {
                   System.out.println("IO Exception " + ioe);
    The problem with your code is that you should first check whether there are any tokens before doing nextToken().
    -Amit

  • Need help with an array, pls could somebody help8-)

    The problem I am currently having is that I want to display variable myblock down 10 times and then test it for collison,
    I am using the variable I to store the blocks, pls excuse me as I am new to this, If I manally set the variable i to lets say 1 and 2
    and then test for collison it works, but when I use I from the for loop it only detects one object from the array, I think that there is something
    probably simple missing such as an extra variable, as you can see from the code I am trying to use the ' i ' to replace for instance addChild(blockarray[1]);
    I have set it manually to display two blocks in the code below, collison detection works, but when I want to use a loop to display and test the collison
    it only picks up one of the blocks, not sure if this is because variable i is set to 0 in the for loop, any help would be greatly appreciated, this is my first post on here as I'm new to Actionscript, ty for reading8-)
    var thehero:BlueBlock = new BlueBlock;
    thehero.x=20;
    thehero.y=20;
    addChild(thehero);
    var blockarray = new Array()
    for(var i:Number=0;i<10; i++)
    // this is where I setup my blocks
    var myblock:BlueBlock = new BlueBlock;
    blockarray[i]=myblock;
    blockarray[i].x = Math.random()*500;
    blockarray[i].y = Math.random()*400;
    trace(blockarray[i]);
    blockarray.push(myblock);
    //addChild(blockarray[i]);
    addChild(blockarray[1]);
    addChild(blockarray[2]);
    // Check for keyboard events such as the arrow keys been pressed
    stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
    stage.addEventListener(Event.ENTER_FRAME,blockcollision);
    function myKeyDown (e:KeyboardEvent){
    if (e.keyCode == Keyboard.LEFT){
    thehero.x -=5;
    if (e.keyCode == Keyboard.RIGHT){
    thehero.x +=5;
    if (e.keyCode == Keyboard.UP){
    thehero.y -=5;
    if (e.keyCode == Keyboard.DOWN){
    thehero.y +=5;
    function blockcollision(e:Event):void{
    if (thehero.hitTestObject(blockarray[1]))
    trace("Hit");
    if (thehero.hitTestObject(blockarray[2]))
    trace("Hit");

    Thankyou very much Andrej for your quick response, it worked perfectly, I can now carry on with my code, thanks again
    Adriannax

  • I need help with an array

    Can anyone help me with this?
    I keep getting two errors:
    Cannot find symbol method "isEmpty()"
    Cannot find symbol method "readString()"
    import java.util.*;
    import java.text.*;
    import java.io.*;
    import java.net.*;
    import java.lang.*;
    public class LetterCount3_1 {
    public static void main(String[] args) {
    int[] cnt = new int[26];
              InputStreamReader stdin = new InputStreamReader(System.in);
              BufferedReader console = new BufferedReader(stdin);
    Scanner keyboard = new Scanner (System.in);
    while (!stdin.isEmpty()) {
    String s = stdin.readString();
    for (int i = 0; i < 26; i++)
    cnt[i] = 0;
    for (int i = 0; i < s.length(); i++)
    ++cnt[s.charAt(i) - 'a'];
    boolean match = true;
    for (int i = 0; i < 26; i++)
    if (cnt[i] != 0 && cnt[i] != 2) match = false;
    if (match) System.out.println(s);
    }

    Thanks for that but now with this code the only problem I am getting is the isEmpty method.
    import java.util.*;
    import java.text.*;
    import java.io.*;
    import java.util.Scanner;
    public class LetterCount3 {
        public static void main(String[] args) {
            int[] cnt = new int[26];      
              Scanner stdin = new Scanner(System.in);
            while (!stdin.isEmpty()) {
                String s = stdin.nextLine();
                for (int i = 0; i < 26; i++)
                    cnt[i] = 0;
                for (int i = 0; i < s.length(); i++)
                    ++cnt[s.charAt(i) - 'a'];
                boolean match = true;
                for (int i = 0; i < 26; i++)
                    if (cnt[i] != 0 && cnt[i] != 2) match = false;
                if (match) System.out.println(s);
    }

Maybe you are looking for

  • I accidentally changed my settings so another website is opened when I open a new tab; how do I get it back to the default quick links on a new tab?

    The site that is shown is Ask.com, and it changed because when I downloaded iLivid installer I didn't uncheck the boxes that asked me if I wanted to make this change.

  • IISProxy.dll error

    This is the set up we have currently.           Nt 4.0 server with IIS 4.0. I have followed the WebLogic 5.1 documentation           and made the root web executable then mapped the extensions .jsp and .jhtml           to c:\weblogic\iisproxy.dll.   

  • Check Oracle installation 10

    Hi friends, I have a query about the commands to verify the following on Solaris 10 - Compiler installed - All patches installed - Shells Limits - Kernel parameters - Run Level - Free space in the folder / tmp - Check if the VNC Server properly insta

  • F5 Big-IP Plugin

    Has anyone installed the F5 Big-IP plugin for grid control. My question is where abouts did you install the agent. The flash card for our F5 load balancer is only 512mb and does not have a lot of room for an agent.

  • What format to export if using third-party encoder?

    I've read the manual on this but I still don't think I've got a full grasp yet on exporting a reference movie. I wonder if someone can help enlighten me. Does exporting a movie using the Using QuickTime Conversion... option, and then selecting an enc