Recent Forum Posts
From categories:
page 1123...next »

Yes, Landis, looks good…I made a few minor changes below but overall you got it. Btw, your original "for" loop for #3 was fine…I misread it during my first reply. Nice job with the code block!

3:
char s = hand.get(0).getSuit();
for(int i = 1; i < hand.size(); i++)
{
    if(hand.get(i).getSuit() != s)
        return false;
}
return true;

4:
String s = "" + number;
for(int i = 0; i < s.length(); i++)
{
    int num = Integer.valueOf(s.substring(i, i+1));
    if(number % num != 0)
        return false;
}
return true;
Re: Chapter 7&8 Study Session by ptcsptcs, 10 Feb 2010 03:20

So…this is correct?

3:
char s = hand.get(0).getSuit();
for(int i = 1; i < hand.size() - 1; i++)
{
    if(!hand.get(i).getSuit().equals(s))
        return false;
}
return true;

4:
String s = "" + number;
for(int i = 0; i < s.length(); i++)
{
    int num = Integer.valueOf(s.substring(i, i+1));
    if(number % num != 0)
        return false;
}
return true;
Re: Chapter 7&8 Study Session by jlandisjlandis, 10 Feb 2010 02:02

Chen, your answers look good.

Re: Chapter 7&8 Study Session by ptcsptcs, 10 Feb 2010 01:55

Landis, 1 & 2 look good but #3 and #4 have minor issues. See my notes below:

#3 Comments
- The suit is represented as a char instead of a String.
- The for loop is incorrect

#4 Comments
- To convert a number to a String, you should do:

String s = "" + number;

- You cannot use the % operator with a String (which is what s.substring returns). Instead, you must convert the String to an integer then use that with the % operator:

int digit = Integer.valueOf(s.substring(i, i+1));

if(number % digit != 0)
    return false;

To indent, you must use a code block.

Re: Chapter 7&8 Study Session by ptcsptcs, 10 Feb 2010 01:53

1) it will return an array will integers 1,2,3,4,5,5 in that order in the array.
2)int[][] nums = new int[3][3];
int count=1;
for(int x=0; x<3; x++)
{
for(int y=0; y<3; y++)
{
nums[x][y]=count;
count++;
}
}
3)if(hand.get(0).getSuit()==hand.get(1).getSuit()&&hand.get(1).getSuit()==hand.get(2).getSuit()&&hand.get(2).getSuit()==hand.get(3).getSuit()&&hand.get(3).getSuit()==hand.get(4).getSuit())
* return true;
* else
* return false;

Re: Chapter 7&8 Study Session by jjchenjjchen, 10 Feb 2010 01:51

1: 123455

2: int[][] myArray = new int[3][3];
myArray[0][0] = 1;
myArray[0][1] = 2;
myArray[0][2] = 3;
myArray[1][0] = 4;
myArray[1][1] = 5;
myArray[1][2] = 6;
myArray[2][0] = 7;
myArray[2][1] = 8;
myArray[2][2] = 9;

You could also use nested loop, but it didn't say we had to.

3:
String s = hand.get(0).getSuit();
for(int i = 1; i < hand.size(); i++)
{
if(!hand.get(i).getSuit().equals(s))
return false;
}
return true;

4:
String s = number;
for(int i = 0; i < s.length(); i++)
{
if(number % s.substring(i, i+1) != 0)
return false;
}
return true;

Also, it wouldn't let me indent.

Re: Chapter 7&8 Study Session by jlandisjlandis, 10 Feb 2010 01:31

No but you can post your answers here and people can provide feedback for you.

Re: Chapter 7&8 Study Session by ptcsptcs, 10 Feb 2010 01:16

Is there anywhere we can find solutions to these to check answers?

Re: Chapter 7&8 Study Session by jlandisjlandis, 10 Feb 2010 00:53

(1) You can create an ArrayList in the helper class and PASS it to the constructor of another class then set an instance field in that class to the ArrayList passed to it. This is what we did in the HandEvaluator class. For instance, in the helper code you may have:

ArrayList<Card> myHand = new ArrayList<Card>();
//Fill the hand with Cards
HandEvaluator he = new HandEvaluator(myHand); //Pass the ArrayList to the constructor

Then in the HandEvaluator we assign the instance field "hand" to the ArrayList passed in "h":

public class HandEvaluator
{
    private ArrayList<Card> hand;
    . . .

