Question: Hi, I am trying to write code that reads a command or set of commands in a text file. Here is what I currently have:

Hi, I am trying to write code that reads a command or set of commands in a text file. Here is what I currently have:

static DequeUsingStacks deq = new DequeUsingStacks();

public static void main(String[] args) {

try{

FileInputStream fstream = new FileInputStream("Assignment2.txt");

BufferedReader br = new BufferedReader(new InputStreamReader(fstream));

String l = "";

String[] arr = new String[15];

while((l = br.readLine()) != null){

if(l.equalsIgnoreCase("is_empty"))

System.out.println(deq.isEmpty());

if(l.equalsIgnoreCase("first"))

System.out.println(deq.first());

if(l.equalsIgnoreCase("last"))

System.out.println(deq.last());

if(l.equalsIgnoreCase("addFirst")){ // The textfile will have a string after the command(e.g. addFirst New York)

System.out.println(deq.addFirst(new Value));

I am stuck at the addFirst command since the line will have a set of strings. I want to be able to read the command in the textfile and put the string as the new Value.

Please Help. Thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!