Must be Good at doing JAVA. DO NOT CONTACT IF YOU ARE NOT GOOD AT JAVA

User Generated

satrpun

Computer Science

Description

The following must be done in netbeans IDE 8.2, NOTHING LESS. FOLLOW ALL INSTRUCTIONS IN THE Pdf

Unformatted Attachment Preview

Midterm Project For this project, you’ll create a series of pages that allow you to add, update, or delete a product that’s available to the application. This project needs you to have read chapters 1 through 9. This information below is detailed enough for you to complete the project. However, you will need to determine any unspecified details on your own. For example, you will need to create your own names for the servlet and JSP files that you create, you will need to determine what error messages to display when the user enters invalid data, and so on. Unless you’re instructed otherwise, you can implement the project using any programming techniques you wish. In some cases, however, the project’s specifications will direct you to use a specific programming technique. In that case, you should implement as directed. The following present the user interface, operation, and specifications for the project.: The Index page The Products page The Product page • 2 Projects for Murach’s Java Servlets and JSP (3rd Edition) The Confirm Delete page Operation • When the application starts, it displays the Index page. This page contains a link that leads to the Products page that can be used to add, update, or delete products. • To add a new product, the user selects the Add Product button. This displays the Product page with all text fields empty. Then, the user can fill in the text fields and click on the Update Product button to add the product. • To edit an existing product, the user selects the Edit link for the product. This displays the Product page with all existing data for the product displayed. Then, the user can edit any entries and click on the Update Product button to update the data for the existing product. • To delete a product, the user selects the Delete link for the product. This displays the Confirm Delete page. Then, if the user confirms the deletion by selecting the Yes button, the product is deleted and the Products page is displayed to reflect the new data. If the user selects the No button, the Products page is displayed. Specifications • • • • • Use a Product class like the one shown later in this document to store the product data. Use a ProductIO class like the one shown later in this document to read and write the product data to a text file named products.txt in the WEB-INF directory. Use a text file like the products.txt file shown later in this document as a starting point for the products that are available to the application. Use server-side validation to validate all user entries. In particular, make sure the user enters a code, description, and price for each product. In addition, make sure the product’s price is a valid double value. The Product.java, ProductIO.java, and product.txt files are attached in the “midterm_project” zipped folder in Blackboard. • 3 Projects for Murach’s Java Servlets and JSP (3rd Edition) The Product class package music.business; import java.text.NumberFormat; import java.io.Serializable; public class Product implements Serializable { private private private private Long productId; String code; String description; double price; public Product() {} public Long getId() { return productId; } public void setId(Long productId) { this.productId = productId; } public void setCode(String code) { this.code = code; } public String getCode() { return code; } public void setDescription(String description) { this.description = description; } public String getDescription() { return description; } public String getArtistName() { String artistName = description.substring(0, description.indexOf(" - ")); return artistName; } public String getAlbumName() { String albumName = description.substring(description.indexOf(" - ") + 3); return albumName; } public void setPrice(double price) { this.price = price; } public double getPrice() { return price; } public String getPriceCurrencyFormat() { NumberFormat currency = NumberFormat.getCurrencyInstance(); return currency.format(price); } • 4 Projects for Murach’s Java Servlets and JSP (3rd Edition) public String getImageURL() { String imageURL = "/musicStore/images/" + code + "_cover.jpg"; return imageURL; } public String getProductType() { return "Audio CD"; } } The ProductIO class package music.data; import java.io.*; import java.util.*; import music.business.*; public class ProductIO { private static List products = null; private static String filePath = null; // Called once from the controller based on servlet context public static void init(String filePath) { ProductIO.filePath = filePath; } public static List selectProducts() { products = new ArrayList(); File file = new File(filePath); try { BufferedReader in = new BufferedReader( new FileReader(file)); String line = in.readLine(); while (line != null) { StringTokenizer t = new StringTokenizer(line, "|"); if (t.countTokens() >= 3) { String code = t.nextToken(); String description = t.nextToken(); String priceAsString = t.nextToken(); double price = Double.parseDouble(priceAsString); Product p = new Product(); p.setCode(code); p.setDescription(description); p.setPrice(price); products.add(p); } line = in.readLine(); } in.close(); return products; } catch (IOException e) { System.out.println(e); return null; } } • 5 Projects for Murach’s Java Servlets and JSP (3rd Edition) public static Product selectProduct(String productCode) { products = selectProducts(); for (Product p : products) { if (productCode != null && productCode.equalsIgnoreCase(p.getCode())) { return p; } } return null; } public static boolean exists(String productCode) { Product p = selectProduct(productCode); if (p != null) return true; else return false; } private static void saveProducts(List products) { try { File file = new File(filePath); PrintWriter out = new PrintWriter( new FileWriter(file)); for (Product p : products) { out.println(p.getCode() + "|" + p.getDescription() + "|" + p.getPrice()); } out.close(); } catch (IOException e) { System.out.println(e); } } public static void insertProduct(Product product) { products = selectProducts(); products.add(product); saveProducts(products); } public static void updateProduct(Product product) { products = selectProducts(); for (int i = 0; i < products.size(); i++) { Product p = products.get(i); if (product.getCode() != null && product.getCode().equalsIgnoreCase(p.getCode())) { products.set(i, product); } } saveProducts(products); } public static void deleteProduct(Product product) { products = selectProducts(); for (int i = 0; i < products.size(); i++) { Product p = products.get(i); if (product != null && product.getCode().equalsIgnoreCase(p.getCode())) { products.remove(i); } } saveProducts(products); } } • 6 Projects for Murach’s Java Servlets and JSP (3rd Edition) A product.txt file that contains four products 8601|86 (the band) - True Life Songs and Pictures|14.95 pf01|Paddlefoot - The first CD|12.95 pf02|Paddlefoot - The second CD|14.95 jr01|Joe Rut - Genuine Wood Grained Finish|14.95 •
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Attached.

MainServlet.java---------------------------------------------------------package music.controller;
import java.io.IOException;
import
import
import
import
import

javax.servlet.ServletConfig;
javax.servlet.ServletException;
javax.servlet.http.HttpServlet;
javax.servlet.http.HttpServletRequest;
javax.servlet.http.HttpServletResponse;

import music.business.Product;
import music.data.ProductIO;
/**
* Servlet implementation class MainServlet
*/
public class MainServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public MainServlet() {
super();
// TODO Auto-generated constructor stub
}
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
//Initializing the productIO with full path of the file
String fullFilePath = getServletContext().getRealPath("/WEBINF/product.txt");
ProductIO.init(fullFilePath);
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
*
response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
// The type of action to be performed
Stri...


Anonymous
Great content here. Definitely a returning customer.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags