Implement linked based list and ADTs in Java, fullfilling all conditions listed below Remember to use the code images below for data attributes : A LinkNode structure or class which will have two...


Implement linked based list and ADTs in Java, fullfilling all conditions listed below
Remember to use the code images below for data attributes:



  1. A LinkNode
    structure or class which will have two attributes - a
    dataattribute and a pointer attribute to the
    next
    node.  The data attribute of the LinkNode should be the Money class of Lab 1.

  2. A Singly Linked List
    class
    which will be composed of three attributes - a
    count
    attribute, a LinkedNode pointer/reference attribute pointing to the
    start
    of the list and a LinkedNode pointer/reference attribute pointing to the
    end
    of the list. Since this is a class, make sure all these attributes are private.

  3. The attribute names for the Node and Linked List are the words in bold in #1 and #2.

  4. For the Linked List, implement the most common linked-list behaviors as explained in class -

    1. getters/setters/constructors/destructors for the attributes of the class,

    2. (a) create new list, (b) add data, (c) delete data, (d) find data, (e) count of data items in the list, (f) is list empty, (g) empty/destroy the list and (h) print all data items in a list. Note: create new list can be the constructor and destroy list can be the destructor or garbage collector. Note 2: It will be helpful if you define specific add/delete/find methods for the first and last position of the list.

    3. Any other methods you think would be useful in your program.



  5. A Stack
    class
    derived from the Linked List but with no additional attributes and the usual stack methods - (a) create stack, (b) push, (c) pop, (d) peek, and (e) destroy/empty the stack. Similar to above, create can be the constructor etc.

  6. A Queue
    class
    derived from the Linked List but with no additional attributes and the usual queue methods - (a) create queue, (b) enqueue, (c) dequeue, (d) peekFront, (e) peekRear, and (f) destroy/empty the queue. Similar to above, create can be the constructor etc.

  7. Ensure that all your classes are mimimal and cohesive with adequate walls around them. Try to reuse and not duplicate any code. You are allowed to define interfaces as needed, so you can reuse them in your project.

  8. Then write a main driver program that will demonstrate all the capabilities of your ADTs as follows -

    1. Create seven (7) Node objects of Money class to be used in the program.

    2. Demonstrate the use of your LinkedList with the seven USD Node objects inserted/deleted/searched in a random order.  Remember, you will need to print the contents of the List several times to demonstrate the functionality.

    3. Demonstrate the use of your Stack with the same seven USD Node objects pushed/popped/peeked in a random order different from the one in LinkedList.

    4. Demonstrate the use of your Queue with the same seven USD Node objects enqueued/dequeued/peeked in a random order different from both the LinkedList and Stack.

    5. Demonstrate use of all the methods above by providing sufficient information to screen for actions being taken.

    6. Restrict all your input / output to the main driver program only.



  9. For submission, code your LinkNode and LinkedList in one file and Stack and Queue in a separate file. Remember to include the code file(s) for your Currency and Money classes. Also, your 'main' which is the driver program should be in a separate file of its own. Additionally, you will include your output text file as well as screenshots of the console run.

  10. Remember to include pre/post documentation and comment blocks as necessary in your code files.


