Rewrite Programming Exercise 18.28 using a stack instead of a queue. DirectorySize.java, without using recursion. ? 1
Question:
Rewrite Programming Exercise 18.28 using a stack instead of a queue.
DirectorySize.java, without using recursion.
?
Transcribed Image Text:
1 import java.io.File; 2 import java.util.Scanner; 3 4 public class DirectorySize { public static void main(String[] args) { // Prompt the user to enter a directory or a file System.out.print("Enter a directory or a file: "); Scanner input = new Scanner (System.in); String directory = input.nextLine(); 5 10 11 12 13 // Display the size System.out.println(getSize(new File(directory)) + " bytes"); 14 public static long getSize(File file) { long size = 0; // Store the total size of all files 15 16 17 18 19 20 21 22 23 24 25 26 if (file.isDirectory()) { File[] files = file.listFiles(); // A1l files and subdirectories for (int i = 0; files != null & i < files.length; i++) { size +- getSize(files[i]); // Recursive call else { // Base case size +- file.length(); 27 28 return size; 29 30 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 66% (6 reviews)
Program Plan Create a class FileSizeStack Create an object of Scanner class and name it input Create a String object myDirectory and store the directo...View the full answer
Answered By
Mwangi Clement
I am a tried and tested custom essay writer with over five years of excellent essay writing. In my years as a custom essay writer, I have completed more than 2,000 custom essays in a diverse set of subjects. When you order essays from me, you are working with one of the best paper writers on the web. One of the most common questions I get from customers is: “can you write my essay?” Upon hearing that request, my goal is to provide the best essays and overall essay help available on the web. I have worked on papers in subjects such as Nursing and Healthcare, English Literature, Sociology, Philosophy, Psychology, Education, Religious Studies, Business, Biological Sciences, Communications and Media, Physical Sciences, Marketing and many others. In these fields, my specialties lie in crafting professional standard custom writings. These include, but are not limited to: research papers, coursework, assignments, term papers, capstone papers, reviews, summaries, critiques, proofreading and editing, and any other college essays.
My extensive custom writings experience has equipped me with a set of skills, research abilities and a broad knowledge base that allows me to navigate diverse paper requirements while keeping my promise of quality. Furthermore, I have also garnered excellent mastery of paper formatting, grammar, and other relevant elements. When a customer asks me to write their essay, I will do my best to provide the best essay writing service possible. I have satisfactorily offered my essay writing services for High School, Diploma, Bachelors, Masters and Ph.D. clients.
I believe quality, affordability, flexibility, and punctuality are the principal reasons as to why I have risen among the best writers on this platform. I deliver 100% original papers that pass all plagiarism check tests (Turnitin, Copyscape, etc.). My rates for all papers are relatively affordable to ensure my clients get quality essay writing services at reasonable prices.
4.50+
5+ Reviews
14+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Rewrite Listing 18.7, DirectorySize.java, without using recursion. Listing 1 import java.io.File; 2 import java.util.Scanner; 3 4 public class DirectorySize { public static void main(String[] args) {...
-
Show that using a stack instead of a queue in the previous exercise is bad, by giving a sequence that leads to (N) cost per operation. This is the left-to-right single-pass merge.
-
Rewrite Programming Exercise 18.9 using a helper method to pass the substring high index to the method. The helper method header is: public static void reverseDisplay(String value, int high) Write a...
-
Prepare the journal entries for 2, 4, 6, 8, 12 and 14 using the following information 6% bonds $1200000 par value payable in 5 years were issued for cash at 108, any premium is to be transferred to...
-
A conventional assumption in production theory is free disposal, namely y Y y Y for every y < y A technology is said to be monotonic if x V(y) x V(y) for every x > x where x > x means that xi >...
-
A sample of 150 is drawn from a population with a proportion equal to 0.40 and a population size of 400. Determine the probability of observing a. between 50 and 54 successes. b. between 55 and 62...
-
Almost all organisation members will have contact with a variety of internal customers. Identify your internal customers, or those of another member of staff, and design a short questionnaire to...
-
The Manes Company has two products. Product 1 is manufactured entirely in Division X. Product 2 is manufactured entirely in Division Y. To produce these two products, the Manes Company has two...
-
You short 200 contracts of a call option on Stock XYZ. The contract multiplier is 100, i.e. each contract is on 100 shares of the stock. At the time when you take the option position, option premium...
-
Kenneth Washburn, head of the Sporting Goods Division of Reliable Products, has just completed a miserable nine months. If it could have gone wrong, it did. Sales are down, income is down,...
-
Write the following generic method using selection sort and a comparator. Write a test program that creates an array of 10 GeometricObjects and invokes this method using the GeometricObjectComparator...
-
When you pick four cards from a deck of 52 cards for the 24-point game introduced in Programming Exercise 20.13, the four cards may not have a 24-point solution. What is the number of all possible...
-
In Exercise 1.17 on page 9, we discussed the Salk vaccine experiment. The experiment utilized a technique called double-blinding because neither the children nor the doctors involved knew which...
-
2.11.2Project:Performance Task: The Parallax Problem Project Geometry Sem 1 (S3537251) Julio Duenas Points possible:120 Date: ____________ The Scenario:You're looking for a sponsor to pay for you to...
-
If the most common treatment of assigning overapplied overhead was used, the final balance in Cost of Goods Sold would have been * (1 Point) At the end of the last fiscal year, BREAD Company had the...
-
Angelina received new word processing software for her birthday. She also received a cheque with which she intends to purchase a new computer. Angelina's UNILUS Professor assigned a paper due in two...
-
At date t, the portfolio P to be hedged is a portfolio of Treasury bonds with various possible maturities. Its characteristics are as follows: Value YTM MD Convexity $1,450 6% 4.25 55 We consider...
-
A playground merry-go-round with an axis at the center (radius R = 1.3 m and rotational inertia | = 1.2 x 103 kgm2) is initially rotating at angular velocity w = 0.21 rad/s clockwise). A girl of mass...
-
Refer to Exercise 54. a. Explain why the sample results give some evidence for the alternative hypothesis. b. Calculate the standardized test statistic and P-value. c. What conclusion would you make?...
-
Suppose that A is an m n matrix with linearly independent columns and the linear system LS(A, b) is consistent. Show that this system has a unique solution.
-
What is the size of an ARP packet when the protocol is IPv4 and the hardware is Ethernet?
-
Is the current Internet using circuit-switching or packet-switching at the datalink layer? Explain.
-
Assume we have an isolated link (not connected to any other link) such as a private network in a company. Do we still need addresses in both the network layer and the data-link layer? Explain.
-
Please answer both, its the same question but a 2 part answer. Southwest Milling Company purchased a front-end loader to move stacks of lumber. The loader had a list price of $121,930. The seller...
-
Identify the at least two main ways to invest in real estate indirectly in your country. *MY COUNTRY IS UNITED STATES * Distinguish between direct and indirect investments in real estate.
-
Question 1 (Marks: 10) According to IAS33 Earnings per share there are two types of shareholder, namely ordinary shareholders and preference shareholders. Q.1.1 Why do we call them preference shares...
Study smarter with the SolutionInn App