subject

I need help in how to call a file in java: (file names are sample_input1.txt, sample_input2.txt, sample_input3.txt)

//These are all the imports you are allowed, don't add any more!
import java. util. Scanner;
import java. io. File;
import java. io. IOException;

class SimpleCompiler {

public static Node fileToQueue(String filename) throws IOException {
//given a file name, open that file in a scanner and create a queue of nodes
//the head of the queue of nodes should be the start of the queue
//the values in the nodes should be the strings read in each time you call
//next() on the scanner
return null;
}

public Node compile(Node input, int numSymbols) {
//Given an input queue of symbols, process the number of symbols
//specified (numSymbols) and update the callStack and symbols
//variables appropriately to reflect the state of the "SimpleCompiler"
//(see below the "do not edit" line for these variables).

//Return the remaining queue items.

//For example, if input is the head of a linked list 3 -> 2 -> +
//and numSymbols=2, you would push 3 and push 2, then return the linked
//list with just the + node remaining.

return null;
}

public static void testThisCode() {
//edit this as much as you want, if you use main without any arguments,
//this is the method that will be run instead of the program
System. out. println("You need to put test code in testThisCode() to run SimpleCompiler with no parameters.");
}

//DON'T EDIT BELOW THIS LINE
//EXCEPT TO ADD JAVADOCS

//don't edit these...
public static final String[] INT_OPS = {"+","-","*","/"};
public static final String[] ASSIGN_OPS = {"=","+=","-=","*=","/="};

//or these...
public CallStack callStack = new CallStack<>();
public LookUpBST symbols = new LookUpBST<>();

public static void main(String[] args) {
//this is not a testing main method, so don't edit this
//edit testThisCode() instead!

if(args. length == 0) {
testThisCode();
return;
}

if(args. length != 2 || !(args[1].equals("false") || args[1].equals("true"))) {
System. out. println("Usage: java SimpleCompiler [filename] [true|false]");
System. exit(0);
}

try {
(new SimpleCompiler()).runCompiler(args[ 0], args[1].equals("true"));
}
catch(IOException e) {
System. out. println(e. toString());
e. printStackTrace();
}
}

//provided, don't change this
public void runCompiler(String filename, boolean debug) throws IOException {
Node input = fileToQueue(filename);
System. out. println("\nProgram: " + Node. listToString(input));

if(!debug) {
while(input != null) {
input = compile(input, 10);
}
}
else {
Scanner s = new Scanner(System. in);
for(int i = 1; input != null; i++) {
System. out. println("\n Step " + i + " \n");
System. out. println("Step Output");
input = compile(input, 1);
System. out. println("Lookup BST");
System. out. println(symbols);
System. out. println("Call Stack");
System. out. println(callStack);
if(input != null) {
System. out. println("Program Remaining");
System. out. println(Node. listToString(input));
}
System. out. println("\nPress Enter to Continue");
s. nextLine();
}
}
}
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:00
The great length of north america causes the climate to be varied. true false
Answers: 2
question
Computers and Technology, 22.06.2019 13:10
Calculating the "total price" of an item is tedious, so implement a get_item_cost method that just returns the quantity times the price for an item. by the way, the technical term for this kind of instance method is an accessor method, but you'll hear developers calling them getters because they always start with "get" and they get some value from instance attributes. in order to make the items sortable by their total total price, we need to customize our class. search the lectures slides for "magic" to see how to do this. see section 9.8 for an additional reference. the receipt class: this will be the class that defines our receipt type. obviously, a receipt will consist of the items on the receipt. this is called the composition design pattern. and it is very powerful. instance attributes: customer_name : it is very important to always know everything you can about your customers for "analytics", so you will keep track of a string customer name in objects of type receipt. date : the legal team has required that you keep track of the dates that purchases happen for "legal reasons", so you will also keep track of the string date in objects of type receipt. cart_items : this will be a list of the items in the cart and hence end up on the receipt. methods: 1. create a default constructor that can take a customer name as an argument, but if it gets no customer name, it will just put "real human" for the customer_name attribute. it should also accept a date argument, but will just use the value "today" for the date instance attribute if no date is given. the parameters should be named the same as the instance attributes to keep things simple. 2. add_item : self-descriptive. takes a parameter which we hope beyond hope is of type itemtopurchase and adds it to the cart_items. returns none. 3. print_receipt : takes a single parameter isevil, with default value true. returns a total cost of all the items on the receipt (remember to factor in the quantity). prints the receipt based on the following specification: for example, if isevil is true, and customer_name and date are the default values: welcome to evilmart, real human today have an evil day! otherwise, it should print: welcome to goodgo, real human today have an good day! then the receipt should be printed in sorted order like we discussed earlier, but whether or not it starts with the highest cost (think reverse), depends on the value of isevil. if it is evil, then the lowest cost items should print first, but if it is good, then it will print the highest cost items first. (cost meaning price*quantity). remember to return the total cost regardless! your main() function: the main flow of control of your program should go in a main() function or the program will fail all the unit tests. get the name of the customer with the prompt: enter customer name: get the date with the prompt: enter today's date then, ask the question: are you evil? your program should consider the following as true: yeah yup let's face it: yes hint: what do these strings all have in common? your program should consider all the following as false: no nah perhaps but i'm leaning no (just be glad you don't have to handle "yeah no.") okay enough horsing around. (get it? aggies? ! horsing! ) next, in the main() function, you will have to create a receipt object and start adding things into it using an input-while loop. the loop will prompt the user for the item name exactly as in the previous zylab (9.11). but unlike the previous zylab, the loop will terminate only if an empty string is entered for the item name. then, the price and the quantity will be prompted for exactly as in the previous zylab. create the itemtopurchase objects in the same manner as the previous zylab, but don't forget to add them to the receipt using your add_item instance method. then, the items on the receipt should be printed with the same formatting as in the previous zylab, of course with either "good" or "evil" ordering. however, on the last line, the total should be printed as follows: where 10 is replaced by the actual total. sample run here is what a sample run of the final program should look like: enter customer name: nate enter today's date: 12/20/2019 are you evil? bwahahahaha yes enter the item name: bottled student tears enter the item price: 2 enter the item quantity: 299 enter the item name: salt enter the item price: 2 enter the item quantity: 1 enter the item name: welcome to evilmart, nate 12/20/2019 have an evil day! salt 1 @ $2 = $2 bottled student tears 299 @ $2 = $598 total: $600
Answers: 1
question
Computers and Technology, 22.06.2019 15:00
Which of the following statements tests if students have a grade of 70 or above, as well as fewer than five absences? a: if(grade > = 70 and daysabsent < = 5): b: if(grade > = 70 or daysabsent < = 5): c: if(grade > 70 and daysabsent < = 5): d: if(grade > 70 or daysabsent < = 5): i took the test the answer is a
Answers: 1
question
Computers and Technology, 24.06.2019 03:40
4. does the kernel phenotype distribution support the idea that the cob is the result of a dihybrid cross? what information supports your answer? if a dihybrid cross (i.e. f1 to f2 of standard mendelian crosses) is not indicated what conditions might contribute to this finding.
Answers: 2
You know the right answer?
I need help in how to call a file in java: (file names are sample_input1.txt, sample_input2.txt, sam...
Questions
question
Health, 20.08.2019 16:10
question
History, 20.08.2019 16:10
question
Health, 20.08.2019 16:10
question
Health, 20.08.2019 16:10
question
Mathematics, 20.08.2019 16:10
Questions on the website: 13722361