TRANSLATE THIS PSEUDO CODE INTO JAVA. A high-level algorithm for the traceFile method is given below: Initialize
Fantastic news! We've Found the answer you've been seeking!
Question:
TRANSLATE THIS PSEUDO CODE INTO JAVA.
Transcribed Image Text:
A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open file using filename. while file has lines line = next line in file. if line is not empty and line does not start with '#' indents = number of spaces in line / SPACES_COUNT. while indents is less than size of stack if indents is 0 Close file and return the total complexity of stack.top. else old Top stack.pop() old TopComplexity = total complexity of old Top if oldTopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = old TopComplexity if line contains a keyword keyword=keyword in line. if keyword is "for" Determine the complexity at end of line ("N:" or "log_N: ") Create new 0(n) or 0(log(n)) CodeBlock and push onto stack. else if keyword is "while" else loopVariable = variable being updated (first token after "while"). Create new 0(1) CodeBlock with loopVariable and push onto stack. else Create new 0(1) CodeBlock and push onto the stack. else if stack.top is a "while" block and line updates stack.top's loopVariable Update the blockComplexity of stack.top. Ignore line. while size of stack > 1 oldTop stack.pop() oldTopComplexity = total complexity of oldTop if old TopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = oldTopComplexity Return stack.pop(). A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open file using filename. while file has lines line = next line in file. if line is not empty and line does not start with '#' indents = number of spaces in line / SPACES_COUNT. while indents is less than size of stack if indents is 0 Close file and return the total complexity of stack.top. else old Top stack.pop() old TopComplexity = total complexity of old Top if oldTopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = old TopComplexity if line contains a keyword keyword=keyword in line. if keyword is "for" Determine the complexity at end of line ("N:" or "log_N: ") Create new 0(n) or 0(log(n)) CodeBlock and push onto stack. else if keyword is "while" else loopVariable = variable being updated (first token after "while"). Create new 0(1) CodeBlock with loopVariable and push onto stack. else Create new 0(1) CodeBlock and push onto the stack. else if stack.top is a "while" block and line updates stack.top's loopVariable Update the blockComplexity of stack.top. Ignore line. while size of stack > 1 oldTop stack.pop() oldTopComplexity = total complexity of oldTop if old TopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = oldTopComplexity Return stack.pop(). A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open file using filename. while file has lines line = next line in file. if line is not empty and line does not start with '#' indents = number of spaces in line / SPACES_COUNT. while indents is less than size of stack if indents is 0 Close file and return the total complexity of stack.top. else old Top stack.pop() old TopComplexity = total complexity of old Top if oldTopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = old TopComplexity if line contains a keyword keyword=keyword in line. if keyword is "for" Determine the complexity at end of line ("N:" or "log_N: ") Create new 0(n) or 0(log(n)) CodeBlock and push onto stack. else if keyword is "while" else loopVariable = variable being updated (first token after "while"). Create new 0(1) CodeBlock with loopVariable and push onto stack. else Create new 0(1) CodeBlock and push onto the stack. else if stack.top is a "while" block and line updates stack.top's loopVariable Update the blockComplexity of stack.top. Ignore line. while size of stack > 1 oldTop stack.pop() oldTopComplexity = total complexity of oldTop if old TopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = oldTopComplexity Return stack.pop().
Expert Answer:
Answer rating: 100% (QA)
Heres the Java code translation of the provided pseudocode l... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
4. Given below is the Component Matrix which is a part of the output from SPSS after doing Factor Analysis. Component Matrixa Component 1 2 Age in years 0.790 0.213 Level of education 0.067 0.884...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
When my niece Michelle told me she had learned to read, she was bursting with pride. How might reflecting on this accomplishment affect how Michelle thinks about herself?
-
What is food insecurity and how does it relate to human population, poverty, and world hunger?
-
Apple Inc. (AAPL) designs, manufactures, and markets personal computers and related software. Apple also manufactures and distributes music players (iPod), mobile phones (iPhone), and smartwatches...
-
Select a large, well-known company and access its annual report online. In the annual report of the company you have chosen, find the four basic financial statements and the notes to the financial...
-
Celestial Artistry Company is developing departmental overhead rates based on direct-labor hours for its two production departments, Etching and Finishing. The Etching Department employs 20 people...
-
7. [0.5!1.5 Points] DETAILS PREVIOUS ANSWERS ROLFFM8 7.2.026. MY NOTES ASK YOUR TEACHER PRACTICE ANOTHER A contestant draws a sequence of three cards, one question per card, and tries to answer the...
-
The set of mobile gaming apps in which the number of monthly users was greater than 12 million. Use the following table, which shows the number of monthly users, in millions, for the 10 most used...
-
Fields Company has two manufacturing departments, forming and painting. The company uses the weighted-average method of process costing. At the beginning of the month, the forming department has...
-
The base of the sales tax is either sales proceeds or gross receipts. In general, discuss whether the following are included or excluded from the sales tax base: Returns and allowances Bad debts ...
-
Define nexus. What is the minimum nexus standard for sales and use tax purposes? After reviewing the U.S. Supreme Court cases mentioned in this chapter, do you think that the Courts opinion has...
-
Brookes Ltd is a market research company providing data to consumer goods companies about the markets in which they operate. In order to tender for a contract, they have undertaken some initial...
-
Does a reading of the Courts opinion suggest that the nexus standard for sales tax imposition is different from the nexus standard for use tax collection obligation?
-
Smart Sports has relied on its own staff to manage all aspects of its business. However, it has grown sufficiently large to consider how best to manage certain support functions. Sam is considering...
-
Wormwood, Ltd.. produces a variety of furniture products. The planning committee wants to prepare an aggregate plan for the next six months using the following information. Problem MONTH 1 2 3 4 5 6...
-
Research an article from an online source, such as The Economist, Wall Street Journal, Journal of Economic Perspectives, American Journal of Agricultural Economics, or another academic journal. The...
-
Bev and Ken Hair have been married for 3 years. They live at 3567 River Street, Springfield, MO 63126. Ken is a full-time student at Southwest Missouri State University (SMSU) and Bev works as an...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-4. Ivan and Irene paid the following in 2012 (all by check or can otherwise be...
-
In 2012, Michael has net short-term capital losses of $2,000, a net long-term capital loss of $45,000, and other ordinary taxable income of $45,000. a. Calculate the amount of Michael's deduction for...
-
WorldCom changed its name to MCI. Go to www.CFO.com and enter the words extreme makeover into the search box. From a review of the article, identify the major steps the new CFO carried out to fix...
-
A tree with eight vertices, exactly two of degree three. Draw a graph with the given characteristics.
-
A connected graph with eight vertices, exactly two of degree 3 , which is not a tree. Draw a graph with the given characteristics.
Study smarter with the SolutionInn App