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. The ABC Company has a simple capital structure. Management wants to substitute $100 million of 0.12 debt for common stock. What effect will the change have on the value of the firm to a zero-tax...
-
An asset has the estimated salvage values for various lives, shown in the table below. For each possible life from 1 to 6 by 1, determine the capital recovery cost for MARR of 8 percent/year. EOY NCF...
-
Piedmont Manufacturing produces metal products with the following standard quantity and cost information: Overhead rates were based on normal monthly capacity of 6,000 machine hours. During November,...
-
The figure depicts Jack - in - the - box: "Jack" is attached inside a box by a spring, as shown. You estimate Jack's mass to be 0 . 4 k g . As so often happens, a sign tells you the spring constant:...
-
1. The university rules allow an F grade to be overridden by any pass grade (A, B, C, D). Now, create a view that lists information about all fail grades that have not been overridden (the view...
-
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...
-
This question illustrates what is known as discount interest. Imagine you are discussing a loan with a somewhat unscrupulous lender. You want to borrow $20,000 for one year. The interest rate is 14.5...
-
6. a) Suppose matrix A is the following product: [1 0 0 1 0 0 51 A = 2 1 0 2 1 0 0 3 1 1 3 1 1 0 For what values of t (if any) are there solutions to Ax = (1, 1, t)? 12 (CO2) (POI)
-
Hemingway Inc. hired Mr. King on December 31st, 2016. Mr. King will retire in 5 years (i.e., on December 31st, 2021) and, at that time, will receive a lump sum payment equal to 2% of his final salary...
-
Reviewing the scenarios given bellow, we need to make sure that independence requirements of APES 110 (Code of Ethics for Profession Accountants) are being met. If not, identify potential threats to...
-
A BGC Office Building was recently sold for P80,000,000. Given the following information: Gross income: factor: 10% Expenses: 40% of effective gross income What is the equity rate or cash-on-cash...
-
How much life insurance does Magdalena have to report as taxable income?
-
The records of Deveraux Company show the following amounts in its December 31 financial statements: Deveraux made the following errors in determining its ending inventory : 1. The ending inventory...
-
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.
-
. For each of these relations, write down all functional dependencies. If there are no functional dependencies among attributes, you must state so. Do not write down trivial functional dependencies,...
-
and b = 3. 7.3a=2*b 8.(5-a)*b <7 9.b
-
What diameter of vertical tube would allow mayonnaise (= 1,200 kg/m3) to flow under its own weight?
Study smarter with the SolutionInn App