Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import javax.swing.*; import java.io.*; import java.util.Scanner; public class DinkAround { public static void main(String[] args) throws Exception { String fileName, shoeNumber, purpose, price, comfort, look,
import javax.swing.*; import java.io.*; import java.util.Scanner; public class DinkAround { public static void main(String[] args) throws Exception { String fileName, shoeNumber, purpose, price, comfort, look, function, sampleShoeInventory; String appendOrErase; String dataToAppend = ""; Scanner keyboard = new Scanner(System.in); System.out.print("Enter File Name like (myfile.txt): "); String line = " "; fileName = keyboard.nextLine(); File file = new File(fileName); if(!file.exists()) { try { file.createNewFile(); System.out.println("New File Created..........."); } catch (IOException io) { io.getMessage(); } System.out.println("fileName Exists!!"); System.out.println("Do you want to append to the file, Erase the existing data from the file,Enter : (append/erase)"); appendOrErase = keyboard.nextLine(); if (appendOrErase.equalsIgnoreCase("append")) { try { JFileChooser chooser = new JFileChooser(); int status = chooser.showOpenDialog(null); if (status != JFileChooser.APPROVE_OPTION) { System.out.println("No File Chosen"); System.exit(0); } File filename = chooser.getSelectedFile(); FileWriter outputFile = new FileWriter(filename, true); do { JOptionPane.showMessageDialog(null, "For appending data you must follow the instructions to adding information"); shoeNumber = JOptionPane.showInputDialog("Please select number of shoe starting with 1 and go on.."); purpose = JOptionPane.showInputDialog("For purpose please select if the purpose is casual, dress or athletic "); price = JOptionPane.showInputDialog("For price please enter numbers between 1 through 5 for proper selection"); comfort = JOptionPane.showInputDialog("For comfort please enter numbers between 1 through 5 for proper selection"); look = JOptionPane.showInputDialog("For look please enter numbers between 1 through 5 for proper selection"); function = JOptionPane.showInputDialog("For function please enter numbers between 1 through 5 for proper selection"); outputFile.write(shoeNumber + " " + purpose + " " + price + " " + comfort + " " + look + " " + function + " " + line); sampleShoeInventory = JOptionPane.showInputDialog("Do you want to add another sample shoe inventory on the categories,select yes or no"); } while (sampleShoeInventory.equalsIgnoreCase("Yes")); outputFile.write(line); outputFile.close(); System.out.println("Data written to the file."); } catch (IOException ignored) { } } else if (appendOrErase.equalsIgnoreCase("erase")) { file.delete(); } } } } Can you guys help me to fix correctly the program?a. Write a program named HW4CreateInventory.java to store shoe data into an inventory data file. Ask the user to enter the name of the file to store the information into. If the file exists, ask the user if they want to append to the file, erase the existing data from the file, or use a different file. Handle the user's choice appropriately. Then, repeat until the user is done entering shoe data, capture the shoe number, purpose (casual, dress, or athletic) and the four factor values (price, comfort, look, and function) for each pair of shoes. (This program would be something that the shoe store clerk would run, as they enter new shoes into inventory or that would be captured by the store, based on online reviews from customers.) b. Write a second program named HW4ShoeAdvisor.java to ask the user for a purpose, and ask the user to set their weight preferences. (Verify that the weight preferences adds up to 10). Then read the inventory data file, and output the best pair of shoes for that purpose, using the user's weight preferences. Repeat until the user is ready to quit. Sample data is shown below. Assume we are only interested in the three purposes shown. Shoes 1-3 are the sample shoes described above. (This program would be ran by a customer looking for a pair of shoes.) Sample User's Weight Preferences: 3 2 3 2 Sample shoes in inventory: Shoe Using the sample weights, Number Purpose Price Comfort Look Function calculated shoe rating 1 casual 1 3 5 5 2 casual 5 2 5 3 3 casual 1 5 4 3 4 dress 4 5 4 5 athletic 2 4 5 2 6 dress 3 5 4 5 7 athletic 5 4 3 5 8 dress 5 3 4 3 34 40 31 4 42 33 41 42 39 Use JFileChooser for choosing the filename. Output your name as part of the output. To make this a useable solution in real-life: What additional data would you need? What additional questions would you need answered? What are additional modifications would you need to make? Include your answers to these questions in your heading documentation of the second program. Bonus: Ask the user if he/she wants to use the default weights (the same as Emily's weights), or set their own weights. Then, continue with the shoe advisor appropriately. Validate the purpose of the shoe meets one of the three listed. More Bonus: Incorporate additional factors into your solution that would aid its value in a real-life situation. In the heading documentation explain what problem your bonus is focused on solving and how your implementation solves it. More Bonus: Using a different problem domain, answer the questions above and solve the problem. For example, how would you: rank football teams? Decide which car to purchase? Decide which school to attend
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started