Page 1 of 3 123 LastLast
Results 1 to 20 of 41
Like Tree6Likes

Thread: Array data structure or Linked List for Dice

  1. #1
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Post Array data structure or Linked List for Dice

    Hi All Expert need your help on this question.
    What should i answer for the *Fill in your implementation here
    ================================================== ==

    public class DiceArray implements DiceIF{
    public static final int MAX = 5; //default maximum size
    protected int lastItem; //points to the last item of the list
    protected Integer[] arr;
    public DiceArray(){
    //Fill in your implementation here
    }
    public int size() {
    //Fill in your implementation here
    }
    public boolean isEmpty() {
    //Fill in your implementation here
    }
    public Integer remove(int k) {
    //Fill in your implementation here
    }
    public void insert(int k, Integer data) {
    //Fill in your implementation here
    }
    public String toString() {
    //Fill in your implementation here
    }
    }

    public class Node {
    private Integer data;
    private Node next;
    public Node(Integer data){
    this.data = data;
    }
    public Node(Integer data, Node next){
    this.data = data;
    this.next = next;
    }
    public Integer getData() {
    return data;
    }
    public void setData(Integer data) {
    this.data = data;
    }
    public Node getNext() {
    return next;
    }
    public void setNext(Node next) {
    this.next = next;
    }
    }
    public class DiceSList implements DiceIF{
    private Node head;
    private int listsize; //size of the list
    public DiceSList(){
    //Fill in your implementation here
    }
    public int size() {
    //Fill in your implementation here
    }
    public boolean isEmpty() {
    //Fill in your implementation here
    }
    public Integer remove(int k) {
    //Fill in your implementation here
    }
    public void insert(int k, Integer data) {
    //Fill in your implementation here
    }
    public String toString() {
    //Fill in your implementation here
    }
    }

    public interface DiceIF {
    //returns the actual number of data in the list
    public int size();
    //returns true if the list is empty
    public boolean isEmpty();
    //returns the value of the item at position k, then removes it from the list
    public Integer remove(int k);
    //add an item with value "data" at the k-th position of the list
    public void insert(int k, Integer data);
    //traverse and returns all values in the list
    public String toString();
    }
    import java.util.Random;
    public class DiceTester {
    public static void main(String args[]){
    DiceTester tester = new DiceTester();
    //Test with array implementation
    System.out.println("--- Test with array implementation ---");
    tester.run(new DiceArray());
    //Test with list implementation
    System.out.println("\n--- Test with list implementation ---");
    tester.run(new DiceSList());
    }
    public int throwDice(){
    int max=6, min=1;
    Random rand = new Random();
    int randomNum = rand.nextInt((max - min) + 1) + min;
    return randomNum;
    }
    public void run(DiceIF obj){
    for(int i=0; i < 10; i++){
    int num = throwDice();
    System.out.print(num+"\t");
    obj.insert(i, new Integer(num));
    }
    System.out.println("Size: "+obj.size());
    System.out.println("Original list \t\t\t\t Print: "+obj.toString());
    System.out.print("Removes "+obj.remove(5)+"\t");
    System.out.println("Print after executing remove(5): "
    +obj.toString()+"\t\t Size: "
    +obj.size());
    }
    }
    Attached Thumbnails Attached Thumbnails Array data structure or Linked List for Dice-question-java.jpg  

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Array data structure or Linked List for Dice

    Many participants here are a little reluctant to function as a last minute homework service, but I can give you hint for a shortcut: The Java Collections API already has the methods implemented that you have to re-invent. Some might just have slightly different names.
    sharinganxy likes this.

  3. #3
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Please provide me the answer as well
    thanks

  4. #4
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Please provide me the answer as well
    thanks

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Array data structure or Linked List for Dice

    Quote Originally Posted by sharinganxy View Post
    Please provide me the answer as well
    thanks
    That is not how it works overhere, you try to solve your homework and when you're stuck ask questions here, showing your own attempts and we'll try to help you out. But it's you who's got to do the work, not us.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Array data structure or Linked List for Dice

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    this is a serious question.

    Hope you all expert can help answer instead of put bad comments on it

  8. #8
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Hi Norm,

    Pleas help,

    As i know you all are expert here

    Urgent

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Array data structure or Linked List for Dice

    Could you post code that shows what you have tried to do? Be sure to wrap all posted code in code tags.
    And make sure the posted code is properly indented making it easier to read and understand.

    Ask some questions about any specific problems you are having. Where are you having problems? Describe the problems.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Array data structure or Linked List for Dice

    Quote Originally Posted by sharinganxy View Post
    this is a serious question.

    Hope you all expert can help answer instead of put bad comments on it
    You also got serious answers. Benji even helped you on your way to get started. But nobody here is going to do your homework for you. You have to put in that effort yourself.

    So, which part of the exercise did you not understand?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  11. #11
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Hi Norm,

    i need to know what to fill in under the *//Fill in your implementation in the

    i don't know to to declare classes using array





    Java Code:
    public class DiceArray implements DiceIF{
    public static final int MAX = 5; //default maximum size
    protected int lastItem; //points to the last item of the list
    protected Integer[] arr;
    public DiceArray(){
    //Fill in your implementation here
    }
    public int size() {
    //Fill in your implementation here
    }
    public boolean isEmpty() {
    //Fill in your implementation here
    }
    public Integer remove(int k) {
    //Fill in your implementation here
    }
    public void insert(int k, Integer data) {
    //Fill in your implementation here
    }
    public String toString() {
    //Fill in your implementation here
    }
    }

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Array data structure or Linked List for Dice

    You missed my suggestion:
    And make sure the posted code is properly indented making it easier to read and understand.
    The statements in the posted code all start in the first column. Logically nested statements should be indented.
    Here is an example:
    Java Code:
          for(int pos = 0; pos < arr.length && !done; pos++) {
              System.out.println("pos="+pos + ", position="+position);
              if(!done && arr[pos] == toRemove) {
                 done = true;
                 position = pos;
             }
          }
    Take the methods one at a time, define what the selected method should do and write a list of the steps needed to do that.
    If you have any problems, post the name of the method you are working on and your ideas about what the method should do.

    Don't try writing any code until you have a clear idea what the method should do.

    Go ahead, pick a method and get started.
    Last edited by Norm; 03-01-2017 at 05:00 PM.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Hi,

    i did not know what to fill in for the

    public class DiceArray there

    what i should declare for the array data structure in order to get this out at last
    Array data structure or Linked List for Dice-output.pngClick image for larger version. 

Name:	output.PNG 
Views:	12 
Size:	10.7 KB 
ID:	7231

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Array data structure or Linked List for Dice

    know what to fill in for the

    public class DiceArray
    That is the definition for a class named DiceArray. What fields need to be defined in the class for it to do what it is supposed to do?
    Usually the fields and methods are not all define at one time. Some are known when first writing the class and others are added as needed while the rest of the code for the class is developed.

    Note: When you post an image instead of text it is impossible for any of the text in the image to be copied to include in a response. It is better to post text (wrapped in code tags to preserve formatting) instead of an image.
    Last edited by Norm; 03-01-2017 at 05:06 PM.
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Hi Norm,

    what i need to know is how to answer the *//Fill in your implementation here in each public class stated question from the beginning of my question posted.

    public class DiceArray implements DiceIF{
    public static final int MAX = 5; //default maximum size
    protected int lastItem; //points to the last item of the list
    protected Integer[] arr;
    public DiceArray(){
    //Fill in your implementation here ---Answer for the code to run for the output as attachment

    }
    public int size() {
    //Fill in your implementation here
    }
    public boolean isEmpty() {
    //Fill in your implementation here
    }
    public Integer remove(int k) {
    //Fill in your implementation here
    }
    public void insert(int k, Integer data) {
    //Fill in your implementation here
    }
    public String toString() {
    //Fill in your implementation here
    }
    }

    public class Node {
    private Integer data;
    private Node next;
    public Node(Integer data){
    this.data = data;
    }
    public Node(Integer data, Node next){
    this.data = data;
    this.next = next;
    }
    public Integer getData() {
    return data;
    }
    public void setData(Integer data) {
    this.data = data;
    }
    public Node getNext() {
    return next;
    }
    public void setNext(Node next) {
    this.next = next;
    }
    }
    public class DiceSList implements DiceIF{
    private Node head;
    private int listsize; //size of the list
    public DiceSList(){
    //Fill in your implementation here
    }
    public int size() {
    //Fill in your implementation here
    }
    public boolean isEmpty() {
    //Fill in your implementation here
    }
    public Integer remove(int k) {
    //Fill in your implementation here
    }
    public void insert(int k, Integer data) {
    //Fill in your implementation here
    }
    public String toString() {
    //Fill in your implementation here
    }
    }

    public interface DiceIF {
    //returns the actual number of data in the list
    public int size();
    //returns true if the list is empty
    public boolean isEmpty();
    //returns the value of the item at position k, then removes it from the list
    public Integer remove(int k);
    //add an item with value "data" at the k-th position of the list
    public void insert(int k, Integer data);
    //traverse and returns all values in the list
    public String toString();
    }
    import java.util.Random;
    public class DiceTester {
    public static void main(String args[]){
    DiceTester tester = new DiceTester();
    //Test with array implementation
    System.out.println("--- Test with array implementation ---");
    tester.run(new DiceArray());
    //Test with list implementation
    System.out.println("\n--- Test with list implementation ---");
    tester.run(new DiceSList());
    }
    public int throwDice(){
    int max=6, min=1;
    Random rand = new Random();
    int randomNum = rand.nextInt((max - min) + 1) + min;
    return randomNum;
    }
    public void run(DiceIF obj){
    for(int i=0; i < 10; i++){
    int num = throwDice();
    System.out.print(num+"\t");
    obj.insert(i, new Integer(num));
    }
    System.out.println("Size: "+obj.size());
    System.out.println("Original list \t\t\t\t Print: "+obj.toString());
    System.out.print("Removes "+obj.remove(5)+"\t");
    System.out.println("Print after executing remove(5): "
    +obj.toString()+"\t\t Size: "
    +obj.size());
    }
    }
    Array data structure or Linked List for Dice-output.png

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Array data structure or Linked List for Dice

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Take the methods one at a time, define what the selected method should do and write a list of the steps needed to do that.
    If you have any problems, post the name of the method you are working on and your ideas about what the method should do.

    Don't try writing any code until you have a clear idea what the method should do.

    Go ahead, pick a method and get started.

    Note: When you post an image instead of text it is impossible for any of the text in the image to be copied to include in a response. It is better to post text (wrapped in code tags to preserve formatting) instead of an image.
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Array data structure or Linked List for Dice-question1.png
    Array data structure or Linked List for Dice-question2.png
    Array data structure or Linked List for Dice-question3.png

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Array data structure or Linked List for Dice

    Sorry, please do not post images. They can not be used to copy text.

    If you want any help you need to do this:
    Take the methods one at a time, define what the selected method should do and write a list of the steps needed to do that.
    If you have any problems, post the name of the method you are working on and your ideas about what the method should do.

    Don't try writing any code until you have a clear idea what the method should do.

    Go ahead, pick a method and get started.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Hi All,

    Please help to fill in the *Fill in your implementation here as already help me to answer the question already.


    public class DiceArray implements DiceIF{
    public static final int MAX = 5; //default maximum size
    protected int lastItem; //points to the last item of the list
    protected Integer[] arr;
    public DiceArray(){
    //Fill in your implementation here
    }
    public int size() {
    //Fill in your implementation here
    }
    public boolean isEmpty() {
    //Fill in your implementation here
    }
    public Integer remove(int k) {
    //Fill in your implementation here
    }
    public void insert(int k, Integer data) {
    //Fill in your implementation here
    }
    public String toString() {
    //Fill in your implementation here
    }
    }

    public class Node {
    private Integer data;
    private Node next;
    public Node(Integer data){
    this.data = data;
    }
    public Node(Integer data, Node next){
    this.data = data;
    this.next = next;
    }
    public Integer getData() {
    return data;
    }
    public void setData(Integer data) {
    this.data = data;
    }
    public Node getNext() {
    return next;
    }
    public void setNext(Node next) {
    this.next = next;
    }
    }
    public class DiceSList implements DiceIF{
    private Node head;
    private int listsize; //size of the list
    public DiceSList(){
    //Fill in your implementation here
    }
    public int size() {
    //Fill in your implementation here
    }
    public boolean isEmpty() {
    //Fill in your implementation here
    }
    public Integer remove(int k) {
    //Fill in your implementation here
    }
    public void insert(int k, Integer data) {
    //Fill in your implementation here
    }
    public String toString() {
    //Fill in your implementation here
    }
    }

    public interface DiceIF {
    //returns the actual number of data in the list
    public int size();
    //returns true if the list is empty
    public boolean isEmpty();
    //returns the value of the item at position k, then removes it from the list
    public Integer remove(int k);
    //add an item with value "data" at the k-th position of the list
    public void insert(int k, Integer data);
    //traverse and returns all values in the list
    public String toString();
    }
    import java.util.Random;
    public class DiceTester {
    public static void main(String args[]){
    DiceTester tester = new DiceTester();
    //Test with array implementation
    System.out.println("--- Test with array implementation ---");
    tester.run(new DiceArray());
    //Test with list implementation
    System.out.println("\n--- Test with list implementation ---");
    tester.run(new DiceSList());
    }
    public int throwDice(){
    int max=6, min=1;
    Random rand = new Random();
    int randomNum = rand.nextInt((max - min) + 1) + min;
    return randomNum;
    }
    public void run(DiceIF obj){
    for(int i=0; i < 10; i++){
    int num = throwDice();
    System.out.print(num+"\t");
    obj.insert(i, new Integer(num));
    }
    System.out.println("Size: "+obj.size());
    System.out.println("Original list \t\t\t\t Print: "+obj.toString());
    System.out.print("Removes "+obj.remove(5)+"\t");
    System.out.println("Print after executing remove(5): "
    +obj.toString()+"\t\t Size: "
    +obj.size());
    }
    }

  20. #20
    sharinganxy is offline Member
    Join Date
    Mar 2017
    Posts
    24
    Rep Power
    0

    Default Re: Array data structure or Linked List for Dice

    Hi Norm,

    I need to know a diceThrow method in java.

Page 1 of 3 123 LastLast

Similar Threads

  1. List data structure
    By suhaas.mohandos@gmail.com in forum New To Java
    Replies: 4
    Last Post: 08-14-2013, 09:10 AM
  2. Replies: 8
    Last Post: 10-17-2011, 09:17 AM
  3. Linked List, Array List time complexity
    By Rick99771977 in forum New To Java
    Replies: 4
    Last Post: 08-18-2011, 05:37 AM
  4. Replies: 1
    Last Post: 12-03-2009, 07:03 AM
  5. Doubly-linked list with data structure
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •