Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 20, Problem 20.20PE
Program Plan Intro
Directory size using Stack
Program plan:
- Import the required packages into the program.
- In the Exercise20_20 class,
- In the main() method,
- Read the directory or a file from user.
- Create an object for Scanner to read inputs.
- Call getSize() method to get the size of file or directory and then display the result.
- In the getSize() method.
- Declare and initialize the variable.
- Create an object for Stack.
- Add the file into stack.
- The while loop executes until the stack size. If yes,
- Remove the file from the stack.
- Check whether the directory or file is present. If yes,
- Assign the removed file into “files”.
- The for loop executes until the files. If yes,
- Add the files into stack.
- Otherwise, calculate the size of files or directory.
- Return the files or directory size.
- In the main() method,
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(True/False): Local variables are created by adding a positive value to the stack pointer
(python)
5. Write the python code to create a list inside of another list. The list should contain data like this:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
(Postfix notation) Postfix notation is a way of writing expressions without
using parentheses. For example, the expression (1 + 2) 3 would be writ-
ten as 1 2 + 3 *. A postfix expression is evaluated using a stack. Scan a
postfix expression from left to right. A variable or constant is pushed to the
stack. When an operator is encountered, apply the operator with the top two
operands in the stack and replace the two operands with the result. The follow-
ing diagram shows how to evaluate 1 2 + 3 *.
1.
3
3
9.
12 + 3 *
12 + 3*
12+3*
12 + 3*
12 +3*
scanned
scanned
scanned
scanned
scanned
Write a program that prompts the user to enter a postfix expression and evalu-
ates it.
Chapter 20 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 20.2 - Prob. 20.2.1CPCh. 20.2 - Prob. 20.2.2CPCh. 20.2 - Prob. 20.2.3CPCh. 20.2 - Prob. 20.2.4CPCh. 20.2 - Prob. 20.2.5CPCh. 20.3 - Prob. 20.3.1CPCh. 20.3 - Prob. 20.3.2CPCh. 20.3 - Prob. 20.3.3CPCh. 20.3 - Prob. 20.3.4CPCh. 20.4 - Prob. 20.4.1CP
Ch. 20.4 - Prob. 20.4.2CPCh. 20.5 - Prob. 20.5.1CPCh. 20.5 - Suppose list1 is a list that contains the strings...Ch. 20.5 - Prob. 20.5.3CPCh. 20.5 - Prob. 20.5.4CPCh. 20.5 - Prob. 20.5.5CPCh. 20.6 - Prob. 20.6.1CPCh. 20.6 - Prob. 20.6.2CPCh. 20.6 - Write a lambda expression to create a comparator...Ch. 20.6 - Prob. 20.6.4CPCh. 20.6 - Write a statement that sorts an array of Point2D...Ch. 20.6 - Write a statement that sorts an ArrayList of...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.7 - Are all the methods in the Collections class...Ch. 20.7 - Prob. 20.7.2CPCh. 20.7 - Show the output of the following code: import...Ch. 20.7 - Prob. 20.7.4CPCh. 20.7 - Prob. 20.7.5CPCh. 20.7 - Prob. 20.7.6CPCh. 20.8 - Prob. 20.8.1CPCh. 20.8 - Prob. 20.8.2CPCh. 20.8 - Prob. 20.8.3CPCh. 20.9 - How do you create an instance of Vector? How do...Ch. 20.9 - How do you create an instance of Stack? How do you...Ch. 20.9 - Prob. 20.9.3CPCh. 20.10 - Prob. 20.10.1CPCh. 20.10 - Prob. 20.10.2CPCh. 20.10 - Prob. 20.10.3CPCh. 20.11 - Can the EvaluateExpression program evaluate the...Ch. 20.11 - Prob. 20.11.2CPCh. 20.11 - If you enter an expression "4 + 5 5 5", the...Ch. 20 - (Display words in ascending alphabetical order)...Ch. 20 - (Store numbers in a linked list) Write a program...Ch. 20 - (Guessing the capitals) Rewrite Programming...Ch. 20 - (Sort points in a plane) Write a program that...Ch. 20 - (Combine colliding bouncing balls) The example in...Ch. 20 - (Game: lottery) Revise Programming Exercise 3.15...Ch. 20 - Prob. 20.9PECh. 20 - Prob. 20.10PECh. 20 - (Match grouping symbols) A Java program contains...Ch. 20 - Prob. 20.12PECh. 20 - Prob. 20.14PECh. 20 - Prob. 20.16PECh. 20 - (Directory size) Listing 18.10,...Ch. 20 - Prob. 20.20PECh. 20 - (Nonrecursive Tower of Hanoi) Implement the...Ch. 20 - Evaluate expression Modify Listing 20.12,...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- (True/False): Arrays are passed by reference to avoid copying them onto the stackarrow_forward(Printing a Sentence in Reverse Order with a Stack) Write a program that inputs a line of text and uses a stack object to print the line reversed.arrow_forward(Summing and Averaging Elements in a List) Write a program that inserts 25 random integers from 0 to 100 in order in a linked list object. The program should calculate the sum of the elements and the floating-point average of the elements.arrow_forward
- (JAVA)Almost a priority queue. Design a data structure that supports the followingoperations for almost a priority queue:(i) FindSecondSmallest() which returns the second smallest item in the data structure.(ii) Insert(x) which inserts item x to the data structure.(iii) DeleteSecondSmallest() which removes the second smallest item from the datastructure.Your data structure should implement the operation FindSecondSmallest() in O(1), andthe other two operations in O(log n), where n is the number of elements in the datastructure.Problem 4: Binomial heaps. Let H1 and H2 be two binomial heaps. We would like tomerge H1 and H2 to obtain the binomial heap H and also to find the minimum key in H.A standard approach would be to perform the following sequence of operationsH = Merge(H1, H2);m = Min(H).Alternatively, we may perform the following sequence of operationsm1 = Min(H1);m2 = Min(H2);m = min{m1, m2};H = Merge(H1, H2).arrow_forward(True/False): In 32-bit mode, the last argument to be pushed on the stack in a subroutine callis stored at location EBP + 8.arrow_forward(Version #1) We start with an empty stack and then execute the following commands: push 8 push 4 pop push 2 push 6 pop push 9 pop pop push 6 push 3 dod push 7 push 2 dod push 3 Draw the resulting stack.arrow_forward
- apartmentList is a pointer to the first node in a linked list of nodes. Use this for Parts a, b, and c. Part a. Create an inner class that will hold the following information: the apartment number of the apartment (an int), the number of bedrooms in the apartment (also an int), the current rent of the apartment (a double). Don't forget to include a field for the link! Just create the class itself and the instance variables; you don't need to put any methods into the class.arrow_forward(Don't use C++) Only use Carrow_forwardjava pleasearrow_forward
- Refer to imagearrow_forward(Merging Ordered Lists) Write a program that merges two ordered list objects of integers into a single ordered list object of integers. Function merge should receive references to each of the list objects to be merged and a reference to a list object into which the merged elements will be placed.arrow_forward(Class Average: Writing a Gradebook Dictionary to a JSON File) Reimplement Exercise 9.3 using the json module to write the student information to the file in JSON format. For this exercise, create a dictionary of student data in the following format: gradebook_dict = {'students': [student1dictionary, student2dictionary, ...]} Each dictionary in the list represents one student and contains the keys 'first_name', 'last_name', 'exam1', 'exam2' and 'exam3', which map to the values representing each student’s first name (string), last name (string) and three exam scores (integers). Output the gradebook_dict in JSON format to the file grades.json.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education