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?
-
List the following compounds in order of decreasing acidity:
-
Question 15 o pts At the end of this fiscal year, ABC Company's balance sheet showed $5,489,892 of long term debt, $1,000,000 of common stock account, and $2,674,200 of retained earnings. The company...
-
What questions should the board ask when determining adequate operational reserves for the organization?
-
1. What theories from this chapter are revealed through the case? 2. How did Gores sponsors program facilitate the creation of high-quality relationships among leaders, sponsors, and associates? 3....
-
Royal Gorge Company uses the gross profit method to estimate ending Inventory and cost of goods sold when preparing monthly financial statements required by its bank. Inventory on hand at the end of...
-
Your parents are considering investing in Apple Inc. common stock. They ask you, as an accounting expert, to make an analysis of the company for them. Financial statements of Apple are available...
-
Find the theta notation for the following expression: t(n)= 9n +n! + 2" +n lg n (i) (ii) t(n)= = 1.4.9 +-+-+...+ nnn n
-
An Al alloy airframe component experiences the numbers of cycles n listed in the table below, at stress amplitudes of 280 MPa, then 200 MPa, and then 130 MPa. The N, values (from the Al alloy's S-N...
-
Adger Corporation is a service company that measures its output based on the number of customers served. The company provided the following fixed and variable cost estimates that it uses for...
-
If the expected return on an asset A is 10%, on an asset B it is 8% and on an asset C it is 6%; What is the return on the portfolio made up of 20% of asset A, 35% of asset B and 45% of asset % of...
-
Assume that you own a $100,00 portfolio of corporate bonds. Your portfolio manager believes that interest rates will most likely rise in the coming months. Assuming that his belief comes true, what...
-
OMD Manufacturing reported the following budgeted and actual figures for one of its products: Standard overhead cost per unit (1 hour at $2.50 per hour) $2.50 Actual overhead costs $4,850 Budgeted...
-
Out of 500 people sampled, 80 had kids. Based on this, construct a 95% confidence interval for the true population proportion of people with kids. Give your answers as decimals, to three places < p
-
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...
-
Classify each of the following costs relative to the cost object customer for a clothing retailer: Salesperson wages Store manager salary. Depreciation on furniture and fixtures. Cost of merchandise...
-
Number the following activities from 1 to 5 in the order corresponding to the typical flow of cost in a manufacturing company: Record the transfer of raw materials into production. Record cost of...
-
Complete the following T-accounts: Materials Inventory 320 ? 18,120 250 Wages Payable 9,000 300 Work-in-Process Inventory Finished Goods Inventory 1,000 ? ? 1,500 ? ? 9,000 ? 500 1,200
Study smarter with the SolutionInn App