//Chapter 13 (File Input and Output), Java Programming, joyce Farrell, 8th edit
ID: 3681543 • Letter: #
Question
//Chapter 13 (File Input and Output), Java Programming, joyce Farrell, 8th edit
//DebugThirteen4.java
//output, need to fix
// Reads file of entrees and prices
// prompts user for a cutoff price
// and displays entrees that cost no more than the cutoff
import java.nio.file.*;
import java.io.*;
import static java.nio.file.AccessMode.*;
import java.util.Scanner;
public class DebugThirteen4
{
public static void main(String[] args)
{
Scanner keyBoard = new Scanner(System.in);
Path file =
Paths.get("C:\Java\Chapter.13\DebugData4.txt");
String[] array = new String[2];
String string = "";
String delimiter = ",";
double searchPrice;
boolean wasFound = false;
try
{
InputStream input = new BufferedInputStream(Files.newInputStream(reader));
BufferedReader reader = new BufferedReader(new InputStreamReader(reader));
System.out.println();
System.out.print("Enter maximum price to search for >> ");
searchPrice = keyBoard.next();
System.out.println(" Entrees no more than $" + searchPrice + " ");
string = reader.readLine();
while(string == null)
{
array = string.split(delimitr);
if(searchPrice >= Double.parseDouble(array[2]))
{
wasFound = falsw;
System.out.println(array[0] + " $" + array[1]);
}
string = reader.readLine();
}
if(!wasFound)
System.out.println("No entrees found under $" + price);
reader.close();
}
catch(Exception e)
{
System.out.println("Message: " + message);
}
}
}
------------------------------------------------
//DebugData1.txt
Somewhere over the rainbow.
-----------------------------------------------
//DebugData2.txt
There's no place like home.
Are you a good witch or a bad witch?t
---------------------------------------------------
//DebugData3.txt
435-9845
239-9845
981-9883
384-5656
875-3784
874-8120
----------------------------------------------------
//DebugData4.txt
steak,20
lobster,30
macaroni,8
spaghetti,10
Explanation / Answer
Hi, I have fixed all error. Plese test and let me in case of any issue.
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
public class DebugThirteen4 {
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
Path file =Paths.get("C:\Java\Chapter.13\DebugData4.txt");
String[] array = null;
String string = "";
String delimiter = ",";
double searchPrice;
boolean wasFound = false;
try {
InputStream input = new BufferedInputStream(
Files.newInputStream(file));
BufferedReader reader = new BufferedReader(new InputStreamReader(
input));
System.out.println();
System.out.print("Enter maximum price to search for >> ");
searchPrice = keyBoard.nextDouble();
System.out.println(" Entrees no more than $" + searchPrice + " ");
string = reader.readLine();
while (string == null) {
array = string.split(delimiter);
if (searchPrice >= Double.parseDouble(array[1])) {
wasFound = true;
System.out.println(array[0] + " $" + array[1]);
}
string = reader.readLine();
}
if (!wasFound)
System.out.println("No entrees found under $" + searchPrice);
reader.close();
} catch (Exception e) {
System.out.println("Message: " + e.getMessage());
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.