Write a system utility that shows the space used by files within the current wor
ID: 3600622 • Letter: W
Question
Write a system utility that shows the space used by files within the current working directory (see below)
2 Requirements 35 points In this assignment you will write a system utility that displays the space utilized by files within the current working directory. Each file and directory will be displayed, prefixed by the space it takes up. Space will be displayed in a user-friendly format (e.g., B, K, MB). The utility will be recursive in that it lists the space used by files nested within a child directory in the current directory. Your program must compile and run under Xubuntu (or another variant of Ubuntu) 16.04. Sample output Terminal- ruben ruben-VirtualBox:-/NetBeansProjects/CApplication 1 File Edit ViewTerminal Tabs Help ruben@ruben-VirtualBox:-/NetBeansProjects/CApplication_1s /main 163B / 378 12K 438 27K 31K /build/Debug /build/Debug/GNU-Linux/main.o /build/Debug/GNU-Linux/main.o.d /build/Debug/GNU-Linux/newmain.o /build/Debug/GNU-Linux/newmain.o.d /build/Debug/GNU-Linux /build 19K /dist/Debug/GNU-Linux/capplication 1 27K 31K 19K /dist/Debug/GNU-Linux /dist/Debug /dist /main.c /Makefile /nbproject/configurations.xm /nbproject/Makefile-Debug.mk /nbproject/Makefile-impl.mk /nbproject/Makefile-Release.mk /nbproject/Makefile-variables.mk /nbproject/Package-Debug.bash /nbproject/Package-Release.bash /nbproject/private/c standard headers indexer.c /nbproject/private/configurations.xml /nbproject/private/cpp standard headers indexer.cpp /nbproject/private/Launcher.properties /nbproject/private/Makefile-variables.mk 4K 706B /nbproject/private/private.xml 22K /nbproject/private 9768 /nbproject/project.xm 41K /nbproject /newmain. 138K . Specific Requirements:Explanation / Answer
public class theDeque()
{
int maxSize=10; // as mentioned that the size of the deque is 10
int nItems; //no of items in your deque
int left; //key left
int right; //key right
boolean isEmpty() //to check wheather the que is empty or not
{
return nItems == 0;
}
boolean isFull() // to check wheather the que is full or not
{
return nItems == maxSize;
}
/* method to insert left*/
public void insertLeft(long j) {
if (isFull())
throw new RuntimeException("It is full"); // you can omit it also,as it is already in switch statement also.But its a better programming practice
if (left == 0)
left = maxSize; // you can also write is as 10 as declared.But hardcode value is not appreciated in java
theDeque[--left] = j;
nItems++;
/*Method to insert Right*/
public void insertRight(long i) {
if (isFull())
throw new RuntimeException("It is full");
if (right == maxSize - 1)
right = -1;
Deque[++right] = i;
nItems++;
}
/* Method to remove Left*/
public long removeLeft() {
if (isEmpty())
throw new RuntimeException("It is empty");
long temp = Deque[left];
left++;
if (left == maxSize - 1)
left = -1;
nItems--;
return temp;
}
/* Method to remove Right*/
public long removeRight() {
if (isEmpty())
throw new RuntimeException("It is empty");
long temp = Deque[right];
right--;
if (right < 0)
right = maxSize - 1;
nItems--;
return temp;
}
}
You MUST use this main:
public static void main(String[] args) throws IOException
{
Deque theDeque = new Deque(10);
while(true)
{
long value;
System.out.println("");
if( theDeque.isFull() )
System.out.println(
"*** Deque is full. No insertions. ***");
if( theDeque.isEmpty() )
System.out.println(
"*** Deque is empty. No deletions. ***");
System.out.print("Enter first letter of ");
System.out.println("insertLeft, InsertRight, ");
System.out.print("removeLeft, RemoveRight, or display: ");
int choice = getChar();
switch(choice)
{
case 'd':
theDeque.display();
break;
case 'i':
System.out.print("Enter value to insert left: ");
value = getLong();
theDeque.insertLeft(value);
break;
case 'I':
System.out.print("Enter value to insert right: ");
value = getLong();
theDeque.insertRight(value);
break;
case 'r':
value = theDeque.removeLeft();
System.out.println("Removed left: " + value);
break;
case 'R':
value = theDeque.removeRight();
System.out.println("Removed right: " + value);
break;
default:
System.out.print("Invalid entry ");
} // end switch
} // end while
} // end main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.