The following is java code. I\'ve been trying to write a while loop that will se
ID: 3675083 • Letter: T
Question
The following is java code. I've been trying to write a while loop that will search out data on a .txt file and write it on a print writer and if #4 is called, it would print out the entirety of the printwriter. I was wondering what errors I could fix to make this compile and work for me?
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
int count = 0;
if (n == 3)
{
int d = 0;
int e = 0;
int cid = 0;
int iid = 0;
System.out.println("Please enter a customer id: ");
cid = scan.nextInt();
System.out.println("Please enter an item id");
iid = scan.nextInt();
while (inputCustomer.hasNextLine())
{
int idNum = inputCustomer.nextInt();
if (idNum ==cid)
{
d++;
}
}
while (inputItem.hasNextLine())
{
int id = inputItem.nextInt();
if (id == iid)
{
d++;
}
}
if (d == 0)
{
System.out.println("Invalid Customer ID. Record Not Added.");
}
if (e == 0)
{
System.out.println("Invalid Item ID. Record Not Added.");
}
if (d > 0 && e > 0)
{
writer.println(cid + " " + iid);
writer.close();
count++;
}
}
if (n == 4)
{
if (count > 0)
{
System.out.println(stringWriter.toString());
}
else
{
System.out.println("No Records Found");
}
Explanation / Answer
Can you post whole program, because I can not resolve untill will be having whole program ?
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.