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

Can Anybody write help me to write java code for this project please? Here is th

ID: 3775662 • Letter: C

Question

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 Cheese
{
private String cheeseType;
private double cheesePrice;
  
  
/**
* Constructor
* @param newCheeseType The value to store in cheeseType.
* @param newCheesePrice The value to store in cheesePrice.
*/
  
public Cheese(String newCheeseType, double newCheesePrice)
{
cheeseType = newCheeseType;
cheesePrice = newCheesePrice;
}
  
/**
* The setCheeseType method stores a value in the cheeseType field.
* @param newCheeseType The value to store in cheeseType.
*/
  
public void setCheeseType(String newCheeseType)
{
cheeseType = newCheeseType;
}
  
public String getCheeseType()
{
return cheeseType;
}
  
/**
* The setCheesePrice method stores a value in the cheesePrice field.
* @param newCheesePrice The value to store in cheesePrice.
*/
  
public void setCheesePrice(double newCheesePrice)
{
cheesePrice = newCheesePrice;
}
  
/**
* The getCheesePrice method returns a Cheese objects price.
* @return The value in the cheesePrice field.
*/
  
public double getCheesePrice()
{
return cheesePrice;
}
  
//@Override
// public String toString()
// {
// return "Cheese Type:" + cheeseType + "Cheese Price:" + cheesePrice;
// }
  
}

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

Create a program that allows a user to maintain a "Bag" of "Objects" using your Class from Lab 2 and your Node and LinkedBagsE> from Lab 5 Regarding your class: You will have to add an equals() method to your Class so that equals, remove() and count occurrences() will work. honors option will have to add compareTo() as well l You will also have to add a toString() method to your Class You may need to add a constructor that accepts ALL parameters to make the call ofto the methods easier example: after prompting user for yearEntered and makeEntered, then can execute if (myBag exists (new Car(yearEntered,makeEntered))) Your class from Lab 2 is subject to the same requirements as Lab 2. Your program should have the following options A-Add "Object" to bag o Asks the user to enter attributes for an "Object" and then adds the "Object" to the bag (calls .add() method) o Honors Option: maintain order on add() Remove "object" from bag o Asks the user to enter attributes for an "Object" and then attempts to remove the Object" from the bag should return a success/failure message (calls .remove() method need to use if for success/failure) o Honors option: maintain order on remove() F finds if an "Object" is in the bag o Asks the user to enter attributes for an "object" and then a message based on whether the object is in the bag (calls exists() method) C Counts the number of occurrences of an "Object" in bag o Asks the user to enter attributes for an "Object" and then displays the number of occurrences of that "Object" in the bag (calls countoccurrences() method) D-displays contents of bag o Honors Option: if you maintained order for add() and remove(), they should display in order S Display Size of Bag o Displays the size of the bag (calls .size() method) X-gracefully exits Note: if user selects an invalid command-display an error G-grab extra Credit See DemoDoWhilestrings.java in Java Review Part1.zip demo file

Explanation / Answer

CheeseDemo.java

import java.util.Scanner;


class Cheese {//class name

    private String cheeseType;
    private double cheesePrice;

    /**
     * Constructor
     *
     * @param newCheeseType The value to store in cheeseType.
     * @param newCheesePrice The value to store in cheesePrice.
     */
    public Cheese(String newCheeseType, double newCheesePrice) {//constructor with arguments
        cheeseType = newCheeseType;
        cheesePrice = newCheesePrice;
        System.out.println("Cheese Type= :" + cheeseType);
        System.out.println("Cheese price :" + cheesePrice);
    }

    /**
     * The setCheeseType method stores a value in the cheeseType field.
     *
     * @param newCheeseType The value to store in cheeseType.
     */
    //setter and getter values
    public void setCheeseType(String newCheeseType) {
        cheeseType = newCheeseType;
    }

    public String getCheeseType() {
        return cheeseType;
    }

    /**
     * The setCheesePrice method stores a value in the cheesePrice field.
     *
     * @param newCheesePrice The value to store in cheesePrice.
     */
    public void setCheesePrice(double newCheesePrice) {
        cheesePrice = newCheesePrice;
    }

    /**
     * The getCheesePrice method returns a Cheese objects price.
     *
     * @return The value in the cheesePrice field.
     */
    public double getCheesePrice() {
        return cheesePrice;
    }

    //@Override
    // public String toString()
    // {
    //     return "Cheese Type:" + cheeseType + "Cheese Price:" + cheesePrice;
    // }
}

public class CheeseDemo {//main class

    public static void main(String[] args) {//main method
        String cheeseType;
        double cheesePrice;
                 Scanner keyboard = new Scanner(System.in);
      
        System.out.print("Enter your favorite Cheese Type: ");
        cheeseType = keyboard.nextLine();
      
        System.out.print("Enter the price of Cheese: ");
        cheesePrice = keyboard.nextDouble();

        Cheese ces = new Cheese(cheeseType,cheesePrice);//constructor invoking

        System.out.println(ces.toString());//coverting object

    }

}


output

Enter your favorite Cheese Type: provolin
Enter the price of Cheese: 5.99
Cheese Type= :provolin
Cheese price :5.99
Cheese@1f96302

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