Question: Hi, can you help me with my programming assignment for my data structures class using java. My program's while loop is not working properly. Main

Hi, can you help me with my programming assignment for my data structures class using java. My program's while loop is not working properly.

Hi, can you help me with my programming assignment for my data

Main program

package recipedatabase;

import javax.swing.JOptionPane;

public class RecipeDatabase {

public static void main(String[] args) { //Elijah Knight, CSC 222, Fall 2017, Program #3, Recipe Database

JOptionPane.showMessageDialog(null, "Welcome to the Recipe Database, by Elijah Knight." + " This program will display a main menu where you can add a recipe, delete a" + " recipe, change a recipe, show one recipe, or show all recipes. Enjoy!");

Recipe r = new Recipe(); CircularLinkedList list = new CircularLinkedList(); String cont = "y"; String rName = null; String rType = null; String instructions = null; String dateUsed = null; int numServings = 0; String mainMenu = "";

while (!mainMenu.equalsIgnoreCase("Q")) {

mainMenu = JOptionPane.showInputDialog("(A)dd a recipe" + " (D)elete a recipe" + " Show (O)ne recipe" + " (C)hange a recipe" + " (S)how all recipes" + " (Q)uit");

if (mainMenu.equalsIgnoreCase("A")) { rName = JOptionPane.showInputDialog("Enter Recipe Name"); rType = JOptionPane.showInputDialog("Enter type of recipe"); instructions = JOptionPane.showInputDialog("Enter instructions for recipe"); dateUsed = JOptionPane.showInputDialog("Enter the date of last use"); numServings = Integer.parseInt(JOptionPane.showInputDialog("Enter number of servings")); r = new Recipe(rName, rType, instructions, dateUsed, numServings); list.insert(r);

} if (mainMenu.equalsIgnoreCase("D")) { rName = JOptionPane.showInputDialog("Enter Name of recipe to be deleted"); JOptionPane.showMessageDialog(null, list.delete(rName)); } if (mainMenu.equalsIgnoreCase("O")) { rName = JOptionPane.showInputDialog("Enter name of recipe to be shown"); JOptionPane.showMessageDialog(null, list.showOne(rName)); } if (mainMenu.equalsIgnoreCase("C")) { rName = JOptionPane.showInputDialog("Enter name of recipe to be changed"); rName = JOptionPane.showInputDialog("Enter Recipe Name"); rType = JOptionPane.showInputDialog("Enter type of recipe"); instructions = JOptionPane.showInputDialog("Enter instructions for recipe"); dateUsed = JOptionPane.showInputDialog("Enter the date of last use"); numServings = Integer.parseInt(JOptionPane.showInputDialog("Enter number of servings")); r = new Recipe(rName, rType, instructions, dateUsed, numServings); list.change(rName, r);

} if (mainMenu.equalsIgnoreCase("S")) { rType = JOptionPane.showInputDialog("Enter type of recipes to be shown"); list.showAll(rType);

} if (mainMenu.equalsIgnoreCase("Q")) { JOptionPane.showMessageDialog(null, "Thanks for using my program!"); break; }

} } }

circular linked list class

package recipedatabase;

import javax.swing.JOptionPane;

public class CircularLinkedList {

public class Node {

private Recipe recipe; private int num; private Node next;

public Node(Recipe recipe) { }

}

Node top; Node bottom; int size;

public CircularLinkedList() {

Node head; head = null;

size = 0;

}

public Recipe showOne(String name) { Node current = top.next; while (JOptionPane.showInputDialog("Search for Recipe").equalsIgnoreCase(name)) { current = current.next; } if (current != top) { return current.recipe.deepCopy();

} else { return null; } }

public void showAll(String s) { Node n = top.next; while (n != top) {

if (s == n.recipe.showType()) { JOptionPane.showMessageDialog(null, n.recipe.toString());

} n = n.next;

}

}

public boolean isEmpty() { return top == null; }

public void insert(Recipe recipe) { Node newNode = new Node(recipe); newNode.recipe = recipe.deepCopy(); if (isEmpty()) { newNode.next = top;

} else { newNode.next = top.next;

} top.next = newNode; }

public boolean delete(String name) { Node p = top; Node t = top.next;

if (JOptionPane.showInputDialog("Search for Recipe").equalsIgnoreCase(name)) { p.next = t.next; return true;

} else { return false; }

}

public boolean change(String name, Recipe newRecipe) { if (!delete(name)) { return false;

} insert(newRecipe); return true; }

}

Recipe class

package recipedatabase;

public class Recipe {

String rName; String rType; String instructions; String dateUsed; int numServings;

public Recipe(){ } public Recipe(String n, String t, String i, String d, int s) { n = rName; t = rType; i = instructions; d = dateUsed; s = numServings;

}

public String showRecipe() { return rName + " " + " " + rType + " " + " " + instructions + " " + " " + dateUsed + " " + " " + numServings;

}

public String showName() { return rName; }

public String showType() { return rType;

}

public String showInstructions() { return instructions;

}

public String showDate() { return dateUsed; }

public int showServings() { return numServings; }

public Recipe deepCopy() { Recipe copy = new Recipe(rName, rType, instructions, dateUsed, numServings); return copy; }

@Override public String toString() { return "Recipe: " + showName();

} }

program3 [Compatibility Mode] s Mailings Review View A. AaBbCcDdEe AaBbCcDd AaBbCo Caption Heading 1 Headi Data Structures CSC 222 -Fall 2017 Programming Assignment #3-50 Points Due by 11:59PM, Tuesday, October 10h Seems like we need to do some linked list practice... So, your task for this program is to create a database for your mom's (or dad's or significant other's) collection of recipes. Sounds useful, doesn't it? Details: Comments: The banner for your program (comment at the top) should include Name, Class, Semester, Program number, and program description. The remainder should follow the WJU Computer Science standards. Execution: Your program will first display your welcome message, which should include your name and a brief description of the program (with any appropriate instructions). Next, it will display a menu to allow the user to (A)dd a recipe to the database, (D)elete a recipe from the database, show (O)ne recipe, (C)hange a recipe, (S)how all recipes for a specific type (i.e. entree, dessert, etc), or (Q)juit. After the "Q" option is chosen, it will show your exit message Implementation: You will be writing this one using a circular, singly-linked list using the techniques and some of code from the book and the list does NOT need to be sorted. Your show one" recipe should be based on the name of the recipe and should show the entire recipe but your "show all should only show the names of the recipes (based on their type). You will do this "manually", not by using the built-in Java LinkedList libraries or iterators. Your program should contain (at least) 3 classes: the main program, the CircularLinkedList class (with an inner Node class), and the Recipe class Each recipe needs to have the following information: recipe name (i.e. beef stroganoff, etc), type of recipe (i,e. entree, salad, dessert, soup, appetizer, snack, beverage, etc), instructions, date of last use, and number of servings. Help Documentation: Include a statement of any outside help received in your main comment block Submittal: Use the assignment button on BlackBoard to submit your zipped project. As always, extra effort will earn extra credit, but be SURE you get the basics down first! Up to 10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!