Class Composition with Array's - New to Java

Greetings.
I have the basic foundtion to my program laid and it seems to be doing what i need it to. However in my transaction method I have an "If" statement that is supposed to process a transaction differently based on the type of member. Based on what I have done the program operates fine if I make member type static. I will include the areas of code that refer to the problem of the member type and the error i recieve. Hopefully it will be enough to demonstrate what I am doing wrong.
Outline of the Problem
Create an Array of Users (user) - Working
Create and Array of Accounts containing Beginning balance and Account Number (accountNum) - Working
Set Array owner using last name - Working
Process Transactions - Returning the returning the following error:
Exception in thread "main" java.lang.NullPointerException
     at account.transaction(account.java:90)
     at accountTest.main(accountTest.java:64)
If i set memberType to static It worked earlier. I hope this is enough code and description to help identify the problem. I can include more if you need.
Thank you in advance!
Lava
Class Customer
     private String firstName;
     private String lastName ;
     private String memberType;
     public customer(String first, String last, String member)
          firstName = first;
          lastName = last;
          memberType = member;
     public void setMemberType( String m )
           memberType = m;
     public String getMemberType()
          return memberType;
     }Class Account
     private customer owner;
public void setOwner(customer user)
          owner = user;
     public customer getOwner()
          return owner;
public void transaction(account[] accountNum)
if ( owner.getMemberType().equals("Premier" ));

>
Based on what I have done the program operates fine if I make member type static. >
It has to do with how static fields and instance fields are or are not given default values at runtime. Making the customer member static means that for all instances of the Account class, the customer variable will refer to the same object. For different objects of the Account class, will your customer variable refer to the same object? If so, it should be static and thus a class member. If not, it should be an instance member.