    public HandEvaluator(ArrayList<Card> h)
    {
        hand = h;
        ...
    }

    //other code not shown
}

(2) Coupling and cohesion may be tested in the form of a short answer or multiple choice question but not in a free response question.

Re: Chapter 7&8 Study Session by ptcsptcs, 09 Feb 2010 23:40

2 questions:

if we're initializing an ArrayList in a helper class, how do we make it an instance field and then intialize it in the constructor?

and also how would we use the concepts of coupling and cohesion in free response questions?

Re: Chapter 7&8 Study Session by ndamerandamera, 09 Feb 2010 22:41

In order to create the 2-Dimensional Array, you do the following:

int[][] myArray = new int[3][3];

To set a cell in the array, you can do the following:

myArray[0][1] = 8; //This puts an 8 in row 0, column 1

Here is what the array would look like:

080
000
000

Re: Chapter 7&8 Study Session by ptcsptcs, 09 Feb 2010 22:12

I'm not sure how to do the 2D array…

Re: Chapter 7&8 Study Session by jlandisjlandis, 09 Feb 2010 21:59

- FORMAT: The test will be approximately 5 multiple-choice / short answer questions and 2 free response questions.

1) Assume you have the following code:

ArrayList<Integer> myList = new ArrayList<Integer>();

for(int i=0; i<=5; i++)
{
    myList.add(i);

    if(i != 0)
       myList.set(i-1, myList.get(i-1) + 1);
}

What does myList store after the above code executes?

2) Create a 2-dimensional array of int data types with a size of 3x3 and initialize it with the numbers 1 through 9 in the following fashion:

123
456
789

3) Assume we have Card object from our Video Poker project. Complete the method below:

public boolean isFlush(ArrayList<Card> hand)
{

}

4) A self-divisor is a number that is evenly divisible by all of its digits. For instance, the number 128 is a self-divisor because 128 is evenly divisible by 1, 2, and 8. However, 26 is NOT a self-divisor because it is not evenly divisible by 6. Note that 0 is not considered to be a self-divisor so any number containing a 0 is not a self-divisor. Complete the method below:

public boolean isSelfDivisor(int number)
{

}
Chapter 7&8 Study Session by ptcsptcs, 09 Feb 2010 12:21

Testing thread not functional. Just so everyone knows, the test file in Jake's message does not work correctly. Please do not try to use it to test your project.

Re: Testing
jwhitakerjwhitaker 24 Sep 2009 01:19
in discussion Computer Science / APDS » Testing

Just so anyone who might be using this knows, this test file does not work correctly. I apologize for any misunderstandings.

Re: Testing by jwhitakerjwhitaker, 24 Sep 2009 01:19
Testing
jake elliottjake elliott 23 Sep 2009 16:36
in discussion Computer Science / APDS » Testing

I took it down, since it wasn't working.

Testing by jake elliottjake elliott, 23 Sep 2009 16:36

You can add a background image to a JFrame by placing a JPanel on the frame then adding the following code which overwrites the paintComponent method to draw an image:

jPanel1 = new JPanel()
                {
                    public void paintComponent(Graphics g) {
                        super.paintComponent(g); 

                        try {
                            g.drawImage(ImageIO.read(new File("src/Images/Sunset.jpg")), 0, 0, null);
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }                
                };
Adding a Background Image by mr_ritzmr_ritz, 28 Aug 2009 14:44

Using this algorithm, we build a very good dealer, or a good player AI if time premits. http://www.blackjack-university.com/classroom/cardcounting/ This is just the high level logic, not the implementation, which shouldn't be hard to do. (Bunch of if statements as the game looks at the various visile cards)

Build the dealer AI by mblummblum, 26 Aug 2008 22:58
sclarkesclarke 26 Aug 2008 00:48
in discussion Hidden / Per page discussions » Blackjack Sec1

What did we say we were going to do if a player loses all of his money? Are we going to give him like $20 or something or are we going to accumulate a bunch of users that cannot even play assuming we decide to save the users?

by sclarkesclarke, 26 Aug 2008 00:48

Here's a problem I thought of — should there be an option that allows a player to withdraw himself from the game? Let's say one of the four humans (most likely Samuel) suddenly had to go in the middle of the game… it'd be annoying for the other players to have to play for him for the rest of the game if they wanted to finish it.

One player wants to leave by RichardNiRichardNi, 26 Aug 2008 00:03
page 1123...next »
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License