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

The file, glass.txt, contains thefollowing: Moretti 247 H 1.1 $38.50 Moretti 276

ID: 3614156 • Letter: T

Question

The file, glass.txt, contains thefollowing:

Moretti 247 H 1.1 $38.50
Moretti 276 O 0.9 $10.80
Vetrofond 902 T 0.4 $4.00
Vetrofond 408 S 0.6 $9.00
Lauscha 045 T 0.2 $2.00
Vetrofond 907 L 0.1 $4.50

"Read in each line of data from the file, and display it tothe user using an information-type message box, indicating themanufacture name, the number, the category (spelled out as a word),the amount of glass in pounds, and the cost of the glass"

Ex. Moretti -> manufacture name
      247        -> number
       H     -> category
1.1         -> amount ofglass in pounds
     $38.50    -> cost of theglass
      manufacture

I did it, but something is wrong.. I think I have a problem withreading comprehension, so I think I am not totally understandingwhat the question is asking. Could you please tell me what is wrongwith my code?
Thank you!!!


 javax.swing.JOptionPane;        

java.io.*;



problem3



main(String[] args) IOException



String filename;

String categories;







filename = JOptionPane.showInputDialog();





FileReader freader = FileReader(filename);

BufferedReader inputFile = BufferedReader(freader);





categories = inputFile.readLine();







(categories != )





JOptionPane.showMessageDialog(, categories);





categories = inputFile.readLine();







inputFile.close();






Explanation / Answer

please rate - thanks the categories have to be changed to words and not single characterwith if else or switch importjavax.swing.JOptionPane;       // Needed for the JOptionPane class importjava.io.*;                   // Needed for file classes import java.util.*; public class untitled { public static void main(String[] args) throws IOException { String filename;        //Needed to read the file String output,categories;       // Needed to read the categories String name,cost; int number; char cat; double amt; // Get the filename. filename = JOptionPane.showInputDialog("Enter the filname."); // Open the file. //FileReader freader = new FileReader(filename); Scanner inputFile=new Scanner(new File(filename)); //BufferedReader inputFile = new BufferedReader(freader); // Read the categories from the file. // If a category was read, display it and // read the remaining categories. while (inputFile.hasNext()) {name = inputFile.next(); number=inputFile.nextInt(); cat=inputFile.next().charAt(0); amt=inputFile.nextDouble(); cost=inputFile.next(); categories="manufacturer: "+name+" number: "+number+" category:"+cat; categories+=" amount of glass: "+amt+" cost of the glass:"+cost; // Display the last category read. JOptionPane.showMessageDialog(null, categories); } // Close the file. inputFile.close(); } }

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