// abstract base class called Currency with two integers attributes<br>public abstract class Currency {<br>1<br>35 }<br>public class Money extends Currency{<br>//coin value is greater than 10 cents<br>if(super.getCoinValue() > 10){<br>return(super.getNoteValue() +<br>} else{<br>return(super.getNoteValue() +
other.getNoteValue()) 46 13 } 13 this.coinName "Cent"; 47 14 public Currency(Currency currency){ 14 } 48 return 1; 15 this.noteValue currency.noteValue; public Currency addCurrency(Currency currency){ else if(this.getNoteValue() < other.getnotevalue())="" 15="" 49="" 16="" this.coinvalue="currency.coinValue;" cast="" the="" currency="" to="" be="" money="" money="" other="(Money)" currency;="" 16="" 50="" return="" -1;="" 17="" }="" 17="" 51="" else="" if(this.getcoinvalue()=""> other.getCoinValue()) 18 18 //get notes and coins value 52 return 1; super.getNoteValue() + other.getNoteValue(); super.getCoinValue() + other.getCoinValue(); 19 public int getNoteValue(){ 19 int notes else if(this. getCoinValue() < other.getcoinvalue())="" 53="" 20="" return="" notevalue;="" 20="" int="" coins="" 54="" return="" -1;="" 21="" }="" if="" coins="" is="" greater="" than="" 100="" if(coins="">= 100){ 21 55 else return 0; 22 public void setNoteValue(int noteValue){ 22 56 } 23 this.noteValue noteValue; 23 //increment the notes count public void printCurrency(){ //coin value is greater than 10 cents if(super.getCoinValue() > 10){ System.out.println(super.getNoteValue() + " " + currencyName + " " + super.getCoinValue() + " "+ coinName); } else{ System.out.print(super.getNoteValue() + ".0" + currencyName + 57 24 } 24 notes++; 58 25 public int getCoinValue(){ 25 //decrement 100 from coins 59 26 return coinValue; 26 coins -= 100; 60 II II 27 } 27 } 61 28 public void ssetCoinValue(int coinValue){ 28 return new Money(notes,coins); + super.getCoinValue()+ + coinName); 62 29 this.coinValue coinValue; 29 } 63 } 30 } 30 public Currency subtractCurrency(Currency currency){ 64 } public abstract Currency addCurrency(Currency c); public abstract Currency subtractCurrency(Currency c); public abstract int compareCurrency(Currency c); public abstract void printCurrency(); 31 //Cast the currency to be Money (Money) currency; 31 65 @Override 32 32 Money other 66 public String toString(){ 33 33 // get ntoes and coins value 34 34 int notes = super.getNoteValue() - other.getNoteValue(); 4 5 6 8 "/>
Extracted text: // abstract base class called Currency with two integers attributes public abstract class Currency { 1 35 } public class Money extends Currency{ //coin value is greater than 10 cents if(super.getCoinValue() > 10){ return(super.getNoteValue() + } else{ return(super.getNoteValue() + ".0" + currencyName + " " + super.getCoinValue() + " " + coinName); } 35 int coins = super.getCoinValue() - other.getCoinValue(); 67 36 private String currencyName; 36 //if no coins 68 3 protected int noteValue; 3 private String coinName; + currencyName + 37 if(coins < 0){="" 69="" +="" super.getcoinvalue()="" +="" "="" "="" +="" coinname="" );="" ii="" i|="" protected="" int="" coinvalue;="" 4.="" 38="" increment="" the="" ntoes="" count="" 70="" public="" money(o{="" super();="" this.currencyname="" ii="" ii="" 39="" notes="" --;="" 71="" public="" currency(){="" 40="" decrement="" 100="" from="" coins="" 72="" 7="" this.notevalue="" 0;="" 7="" "dollar";="" 41="" coins="" +="100;" 73="" }="" this.coinvalue="" 0;="" 8.="" this.coinname="" "cent";="" 42="" }="" 74="" }="" %3|="" 9.="" }="" 9.="" }="" 43="" return="" new="" money="" (notes,coins);="" 75="" public="" currency(int="" notevalue,="" int="" coinvalue){="" public="" money(int="" notevalue,="" int="" coinvalue){="" super(notevalue,="" coinvalue);="" this.currencyname="" 10="" 10="" 44="" }="" 76="" 11="" this.notevalue="" notevalue;="" 11="" public="" int="" comparecurrency(currency="" currency){="" (money)="" currency;="" 45="" 77="" 12="" this.coinvalue="" coinvalue;="" 12="" "dollar";="" money="" other="" if(this.getnotevalue()=""> other.getNoteValue()) 46 13 } 13 this.coinName "Cent"; 47 14 public Currency(Currency currency){ 14 } 48 return 1; 15 this.noteValue currency.noteValue; public Currency addCurrency(Currency currency){ else if(this.getNoteValue() < other.getnotevalue())="" 15="" 49="" 16="" this.coinvalue="currency.coinValue;" cast="" the="" currency="" to="" be="" money="" money="" other="(Money)" currency;="" 16="" 50="" return="" -1;="" 17="" }="" 17="" 51="" else="" if(this.getcoinvalue()=""> other.getCoinValue()) 18 18 //get notes and coins value 52 return 1; super.getNoteValue() + other.getNoteValue(); super.getCoinValue() + other.getCoinValue(); 19 public int getNoteValue(){ 19 int notes else if(this. getCoinValue() < other.getcoinvalue())="" 53="" 20="" return="" notevalue;="" 20="" int="" coins="" 54="" return="" -1;="" 21="" }="" if="" coins="" is="" greater="" than="" 100="" if(coins="">= 100){ 21 55 else return 0; 22 public void setNoteValue(int noteValue){ 22 56 } 23 this.noteValue noteValue; 23 //increment the notes count public void printCurrency(){ //coin value is greater than 10 cents if(super.getCoinValue() > 10){ System.out.println(super.getNoteValue() + " " + currencyName + " " + super.getCoinValue() + " "+ coinName); } else{ System.out.print(super.getNoteValue() + ".0" + currencyName + 57 24 } 24 notes++; 58 25 public int getCoinValue(){ 25 //decrement 100 from coins 59 26 return coinValue; 26 coins -= 100; 60 II II 27 } 27 } 61 28 public void ssetCoinValue(int coinValue){ 28 return new Money(notes,coins); + super.getCoinValue()+ + coinName); 62 29 this.coinValue coinValue; 29 } 63 } 30 } 30 public Currency subtractCurrency(Currency currency){ 64 } public abstract Currency addCurrency(Currency c); public abstract Currency subtractCurrency(Currency c); public abstract int compareCurrency(Currency c); public abstract void printCurrency(); 31 //Cast the currency to be Money (Money) currency; 31 65 @Override 32 32 Money other 66 public String toString(){ 33 33 // get ntoes and coins value 34 34 int notes = super.getNoteValue() - other.getNoteValue(); 4 5 6 8
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here