Similar Messages

  • Error with import of new compiled java package

    Hi,
    in order to change some code in the java classes of the packages stored in the VV2-Content, 1.0 of SAP -> http://sap.com/xi/ISU-IDEX-GE/VV2 -> Mapping Objects -> Imported Archive, I exported all packages in this folder, extracted them, decompiled some classes (using jad), in which I would like to change some code, and imported these classes associated with other exported packages in a new project of eclipse. after changing the code and successfully compiling these java classes (with no error), I exported the ".class" from eclipse, replaced the old ".class" in the packages with the newly compiled ones(in a zip file) and at the end imported the changed packages (in zip files) in the folder "Imported Archive". After saving and activating the change, I sent an IDOC from R3 system to the XI system for test. In the monitor of the XI system, there was an error, which is
    "Inkompatible Versionen von Klassen (Linkage Error)" (in English "incompatible versions of classes (linkage error)"). Can anyone tell me, how I can do with this error? Thanks.

    Vishal,
    thanks for your reply. Actually I did change some code in the decompilied class "XEdixml2EdiConverter". I think this class does nothing with mapping(transformation), but it converts the tranformed edixml to final edifact. Can I test it in the repository as you said?
    regards
    Bin

  • Should I be concerned with the recent news about Java on my mac

    Have been hearing all the news about the concerns with Java from Homeland Security and that users should disable from their computers temporarily.  I am by no means a techie, however I see that Mac uses Java applet.  Is this something I should look at temporrily disabling from my Mac?  I wasn't sure how to proceed.  Can some one give some advise and in layman terms.......

    Java is only a potential problem if you have it installed and enabled in your Internet browser. Safari has had it disabled as the default for a while now.
    To check to make sure it is disabled in your browser. Open Safari->Preferences->Security and make sure Enable Java is not checked
    Note: Java and JavaScript are two different languages and are not to be confused. JavaScript is fine to have enabled.
    regards

  • New to Java, new to array(compacting ,removing etc..)

    hey everybody,
    bear with me im new to JAVA, currently taking my first course in Programming, and one of the assignments is on arrays. my question is i need to compact the array so if an element is removed then i would have to shift each one down so it doesnt waste memory and also have the array packed which means i have to keep all valid elements in the beginning and nulls at the end any suggestions or examples?. i didnt write any part of the code yet so im not sure if my description helps...
    BTW any suggestions as to where i can get practice in Java Programming? my hws sorta help but its not enough practice, and this is all new to me so any suggestions either websites or books?

    thanks for the replies and the link, i think i sorta got an idea how to shift
    well the thing with the array is that if the user inputs a number that is the same as an element in the array i need to remove it, well i guess you can say i have a problem starting the code does any one have a simple example on arrays? and im still confused about creating temps also, can anyone explain in what situation do we have to create temp variables? from my understanding is it only when you wanna change the size of the array? thanks in advance

  • Having compiler issues with Array, can anyone help please?

    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 at the bottom, can anyone tell me what I'm doin wrong please
    //Invoice Lab 6
    //Application to test class Invoice with arrays
    public class InvoiceTest
    public static void main( String args[] )
    Invoice invoice1 = new Invoice( "1234", "Hammer", 2, 14.95 );
    Invoice array [] = new Invoice [2];
    array [0] = new Invoice ("1234", "Hammer", 2, 14.95);
    array [1] = new Invoice ("5678", "PaintBrush", -5, -9.99);
    double total = 0.0;
    System.out.println("Part Number                    Description               Quantity          Price               Amount");
    System.out.println("----------------------------------------------------------------------------------");
    for (int i=0; <=2; i++)
    total+=array.getPaymentAmount();
         system.out.println("The Total retail value is: %.2f\n")
    // 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

    Change this (check my comments):
    for (int i=0; <=2; i++) // what is <=2??  check the fixed version
    total+=array.getPaymentAmount(); //two things 1) this needs to be inside the for-loop 2) you need to tell the array which index to look at
    system.out.println("The Total retail value is: %.2f\n") //no need for \n because println does it automagically
    }to this:
    for(int i=0; i<array.length; i++) {
        total += array.getPaymentAmount();
    System.out.println("The total retail value is: " + total); //if you need another blank line like above be my guest
    Honestly, I didn't look past this part so fix this and post again if something is still broken.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Tutorial & Code Sample for Developping Composites with CAF

    Do you have tutorials & Code samples for developping composites with CAF like Webdypro for Java as on this SDN site:
    https://www.sdn.sap.com/irj/sdn/developerareas/webdynpro?rid=/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d
    Thanls, regards, peter

    Take a look at https://www.sdn.sap.com/irj/sdn/developerareas/xapps?rid=/webcontent/uuid/7b9b3834-0801-0010-6a9a-dc53e0db37f2">the [original link is broken] [original link is broken].
    cheers,
    Marilyn

  • I am completealy new at java.  HELP!!!!

    K, hi, well, i am experienced in HTML and Macromedia Flash, and Game Maker 5, a shit game maker prog. Ne ways, i admire games like RuneScape and would like to know how i would get around to making one. I know that i can't just jut out and make a rs type game. But i would like to know where to start? Are there programs i need to buy or DL, or are there books? And btw, is Java like HTML where u sit in front of a notepad prog, and type? or is it like u type and see whats happening? or do u add objects and give them properties..... Its a whole lot to ask! lol, Help me out.......try to answer it all.

    Resources for Beginners
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java. This one has been getting a lot of very positive comments lately.
    But i would like to know where to start? With reading the "New To Java" tutorials.
    Are there programs i need to buy or DLTo start with you only need Notepad, and the JDK (AKA the Java SDK), downloadable from http://java.sun.com/j2ee/1.4/download-sdk.html
    Later on, you might also want an IDE, or maybe just a better text editor. But for now, just stick with Notepad.
    And btw, is Java like HTML where u sit in front of a notepad prog, and type?Mostly, after writing something (in Notepad), then compile it, then run it. And extra step than HTML has.
    or is it like u type and see whats happening?You can also get interactive shells for it, but for now, do not worry about them.
    r do u add objects and give them propertiesYou can get IDEs which let you work this way, but for now, do not worry about them.

  • New to java, having trouble with classes

    I am new to java and I am having problems importing classes in my first program, please help

    hi
    please tell, what`s your problem exatly?

  • Help with arrays and Exception in thread "main" java.lang.NullPointerExcept

    Hi, I have been having trouble all day getting this array sorted and put into a new array. I think it is something simple with my nested loops in sortCityArray() that is causing the problem. Any help would be greatly appreciated. The error is thrown on line 99 at Highway.sortCityArray(Highway.java:99)
    import java.util.Scanner;
    import java.io.*;
    import java.util.Arrays;
    public class Highway
    private String[] listOfCities=new String[200];
    private City[] cityArray=new City[200];
    private City[] sortedCityArray=new City[200];
    private String city="";
    private String city2="";
    private String fileName;
    private City x;
    private int milesToNextCity;
    private int milesAroundNextCity;
    private int speedToNextCity;
    public Highway(String filename)
    String fileName=filename;//"I-40cities.txt";
           File myFile = new File(fileName);
           try {
           Scanner scan=new Scanner(myFile);
           for(int i=0; scan.hasNextLine(); i++){
           String city=scan.nextLine();
           String city2=scan.nextLine();
           int milesToNextCity=scan.nextInt();
           int milesAroundNextCity=scan.nextInt();
           int speedToNextCity=scan.nextInt();
                   if(scan.hasNextLine()){
              scan.nextLine();
           cityArray=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
    // System.out.println(cityArray[i].getCity());
    // System.out.println(cityArray[i].getNextCity());
    // System.out.println(cityArray[i].getLengthAB());
    // System.out.println(cityArray[i].getLengthAroundB());
    // System.out.println(cityArray[i].getSpeedAB());
    catch (Exception e) {
    System.out.println(e);
    //return cityArray;
    /*public City[] doCityArray(){
    File myFile = new File(fileName);
    try {
    Scanner scan=new Scanner(myFile);
    for(int i=0; scan.hasNextLine(); i++){
    String city=scan.nextLine();
    String city2=scan.nextLine();
    int milesToNextCity=scan.nextInt();
    int milesAroundNextCity=scan.nextInt();
    int speedToNextCity=scan.nextInt();
         if(scan.hasNextLine()){
              scan.nextLine();
    cityArray[i]=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
    // System.out.println(cityArray[i].getCity());
    // System.out.println(cityArray[i].getNextCity());
    // System.out.println(cityArray[i].getLengthAB());
    // System.out.println(cityArray[i].getLengthAroundB());
    // System.out.println(cityArray[i].getSpeedAB());
    catch (Exception e) {
    System.out.println(e);
    return cityArray;
    public City[] sortCityArray(){
    sortedCityArray[0]=new City(cityArray[0].getCity(),cityArray[0].getNextCity(),cityArray[0].getLengthAB(),cityArray[0].getLengthAroundB(),cityArray[0].getSpeedAB());
    for(int j=0; j<cityArray.length; j++ )
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
              break;
    /*     for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
    //     j++;
    System.out.println(sortedCityArray[0].getCity());
    System.out.println(sortedCityArray[0].getNextCity());
    System.out.println(sortedCityArray[0].getLengthAB());
    System.out.println(sortedCityArray[0].getLengthAroundB());
    System.out.println(sortedCityArray[0].getSpeedAB());
    System.out.println(sortedCityArray[1].getCity());
    System.out.println(sortedCityArray[1].getNextCity());
    System.out.println(sortedCityArray[1].getLengthAB());
    System.out.println(sortedCityArray[1].getLengthAroundB());
    System.out.println(sortedCityArray[1].getSpeedAB());
    System.out.println(sortedCityArray[2].getCity());
    System.out.println(sortedCityArray[2].getNextCity());
    System.out.println(sortedCityArray[2].getLengthAB());
    System.out.println(sortedCityArray[2].getLengthAroundB());
    System.out.println(sortedCityArray[2].getSpeedAB());
    System.out.println(sortedCityArray[3].getCity());
    System.out.println(sortedCityArray[3].getNextCity());
    System.out.println(sortedCityArray[3].getLengthAB());
    System.out.println(sortedCityArray[3].getLengthAroundB());
    System.out.println(sortedCityArray[3].getSpeedAB());
    System.out.println(sortedCityArray[4].getCity());
    System.out.println(sortedCityArray[4].getNextCity());
    System.out.println(sortedCityArray[4].getLengthAB());
    System.out.println(sortedCityArray[4].getLengthAroundB());
    System.out.println(sortedCityArray[4].getSpeedAB());
    return cityArray;
    /*public String[] listOfCities(){
    File myFile = new File("I-40cities.txt");
    try {
    Scanner scan=new Scanner(myFile);
    for(int i=0; scan.hasNextLine(); i++){
         String city=scan.nextLine();
         city=city.trim();
    scan.nextLine();
    scan.nextLine();
         listOfCities[i]=city;
         System.out.println(listOfCities[i]);
    catch (Exception e) {
    System.out.println(e);
    return listOfCities;
    public static void main(String args[]) {
    Highway h = new Highway("out-of-order.txt");
    h.sortCityArray();

    the ouput is perfect according to the print lines if I use (increase the int where j is in the loop manually by one) :
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[0].getNextCity().equals(cityArray.getCity())){
              sortedCityArray[0+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
              break;
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[1].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[1+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[2].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[2+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[3].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[3+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
    But I cant do this for 200 elements. Are the loops nested right?
    Edited by: modplan on Sep 22, 2008 6:49 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • New to Java and need help with this program..please!

    I'd really appreciate any helpful comments about this program assignment that I have to turn in a week from Friday. I'm taking a class one night a week and completely new to Java. I'd ask my professor for help, but we can't call him during the week and he never answers e-mails. He didn't tell us how to call from other classes yet, and I just can't get the darn thing to do what I want it to do!
    The assignment requirements are:
    1. Change a card game application that draws two cards
    and the higher card wins, to a Blackjack application
    2. Include a new class called Hand
    3. The Hand class should record the number of draws
    4. The application should prompt for a number of draws
    5. The game is played against the Dealer
    6. The dealer always draws a card if the dealer's hand total is <= 17
    7. Prompt the player after each hand if he wants to quit
    8. Display the total games won by the dealer and total and the total games wond by the player after each hand
    9. Display all of the dealer's and player's cards at the
    end of each hand
    10. Player has the option of drawing an additional card after the first two cards
    11. The Ace can have a value of 11 or 1
    (Even though it's not called for in the requirements, I would like to be able to let the Ace have a value of 1 or an 11)
    The following is my code with some comments about a few things that are driving me nuts:
    import java.util.*;
    import javax.swing.*;
    import java.text.*;
    public class CardDeck
    public CardDeck()
    deck = new Card[52];
    fill();
    shuffle();
    public void fill()
    int i;
    int j;
    for (i = 1; i <= 13; i++)
    for (j = 1; j <= 4; j++)
    deck[4 * (i - 1) + j - 1] = new Card(i, j);
    cards = 52;
    public void shuffle()
    int next;
    for (next = 0; next < cards - 1; next++)
    int rand = (int)(Math.random()*(next+1));
    Card temp = deck[next];
    deck[next] = deck[rand];
    deck[rand] = temp;
    public final Card draw()
    if (cards == 0)
    return null;
    cards--;
    return deck[cards];
    public int changeValue()
    int val = 0;
    boolean ace = false;
    int cds;
    for (int i = 0; i < cards; i++)
    if (cardValue > 10)
    cardValue = 10;
    if (cardValue ==1)     {
    ace = true;
    val = val + cardValue;
    if ( ace = true && val + 10 <= 21 )
    val = val + 10;
    return val;
    public static void main(String[] args)
    CardDeck d = new CardDeck();
    int x = 3;
    int i;
    int wins = 1;
    int playerTotal = 1;
    do {
    Card dealer = (d.draw());
    /**I've tried everything I can think of to call the ChangeValue() method after I draw the card, but nothing is working for me.**/
    System.out.println("Dealer draws: " + dealer);
    do {
    dealer = (d.draw());
    System.out.println(" " + dealer);
    }while (dealer.rank() <= 17);
    Card mine = d.draw();
    System.out.println("\t\t\t\t Player draws: "
    + mine);
    mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
    do{
    String input = JOptionPane.showInputDialog
    ("Would you like a card? ");
    if(input.equalsIgnoreCase("yes"))
         mine = d.draw();
    System.out.println("\t\t\t\t\t\t" + mine);
         playerTotal++;
         else if(input.equalsIgnoreCase("no"))
    System.out.println("\t\t\t\t Player stands");
         else
    System.out.println("\t\tInvalid input.
    Please try again.");
    I don't know how to go about making and calling a method or class that will combine the total cards delt to the player and the total cards delt to the dealer. The rank() method only seems to give me the last cards drawn to compare with when I try to do the tests.**/
    if ((dealer.rank() > mine.rank())
    && (dealer.rank() <= 21)
    || (mine.rank() > 21)
    && (dealer.rank() < 22)
    || ((dealer.rank() == 21)
    && (mine.rank() == 21))
    || ((mine.rank() > 21)
    && (dealer.rank() <= 21)))
    System.out.println("Dealer wins");
    wins++;
         else
    System.out.println("I win!");
    break;
    } while (playerTotal <= 1);
    String stop = JOptionPane.showInputDialog
    ("Would you like to play again? ");
    if (stop.equalsIgnoreCase("no"))
    break;
    if (rounds == 5)
    System.out.println("Player wins " +
    (CardDeck.rounds - wins) + "rounds");
    } while (rounds <= 5);
    private Card[] deck;
    private int cards;
    public static int rounds = 1;
    public int cardValue;
    /**When I try to compile this nested class, I get an error message saying I need a brace here and at the end of the program. I don't know if any of this code would work because I've tried adding braces and still can't compile it.**/
    class Hand()
    static int r = 1;
    public Hand() { CardDeck.rounds = r; }
    public int getRounds() { return r++; }
    final class Card
    public static final int ACE = 1;
    public static final int JACK = 11;
    public static final int QUEEN = 12;
    public static final int KING = 13;
    public static final int CLUBS = 1;
    public static final int DIAMONDS = 2;
    public static final int HEARTS = 3;
    public static final int SPADES = 4;
    public Card(int v, int s)
    value = v;
    suit = s;
    public int getValue() { return value; }
    public int getSuit() { return suit;  }
    public int rank()
    if (value == 1)
    return 4 * 13 + suit;
    else
    return 4 * (value - 1) + suit;
    /**This works, but I'm confused. How is this method called? Does it call itself?**/
    public String toString()
    String v;
    String s;
    if (value == ACE)
    v = "Ace";
    else if (value == JACK)
    v = "Jack";
    else if (value == QUEEN)
    v = "Queen";
    else if (value == KING)
    v = "King";
    else
    v = String.valueOf(value);
    if (suit == DIAMONDS)
    s = "Diamonds";
    else if (suit == HEARTS)
    s = "Hearts";
    else if (suit == SPADES)
    s = "Spades";
    else
    s = "Clubs";
    return v + " of " + s;
    private int value; //Value is an integer, so how can a
    private int suit; //string be assigned to an integer?
    }

    Thank you so much for offering to help me with this Jamie! When I tried to call change value using:
    Card dealer = (d.changeValue());
    I get an error message saying:
    Incompatible types found: int
    required: Card
    I had my weekly class last night and the professor cleared up a few things for me, but I've not had time to make all of the necessary changes. I did find out how toString worked, so that's one question out of the way, and he gave us a lot of information for adding another class to generate random numbers.
    Again, thank you so much. I really want to learn this but I'm feeling so stupid right now. Any help you can give me about the above error message would be appreciated.

  • Class with objects compile error in Java 1.5.0 and 1.4.2.05

    Hi, I have some problems with creating objects to my java program.
    See below:
    JAVA, creating new class object.
    class AccountTest {
         public static void main(String[]args) {
         Account olesAccount = new Account(123456676756L, "Ole Olsen", 2300.50);
         olesAccount.deposit(1000.0); //Input of 1000$ to account
         double balance = olesAccount.findBalance(); //Ask object about balance!
         System.out.println("Balance: " +balance);
    ERRORS, from compiler (javac):
    AccountTest.java:7: cannot find symbol
    symbol : class Account
    location: class AccountTest
    Account olesAccount = new Account(123456676756L, "Ole Olsen", 2300.50);
    ^
    AccountTest.java:7: cannot find symbol
    symbol : class Account
    location: class AccountTest
    Account olesAccount = new Account(123456676756L, "Ole Olsen", 2300.50);
    ^
    2 errors
    This error occurs with both java 1.5.0 RC and 1.4.2.05
    */

    Assuming you haven't forgotten to compile the Account class, tt seems to be a problem with visibility. Are you sure your classpath is set up correctly and that the class Account is visible to the AccountTest driver?
    I'd try moving the Account out of whatever package it's in right now and making it public. Then, restrict acces from there.

  • Pretty new to Java can someone please help with an addObject() problem?

    Hi I'm pretty knew to programming and I have an assignment which I've been working on but I am stuck
    I have to create a 'space invaders' style game, and I've got some basics working. I wanted to add a boss enemy, which appears when all other enemies have been destroyed. It kind of works, only the program spawns a seemingly infinite amount of the boss which then creates a 'wipe' effect across the top of the screen.
    Here is my code:
    import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
    import java.util.List;
    public class Space extends World
    * Constructor for objects of class Space.
    public Space()
    // Create a new world with 200x250 cells with a cell size of 3x3 pixels.
    super(200, 250, 3);
    //add class with starstreaks
    addObject(new EmptyBox(),1,1);
    //add player character
    addObject(new Player(), 100, 228);
    //add 4 romulan enemies row 1
    for(int i=0; i<4; i++){
    addObject(new Romulan(), (25 + 50 * i), 15);
    //add 3 klingon enemies row 2
    for(int i=0; i<3; i++){
    addObject(new Klingon(), (50 + 50 * i), 40);
    //add 4 romulan enemies row 3
    for(int i=0; i<4; i++){
    addObject(new Romulan(), (25 + 50 * i), 65);
    //add 3 klingon enemies row 4
    for(int i=0; i<3; i++){
    addObject(new Klingon(), (50 + 50 * i), 90);
    //add 3 shields
    for(int i=0; i<3; i++){
    addObject(new Shield(), (30 + 70 * i), 180);
    *public void act(){*
    List<Enemy> enemies = getObjects(Enemy.class);
    *if(enemies.size()==0 ){*
    addObject(new Borg(), 100, 30 );
    I believe the part in bold is the problem, but I dont know why. Klingon and Romulan are subclasses of the Enemy class. The Borg class is it's own seperate class, but with the exact same functions as Enemy. I made it seperate as I figured it would keep respawning if it was a subclass of Enemy.
    Any ideas?

    Its ok, after more than an hour I've got it.
    I simply added private int bossValue = 0; at the beginning and then changed act to this:
    public void act(){
    List<Enemy> enemies = getObjects(Enemy.class);
    if(enemies.size()==0 && bossValue==0 ){
    //for(int i=0; i<1; i++){
    addObject(new Borg(), 100, 30 );
    bossValue =1;
    }

  • 11G: Error invoking adf-binding service in composite with JAVA API

    Hello,
    i'm trying to invoke a asyncrhonous composite via JAVA API. My composite has two services: WS and ADF-BC SERVICE both of two are wired with a MEDIATOR that connects with two BPEL Process depending on two rules.
    I need to invoke a process depending of the input: if the input is A i invoke the process 1 and if the input is B I invoke the process 2. I use the Mediator instead of switch because it's an example in order to build a complex decission system then.
    R1 and R2 are two static rules in the Mediator.
    R1 = $in.payload/client:process/client:tiposiniestro = 'A'
    R2 = $in.payload/client:process/client:tiposiniestro = 'B'
    And my XSD is:
    <schema attributeFormDefault="unqualified"
         elementFormDefault="qualified"
         targetNamespace="http://xmlns.oracle.com/POC_jws/ProcesoApertura/ProcesoApertura"
         xmlns="http://www.w3.org/2001/XMLSchema">
    <element name="process">
              <complexType>
                   <sequence>
                        <element name="tiposiniestro" type="string"/>
                   </sequence>
              </complexType>
         </element>
         <element name="processResponse">
              <complexType>
                   <sequence>
                        <element name="result" type="string"/>
                   </sequence>
              </complexType>
         </element>
    </schema>
    If i invoke with SOAP, sending the message:
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
         <soap:Body xmlns:ns1="http://xmlns.oracle.com/POC_jws/ProcesoApertura/ProcesoApertura">
              <ns1:process>
                   <ns1:tiposiniestro>A</ns1:tiposiniestro>
    </ns1:process>
    </soap:Body>
    </soap:Envelope>
    the composite works. But if i try to invoke with JAVA, with the code:
    String payload5 = "<process xmlns=\"http://xmlns.oracle.com/POC_jws/ProcesoApertura/ProcesoApertura\">" +
         "     <tiposiniestro>A</tiposiniestro>" +
         "</process>";
    String conversationId = UUID.randomUUID().toString();
    NormalizedMessage nm = new NormalizedMessageImpl();
    nm.addProperty(NormalizedMessage.PROPERTY_CONVERSATION_ID, conversationId);
    Map<String,Object> payload = nm.getPayload();
    payload.put("payload", pPayLoad);
    nm.setPayload(payload);
    service.post(pOperation, nm);
    i get the following error:
    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.w3c.dom.Element
    How can I send the message via JAVA API using the mediator in my composite?
    Is there any important difference in the format between send a request with SOAP or JAVA?
    Thanks in advance.
    Edited by: user7239022 on 05-ene-2010 7:38
    Edited by: user7239022 on 05-ene-2010 7:40
    Edited by: user7239022 on 05-ene-2010 7:49
    Edited by: user7239022 on 05-ene-2010 8:41

    Talking about the dynamic rules in the Mediator, Oracle documentation says:
    "As of now, only SOAP bindings are supported. There is a dummy SOAP binding in the composite.xml file. This endpoint is overridden by Mediator in runtime through NM property. So, outbound services can be called only over SOAP."
    Is it valid for static rules as well? I means, how can i use Java API to invoke a Composite with a Mediator as first element? I always get the message:
    +"java.lang.ClassCastException: java.lang.String cannot be cast to org.w3c.dom.Element"+
    Thanks again

  • Trying to teach self Java-question with arrays

    I have a question with arrays. I have a simple inventory program that I am writing(very simple). I have declared and created my array. Is this the time I should build a new class outside of my main in order to hold my array? I am still trying to sort through classes and when to create them. My thought is that because it is a hierarchy I should have a new class. For example, Albums is at the top and then there are specific types of albums, like TributeAlbum, PremiereAlbum, etc. Do I need a class for each of these? When I create the class, do I use the same name as the array?
    More info, just in case: My original class is AlbumInventory. I have created an array to hold 25 TributeAlbums which has 4 instance variables.
    Question 2: Why can I not refer to an album variable like TributeAlbums[0].itemNumber?
    Thanks in advance for your input.
    Denise

    I have a question with arrays. Okay.
    I have a simple
    inventory program that I am writing(very simple). I
    have declared and created my array. Is this the time
    I should build a new class outside of my main in
    order to hold my array? In an OO language classes are usually a good idea.
    I am still trying to sort
    through classes and when to create them. My thought
    is that because it is a hierarchy I should have a new
    class.This sounds a bit confused. You should have a new class when it is appropriate to do so.
    For example, Albums is at the top and then
    there are specific types of albums, like
    TributeAlbum, PremiereAlbum, etc. Do I need a class
    for each of these? Not sure. Why is the type not an attribute of the Album class? This (attribute) seems at first glance to be the way to do it.
    When I create the class, do I use
    the same name as the array?
    ? I am going to say no but I'm not following what you are really asking here.
    More info, just in case: My original class is
    AlbumInventory. I have created an array to hold 25
    TributeAlbums which has 4 instance variables.
    Can you please post some of your actual formatted code? It would also be helpful to know what the attributes for an Album are as you have them.

  • Java class integration with Oracle Identity Manager 9.1.0.2

    Hello Friends,
    I have a java class that is responsible for sending notifications, my question is how do the relationship of this class with the Oracle Identity Manager 9.1.0.2 so you can take the class and notify users when an application is approved or rejected.
    Any recommendation for this process.
    Thanks for the support
    Edited by: JLK on Jun 12, 2012 5:20 PM

    Hi
    Java class integration with OIM happen through concept of adapters. You can go through OIM documentation of how to create adapters.
    In your case you should create a process task adapetrs adn attach it on the Approved response code in your approval process.
    Desingn Console --> Process management --> Process definition --> <Apprlication Process Ex: AD User>.
    Alternatively you can also send notification using OIM OOTB email templates.
    Regards
    user12841694

Maybe you are looking for

  • How to deploy a secured ADF 11g application to WebLogic 10.3 server?

    Hi, I have just enabled security in our ADF 11g application, as descripbed in [chapter 29|http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/adding_security.htm#insertedID0] of the Fusion Developer's Guide. It works fine in the embedded Web

  • How to override the create method invoked by a create form?

    Hello everyone, I'm using ADF Faces and have the next question: How can I override the create method which is invoked by a create form to preset an attribute in the new row (the preset value is not fixed, I have to send it to the method as a paramete

  • PO to SO creation in same client

    Hello Friends!                     Is there any standard configuration by which i can create Purchase order and then against that PO i can create sales order in the same client? i dont want to do it by programs,,,want a standard configuration like ID

  • What does this error message mean?   Bridges Parent application is not active

    I updated my Bridge and now I can't use it because I get this message Bridges Parent application is not active Bridge requires that a qualifying product has been launched at least once to enable this feature

  • Importing albums in iPhoto on MacBook

    My old iBook died but I'd saved my iPhoto library to an external Lacie. I imported the pictures easily enough but the album information didn't come across from the hard drive and the pictures were all in original format (e.g. unrotated, etc) so I wan