Can Anybody write help me to write java code for this projec
Can Anybody write help me to write java code for this project please?
Here is the file of bag of objects from lab 2.
public class Soda
{
private String sodaFlavour;
private double sodaPrice;
/**
* Constructor
* @param newSodaType The value to store in sodaFlavour.
* @param newSodaPrice The value to store in sodaPrice.
*/
public Soda(String newSodaFlavour, double newSodaPrice)
{
sodaFlavour = newSodaFlavour;
sodaPrice = newSodaPrice;
}
/**
* The setSodaFlavour method stores a value in the SodaFlavour field.
* @param newSodaFlavour The value to store in SodaFlavour.
*/
public void setSodaFlavour(String newSodaFlavour)
{
sodaFlavour = newSodaFlavour;
}
public String getSodaFlavour()
{
return sodaFlavour;
}
/**
* The setSodaPrice method stores a value in the sodaPrice field.
* @param newSodaPrice The value to store in sodaPrice.
*/
public void setSodaPrice(double newSodaPrice)
{
sodaPrice = newSodaPrice;
}
/**
* The getSodaPrice method returns a Cheese objects price.
* @return The value in the sodaPrice field.
*/
public double getSodaPrice()
{
return sodaPrice;
}
@Override
public String toString()
{
return \"Soda Flavor:\" + sodaFlavour + \"Soda Price:\" + sodaPrice;
}
}
Here is the file for node<e> from lab 5
public class Node<E>
{ // Start main class
private Node<E> link;
private E data;
/**
* @param initialData is set to data
* @param initialLink is set to link
*/
public Node (E initialData, Node<E> initialLink)
{
initialData = data;
initialLink = link;
}
/*
* getData method calls for value from LinkedBag
* @return data
*/
public E getData()
{
return data;
}
/*
* getLink method calls for value from LinkedBag
* @return the value stored in link
*/
public Node<E> getLink()
{
return link;
}
/*
* setLink method sets data
* @param initialLink
*/
public void setData(E initialData)
{
}
public void setLink(Node<E> initialLink)
{
}
} // End main class
And here is the last file from Lab 5 Linked bag
public class LinkedBag<E>
{ // Start class
private Node<E> head; // declare variables
private int numElements; // declare variables
public LinkedBag()
{
head = null;
numElements = 0;
}
/*
* @param getSize gets the numbers stored
* @return the values of numElements
*/
public int getSize()
{
return numElements;
}
/*
* Add values
* @return the value stored in numElements
*/
public void add(E element)
{
head = new Node<E>(element, head);
numElements++;
}
/*
* countOccurrences method returns value stored in numOccurrences field
* @param target
* @return value in numOccurrences field
*/
public int countOccurrences(E target)
{
Node<E> cursor = head;
int numOccurences = 0;
for(cursor = head; cursor != null; cursor = cursor.getLink())
{
if (cursor.getData() == target)
{
numOccurences++;
}
}
return numOccurences;
}
/*
* exists method returns the value stored in found
* @param target
* @return value stored in found
*/
public boolean exists(E target)
{
boolean found = false;
Node<E> cursor = head;
while(cursor != null && !found)
{
if (cursor.getData() == target)
{
found = true;
}
else
{
cursor = cursor.getLink();
}
}
return found;
}
/*
* remove method returns the value stored in found
* @param target
* @return value stored in found
*/
public boolean remove(String target) {
Node<E> cursor = head;
boolean found = false;
while (cursor!= null && !found)
{
if (cursor.getData().equals(target))
found = true;
else
cursor = cursor.getLink();
}
if (found) {
cursor.setData(head.getData());
head = head.getLink();
numElements++;
}
return found;
}
@Override
public String toString() { // Start method
String stringToReturn = \"\";
Node<E> cursor;
if (numElements == 0) {
stringToReturn = \"empty\";
}
else {
for (cursor = head; cursor != null; cursor = cursor.getLink()) {
stringToReturn = stringToReturn + cursor.getData();
if (cursor.getLink() != null) {
stringToReturn = stringToReturn + \", \";
}
}
} // End method
return stringToReturn;
}
}// End class
Solution
package Sample;
import java.util.Scanner;
public class BagOfobjects {
public LinkedBag<Soda> bagofSodas;
//scanner for both string and double
Scanner scString = new Scanner(System.in);
Scanner scDouble = new Scanner(System.in);
public BagOfobjects() {
bagofSodas = new LinkedBag<Soda>();
}
/**
* @param args
*/
public void add() {
//getting the soda details
System.out.println(\"Enter the flavour of Soda: \");
String flavour = scString.next();
System.out.println(\"Enter the price of Soda: \");
double price = scDouble.nextDouble();
Soda soda = new Soda(flavour, price);
bagofSodas.add(soda);
}
public void delete()
{
System.out.println(\"Enter the flavour to delete: \");
String flavour = scString.next();
System.out.println(\"Enter the price: \");
double price = scDouble.nextDouble();
Soda soda = new Soda(flavour, price);
//bagofSodas.remove();
}
}
more coming...




