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 >...
-
Complete a trend analysis from the following data of Hidalgo Corporation using 2020 as the base year. (Round to the nearest percent.) Sales Gross Profit Net Income 2023 $580,000 168,000 48,800 2022...
-
If total monthly fixed costs for a company were plotted on a graph for seven months, would the line drawn between the plotted points be parallel to the base or sloped? Explain why.
-
The following are a list of possible errors or fraud (1 through 5) involving cash receipts and controls (a through g) that may prevent or detect the errors or fraud: Possible Errors or Fraud 1....
-
Chpt 3 question 5 I need the answers for the blanks!
-
Jimmy owns a garden in which he has planted N trees in a row. After a few years, the trees have grown up and now they have different heights. Jimmy pays much attention to the aesthetics of his...
-
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...
-
The following three accounts appear in the general ledger of Herrick Corp. during 2020. Instructions From the postings in the accounts, indicate how the information is reported on a statement of cash...
-
The roof of one of the presentation booths at Expo '86 in Vancouver was in the shape of a right pyramid. The base of the pyramid was a regular hexagon. The length of one side of the hexagonal base...
-
1. The band is breaking up and Rob, Sue, Tim and Vito each want the tour bus. Using the method of sealed bids, Rob bids $4200, Sue bids $5200, Tim bids $5400, and Vito bids $7300 for the bus. Since...
-
A planet has been discovered orbiting the sun - like star HD 2 0 9 4 5 8 . From the period and velocity measured by the Doppler method, its mass was calculated to be 0 . 6 9 times that of Jupiter....
-
Two point charges with q1 = +3.5 10 7 C and q2 = 4.5 10 7 C are initially separated by a distance of r = 2.5 10 4 m. How much energy is required to double their separation and what is the electric...
-
A. Use the following information is from the autarkic state in Home. Home Country WTV = 12 MPLTY = 2 Pry=? B. Now consider the free trade situation. Wear =? MPL car =? Pear = 4 a) You now know that...
-
You have $10,000 to invest in a stock portfolio. Your choices are Stock X with an expected return of 12.4 percent and Stock Y with an expected return of 10.2 percent. If your goal is to create a...
-
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.
-
Suppose you are analyzing a brand new 60-unit apartment complex set to open next fall across the street from the local university. You believe that under current market conditions, you can fully...
-
Martin Enterprises needs someone to supply it with 147,000 cartons of machine screws per year to support its manufacturing needs over the next five years, and you've decided to bid on the contract....
-
An unlevered firm has a value of $ 8 0 0 million. An otherwise identical but levered firm has $ 1 5 0 million in debt. Under the MM zero - tax model, what is the value of the levered firm? Enter your...
Study smarter with the SolutionInn App