Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program simulating a cd Unix command that changes a current directory in an abstract file system. The simulated command takes two path strings

Write a program simulating a "cd" Unix command that changes a current directory in an abstract file system. The simulated command takes two path strings from the command line and prints either a new path or an error. The first path is a current directory. The second path is a new directory. To make it simple let's assume that a directory name can only contain alphanumeric characters. A single dot (".") indicates a current directory, and the two dots ("..") indicate a step to a previous directory, up from the current one. A single forward slash "/" indicates a root directory. Multiple consecutive slashes are treated as equivalent to a single one. The program needs to check that the new directory path is valid without relying on any OS system call such as chdir() for verification, to construct a new path, and print it out. Since it is a simulator, it should be OS-independent. Write a program using Java only. Automated unit tests are a plus.

image text in transcribed

Examples ('#' is a shell prompt in Unix): #mycd / abc /abc # mycd /abc/def ghi /abc/def/ghi # mycd /abc/def .. /abc #mycd /abc/def /abc /abc # mycd /abc/def /abc/klm /abc/klm # mycd /abc/def..... #mycd /abc/def../../.. # mycd /abc/def. /abc/def # mycd /abc/def ..klm ..klm: No such file or directory #mycd /abc/def III / #mycd /abc/def ......: No such file or directory #mycd /abc/def ../gh///../klm/. /abc/klm

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

Identify cultural barriers to communication.

Answered: 1 week ago