Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java--- PLEASE ENSURE ALL REQUIREMENTS ARE MET BEFORE SUBMITTING… All methods

ID: 3890028 • Letter: I

Question

In Java---

PLEASE ENSURE ALL REQUIREMENTS ARE MET BEFORE SUBMITTING…

All methods work correctly per instructions array (add, remove, peek, print, ifFull, isEmpty)
More added to the driver
all necessary attributes included with private access modifier
header comments and javadoc included

Implement a linked list in java.
Identify the necessary methods in a List Linked implementation (do not forget a display method)
Write a linkedList class (you will need a link class as well)
Write a driver class (tester) to show you have implemented all the necessary methods and appropriately defined your linkedList class

Rewrite the following assignment utilizing a linked list instead of an array.

Implement a linked list in java.
Use your Can Class.
You need to create a driver that makes several cans and places them in alphabetical order in a list.
Identify the necessary methods in a List Linked implementation (do not forget a display method) Write a linkedList class (you will need a link class as well)
Write a driver (tester) to show you have implemented all the necessary methods and appropriately defined your linkedList class
Create a can class, such as a can of soup, only it can be anything on a shelf at a grocery store.
Call your file/class canYourLastName
First define your class variables: Company, Content, Size (usually in ounces), Price. (decide which data types make the most sense)
Next, define a default constructor (takes no arguments) and various other constructors.
Next, define getters and setters and where appropriate. Next, make sure you have toString() method Make sure you have driver class called CanTesterYourLastName.java In this file, create and print objects.
Here is an example driver class:
public class canTesterRuse { public static void main(String[] args) { can SWPeaches = new can("S&W", "Peaches", 12.0, 2.39); can GreenGiantGreenBeans = new can ("Green Giant", "Green Beans"); can DelMonteCreamedCorn = new can("Del Monte", "Creamed Corn", 13.4, 2.49); GreenGiantGreenBeans.setSize(11.9); GreenGiantGreenBeans.setPrice(1.79); System.out.println("Can 1: " + SWPeaches.toString()); System.out.println("Can 2: " + GreenGiantGreenBeans.toString()); System.out.println("Can 3: " + DelMonteCreamedCorn); } } Can 1: can [Company=S&W, Content=Peaches, Size=12.0, Price=2.39] Can 2: can [Company=Green Giant, Content=Green Beans, Size=11.9, Price=1.79] Can 3: can [Company=Del Monte, Content=Creamed Corn, Size=13.4, Price=2.49]

Explanation / Answer

PROGRAM CODE:

Can.java

public class Can implements Comparable<Can> {

private String company;

private String content;

private double size;

private double price;

public Can(String company, String content, double size, double price) {

this.company = company;

this.content = content;

this.size = size;

this.price = price;

}

public Can(String company, String content) {

this.company = company;

this.content = content;

this.size = 0;

this.price = 0;

}

public String getCompany() {

return company;

}

public void setCompany(String company) {

this.company = company;

}

public String getContent() {

return content;

}

public void setContent(String content) {

this.content = content;

}

public double getSize() {

return size;

}

public void setSize(double size) {

this.size = size;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

@Override

public String toString() {

// TODO Auto-generated method stub

return "[Company=" + company + ", " + "Content=" + content + ", " + "Size=" + size + ", " + "Price=" + price + "]";

}

@Override

public int compareTo(Can o) {

if(company.equals(o.company) && content.equals(o.content) && size == o.size && price == o.price)

return 0;

else return -1;

}

}

LinkedList.java

public class LinkedList {

class Node

{

Can data;

Node next;

}

private Node head;

private int size;

public LinkedList() {

head = null;

size = 0;

}

public void add(Can can)

{

Node node = new Node();

node.data = can;

if(isEmpty())

{

head = node;

}

else

{

Node temp = head;

if(head.next == null)

{

head.next = node;

}

else

{

while(temp.next != null)

{

temp = temp.next;

}

temp.next = node;

}

}

size++;

}

public int getSize()

{

return size;

}

public boolean isEmpty()

{

return size==0;

}

public void remove(Can can)

{

if(!isEmpty())

{

if(head.data == can)

head = head.next;

else

{

Node temp = head;

if(temp.next != null)

{

if(temp.next.data == can)

{

temp.next = temp.next.next;

}

}

}

size--;

}

}

public Can peek()

{

if(!isEmpty())

return head.data;

else return null;

}

public void display()

{

Node temp = head;

while(temp != null)

{

System.out.println(temp.data);

temp = temp.next;

}

}

}

CanTesterRuse.java

public class CanTesterRuse {

public static void main(String[] args) {

Can SWPeaches = new Can("S&W", "Peaches", 12.0, 2.39);

Can GreenGiantGreenBeans = new Can ("Green Giant", "Green Beans");

Can DelMonteCreamedCorn = new Can("Del Monte", "Creamed Corn", 13.4, 2.49);

GreenGiantGreenBeans.setSize(11.9); GreenGiantGreenBeans.setPrice(1.79);

System.out.println("Can 1: " + SWPeaches.toString()); System.out.println("Can 2: " + GreenGiantGreenBeans.toString());

System.out.println("Can 3: " + DelMonteCreamedCorn);

System.out.println();

LinkedList list = new LinkedList();

list.add(GreenGiantGreenBeans);

list.add(DelMonteCreamedCorn);

list.add(SWPeaches);

list.display();

System.out.println();

list.remove(GreenGiantGreenBeans);

list.display();

System.out.println();

list.remove(SWPeaches);

list.display();

}

}

OUTPUT:

Can 1: [Company=S&W, Content=Peaches, Size=12.0, Price=2.39]
Can 2: [Company=Green Giant, Content=Green Beans, Size=11.9, Price=1.79]
Can 3: [Company=Del Monte, Content=Creamed Corn, Size=13.4, Price=2.49]

[Company=Green Giant, Content=Green Beans, Size=11.9, Price=1.79]
[Company=Del Monte, Content=Creamed Corn, Size=13.4, Price=2.49]
[Company=S&W, Content=Peaches, Size=12.0, Price=2.39]

[Company=Del Monte, Content=Creamed Corn, Size=13.4, Price=2.49]
[Company=S&W, Content=Peaches, Size=12.0, Price=2.39]

[Company=Del Monte, Content=Creamed Corn, Size=13.4, Price=2.49]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote