Lamya
stacks in java
0 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners

i am doing a program that i have to finish it before monday so i only have tomorow to finish it. it about the stacks im designing the role of spider card game. i have to move more than one card together from one column to another i can move one card usinf pop and push method but if its more that one card togther for example if i want to move 6,5 and 4 to put it in another column in the top of 7. i dont know what to use to move them together. this is the method that im having the problem with currently it moves one card to another columna and only if its in the right order and then if the column is empty then it has to add only jack or bigger card. then the part where im have problem with which to move a list of cards together. please i need help urgently..... thank you


* @pre 0<=c<7 (i.e. the index of the source column is within range)
* && 0<=d<7 (i.e. the index of the target column is within range)
* && 0<=i<columns[c].size() (i.e. the index i is within range)
* && the i-th card in the c-th column is face up
*
* @post If the rules permit, the i-th card of the c-th column has
* been moved onto the bottom of the d-th column, (along with any
* cards displayed below it), leaving all other cards where they were.
* If the rules do not permit this move, all cards are left
* where they were before.
*

public void moveCardBetweenColumnsIfPossible(int c, int i, int d){

CardStack stack = new CardStack();

if (columns[d].isEmpty()&& columns[c].peek().getRank()>=Card.JACK){
Card move=columns[c].pop();
columns[d].push(move);
}

if (((!columns[d].isEmpty()&& columns[c].peek().getRank()==columns[d].peek().getRank()-1))&& (!columns[c].peek().getColour().equals(columns[d].peek().getColour())))
{
Card value=columns[c].pop();
columns[d].push(value);


// to move a list of cards together i is the selected card and d is the destination where you want to move the card to and c is the coloumn

for( int I = columns[c].size() - 1 ; I >= i ; I--)
{


Card card = columns[c].peek();
columns[c].pop();

stack.push(card);


while(!stack.isEmpty())


columns[d].push(columns[c].peek());


}
}

}
View Answers









Related Pages:
stacks in java - Java Beginners
stacks in java  i am doing a program that i have to finish it before monday so i only have tomorow to finish it. it about the stacks im designing the role of spider card game. i have to move more than one card together from one
Java Stacks - Java Beginners
Java Stacks  Hello..Help me with this assignment plzz. Programming Assignment: A) Consider the outpatient pharamacy at University Hospital. At the entrance of the pharmacy, the patient gives his prescriptions
Java Convert decimal to binary using Stacks
Java Convert decimal to binary using Stacks In this section, you will learn how to convert decimal into binary using stacks. You all are aware of Stacks. It performs two basic operations push and pop. The push operation adds an element
implementation of stacks using linked lists in c++
implementation of stacks using linked lists in c++  how to implementation of stacks using linked lists in c++   #include<stdio.h> #include<stdlib.h> #include<conio.h> struct node{ int data
Java stack help
Java stack help  How would I use stacks in java to do a calculation like: 4*((3+3)/(5-3
making trees - Java Beginners
making trees   pls i do't know what this yerms mean in terms of java trees and stacks? Inorder traverse Switch statement Doing something to the stack thanks in advance
java programming - Java Beginners
java programming  how can i program the queue and the stacks.   Refer Complete Reference  Hi friend, import java.util....) ; } } ----------------------------------------- Read for more information. http://www.roseinida.net/java/ Thanks
Infix to Prefix - Java Beginners
Infix to Prefix  Hello, I needed help on converting from an infix expression to a prefix expression using stacks.  Hi Friend, Try the following code: import java.io.*; import java.util.*; public class
hashtable - Java Beginners
hashtable  pls what is a hashtable in java and how can we use it to compine queue and stacks. thnks in advance.  Hi , A hash-table...://www.roseindia.net/java/ Thanks. Amardeep
Java Programming: Chapter 11 Index
: Section 1: Recursion Section 2: Linking Objects Section 3: Stacks and Queues
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Java Programming: Section 11.3
Section 11.3 Stacks and Queues A LINKED LIST is a particular..., stacks and queues. Both stacks and queues are often implemented as linked lists... of this section partly as a discussion of stacks and queues and partly as a case
Java Programming, Solution to Programming Exercise
POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... a LinkedList or an ArrayList to store its data. (Stacks and queues were introduced... the right sort of exception for a stack. Arrays use indices; stacks don't. So
Java Programming: Contents
Introduction to Programming Using Java, Fourth Edition Table of Contents...: Polling Loops and Interrupts Section 3: The Java Virtual Machine Section 4...: Names and Things Section 1: The Basic Java Application Section 2: Variables
Prefix / Postfix to Infix
from India and thus, I don't know how to make the program using stacks, pop etc (the teacher required that we do this). We are using Java / Eclipse. Any code
Core Java Interview Question, Interview Question
Core Java Interview Question Page 2   ... a Vector and an ArrayList Answer: Java Vector class is internally synchronized...: What's the difference between a queue and a stack? Answer: Stacks works
Java Convert Infix to Postfix
Java Convert Infix to Postfix In this tutorial, you will learn how to convert expression from infix to postfix. The given code accepts the expression from the user and display its postfix expression by using Stacks. Example
Core Java Interview Question, Interview Question
Core Java Interview Question Page 24  ...(String args[]) method in Java Answer: We need public: The method can... Answer: Serialization means storing a state of a java object by coverting
Java Programming, Chapter 12 Exercises
programming exercises based on material from Chapter 12 of this on-line Java... either a LinkedList or an ArrayList to store its data. (Stacks and queues were... in B. Suppose that A and B are variables of type set in Java
java
java  diff bt core java and java
java
java  what is java
Java Args example
Java programs? I've tried many times, but I am successful only in loading... of concept for the Java Debugger API. The Java Debugger API allows us to actually... and stacks. However, these commands are really beyond the scope of a jdb intro. One
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  how use java method

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.