Write a program in Java using MVC (Model, View, Controller) architecture using either HashSet or TreeSet implementation where users can able to getItem, searchItem, removeItem, and addItem to the list.
//ItemController.java controller iterface package controller.intf; import model.ItemsDetails; public interface ItemController { public ItemsDetails getItem(String name); public ItemsDetails searchItem(String name); public boolean removeItem(String name); public boolean addItem(String name, double price, String desc); public void printDetails(); }
//Model ItemsDetails.java
package model; public class ItemsDetails { private int id; private String name; private double price; private String desc; public ItemsDetails(int id, String name, double price, String desc) { this.id = id; this.name = name; this.price = price; this.desc = desc; } public ItemsDetails(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ItemsDetails that = (ItemsDetails) o; return name != null ? name.equals(that.name) : that.name == null; } @Override public int hashCode() { return name != null ? name.hashCode() : 0; } @Override public String toString() { return "ItemsDetails{" + "id=" + id + ", name='" + name + '\'' + ", price=" + price + ", desc='" + desc + '\'' + '}'; } }
// Controller ItemControllerImpl.java
package controller; import controller.intf.ItemController; import model.ItemsDetails; import view.ItemView; import java.util.Scanner; import java.util.Set; public class ItemControllerImpl implements ItemController { private final ItemView itemView; private final Set<ItemsDetails> itemsDetails; private int counter; public ItemControllerImpl(ItemView itemView, Set<ItemsDetails> itemsDetails) { this.itemView = itemView; this.itemsDetails = itemsDetails; this.counter = itemsDetails.size(); } public ItemsDetails getItem(String name) { return searchItem(name); } public ItemsDetails searchItem(String name) { ItemsDetails item = new ItemsDetails(name); for (ItemsDetails itemsDetail : itemsDetails) { if(itemsDetail.equals(item)){ return itemsDetail; } } return null; } public boolean removeItem(String name) { ItemsDetails item = new ItemsDetails(name); return itemsDetails.remove(item); } public boolean addItem(String name, double price, String desc) { ItemsDetails item = new ItemsDetails(counter++, name, price,desc); return itemsDetails.add(item); } public void printDetails() { for (ItemsDetails itemsDetail : itemsDetails) { itemView.printItemDetails(itemsDetail.getId(), itemsDetail.getName(), itemsDetail.getPrice(), itemsDetail.getDesc()); } } }
//View ItemView.java
package view; public class ItemView { public void printItemDetails(int id, String name, Double price, String desc){ System.out.println("Item Id :"+id); System.out.println("Item Name :"+name); System.out.println("Item Price :"+price); System.out.println("Item Desc :"+desc); } }
//Demo main class
import controller.ItemControllerImpl; import controller.intf.ItemController; import model.ItemsDetails; import view.ItemView; import java.util.HashSet; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class MVCDemo { public static void main(String[] args) { ItemView itemView = new ItemView(); Set<ItemsDetails> itemsDetails = new HashSet<ItemsDetails>(); ItemController itemController = new ItemControllerImpl(itemView, itemsDetails); Scanner scan = new Scanner(System.in); while(true){ System.out.println("================Menu========================"); System.out.println("To Add new item, Enter 1"); System.out.println("To Search item, Enter 2"); System.out.println("To Get an Item, Enter 3"); System.out.println("To Remove, Enter 4"); System.out.println("To Print all item, Enter 5"); System.out.println("To Exit, Enter 9"); System.out.println("========================================"); System.out.println(); System.out.println("Enter your choice::"); int choice = scan.nextInt(); switch(choice){ case 1: System.out.println("Please enter item details"); addItem(itemController); break; case 2: System.out.println("Searching Item details"); ItemsDetails item = itemController.searchItem(getName()); if(null!=item){ System.out.println("Item found :"+item); }else{ System.out.println("Item not found"); } break; case 3: System.out.println("Fetching item details"); item =itemController.getItem(getName()); if(null!=item){ System.out.println("Item found :"+item); }else{ System.out.println("Item not found"); } break; case 4: System.out.println("Removing item details"); boolean flag = itemController.removeItem(getName()); if(flag){ System.out.println("Item removed successfully"); }else{ System.out.println("Item not found"); } break; case 5: System.out.println("Printing item details"); itemController.printDetails(); break; case 9: System.out.println("Thanks you"); System.exit(0); break; default: System.out.println("Incorrect input!!! Please re-enter your choice from menu"); } } } private static void addItem(ItemController itemController){ Scanner sc =new Scanner(System.in); System.out.println("Item name:"); String name = sc.nextLine(); System.out.println("Item price:"); double price = sc.nextDouble(); System.out.println("Item Details:"); sc.next(); String desc = sc.nextLine(); boolean flag =itemController.addItem(name, price, desc); if (!flag){ System.out.println("Item already present"); }else{ System.out.println("Item added successfully"); } } private static String getName(){ Scanner sc = new Scanner(System.in); System.out.println("Please enter item name"); return sc.nextLine(); } }
// I have create a model ItemDetail which contains item details, An interface for all controller method and a view for ItemView.
Write a program in Java using MVC (Model, View, Controller) architecture using either HashSet or TreeSet...
Create three classes in Java using either treeSet or hashSet implementation where users can able to add items, delete items, getItems, and search items in the list or from the list.
According to Model-View-Controller (MVC) architecture, which component should be responsible for: Defining a custom HTML template: A. Model B. View C. Controller I believe the answer is B but I want to be sure. Will be rated.
The Model View Controller (MVC) and Tier architecture are two of the most widely used web design architectures currently in use. a. Explain both concepts to a team of research who want you to build a website and publish their work b. Make a case by thoroughly explaining why one of the architectures in ‘a’ should be chosen over the other c. Brief the researchers on the dangers of using the internet and the necessary steps that you would put...
IOS Swift Code 3) You are creating a calculator app and you are using the MVC architecture discussed in class. You ate a view, a view controller and a model. The calculator view has two UITextFields for inputting numbers, a UlButton for each operation and a UILabel to display the res a) Given the model, the view nd the view controller, which component(s) have full knowledge of other the components? b) Which components can never talk to each other directly?...
Describe, using code fragments, and concrete examples, how to implement the Model View Controller (MVC) design pattern, in relation to web development, using Javascript.
Write a program using java that determines whether an input string is a palindrome; that is, whether it can be read the same way forward and backward. At each point, you can read only one character of the input string; do not use an array to first store this string and then analyze it (except, possibly, in a stack implementation). Consider using multiple stacks. please type out the code :)
Write a program in Java, Python and Lisp When the program first launches, there is a menu which allows the user to select one of the following five options: 1.) Add a guest 2.) Add a room 3.) Add a booking 4.) View bookings 5.) Quit The functionality of these options is as follows: 1.) When users add a guest they provide a name which is stored in some manner of array or list. Guests are assigned a unique ID...
write a java program implementing stacks using arrays. (not with linked list)
Write a Java program that will implement a stack object to convert from either infix notation to postfix notation or postfix notation to infix notation. The program will also implement a link list data structure to track all the conversions done. The Program should have a menu like the following as its output: "Please select what type of conversion you would like to do: Infix to postfix Postfix to infix Print Equations Exit"
Java Programming Write a program to find the number of comparison using binarySearch and the sequentialSearch algorithms as follows: Suppose list is an array of 2500 elements. 1. Use a random number generator to fill list; 2. Use a sorting algorithm to sort list; 3. Search list for some items as follows: a) Use the binary search algorithm to search list (please work on SearchSortAlgorithms.java and modify the algorithm to count the number of comparisons) b) Use the sequential search...