• Post Reply Bookmark Topic Watch Topic
  • New Topic

java Encapsulation if you can create my stack class  RSS feed

 
sachinda nipun
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Stack{

      //please create this class


}
class Demo{
public static void main(String args[]){
List list=new List(); //Insertion order
list.add(30);
list.add(40);
list.add(50);
list.add(60);
list.add(70);
System.out.println(list); //[30,40,50,60,70]

list.add(2,90); //public void add(int index, int data)
System.out.println(list); //[30,40,90,50,60,70]

list.remove(); //remove last
System.out.println(list); //[30,40,90,50,60]

list.remove(2); //public void remove(int index)
System.out.println(list); //[30,40,50,60]

System.out.println("Size of the list : "+list.size()); //4

list.addFirst(100);
list.addLast(200);
System.out.println(list); //[100,30,40,50,60,200]

list.removeFirst();
System.out.println(list); //[30,40,50,60,200]

list.removeLast();
System.out.println(list); //[30,40,50,60]

list.add(new int[]{1,2,3,4,5});
System.out.println(list); //[30,40,50,60,1,2,3,4,5]

list.add(2,new int[]{11,22,33});
System.out.println(list); //[30,40,11,22,33,50,60,1,2,3,4,5]

list.remove(2,5); //public void remove(int startIndex, int endIndex)
System.out.println(list); //[30,40,50,60,1,2,3,4,5]

list.set(2,555);
System.out.println(list); //[30,40,555,60,1,2,3,4,5]
}
}
 
Tim Cooke
Marshal
Posts: 4040
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and welcome to the Ranch!

It's always best to UseCodeTags when posting code so that it formats correctly and is nice and easy to read. I've copied your code below and added them for you this time. See how much better it looks?

Now, back to your question. I actually don't get what your question is? Are you having trouble with something? If so, explain what you've tried and what specifically you're stuck on. If you're asking us to do your homework for you then you're out of luck, that won't happen here.

What's your question?

sachinda nipun wrote:
 
sachinda nipun
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want fill stack class if you can fill stack class
 
Stefano Carniel
Greenhorn
Posts: 27
Android Java Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Tim Cooke
Marshal
Posts: 4040
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefano's rather humorous contribution is about as close as you're going to get to someone providing you a canned solution to your question. There's plenty of people here that will gladly help you but none will do the work for you. So why don't you have a think about the problem and make an attempt to solve it yourself, after all that's the absolute best way to learn. Once you've had a go, come back if you're stuck, show us what you've got, and tell us specifically what you're stuck on.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sachinda nipun wrote:i want fill stack class if you can fill stack class
Welcome to the Ranch (again).

Tim has already explained that we don't hand out solutions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!