Likes

NIIT Lab@Home 3 ACPC

1. Bryan is an employee of Simple System Solutions Inc. He works on the Windows platform. He notices that some of his computer applications take a long time to execute. In addition, his computer's hard disk responds in an unreasonably slow manner while retrieving data. Sometimes, Bryan finds that data files get corrupt when he tries to access the same from the hard disk. How will you help Bryan in troubleshooting the problems?

To troubleshoot the stated problems, you need perform the following tasks:
Task 1. Use the Disk Cleanup utility to free up disk space.
Task 2. Defragment the C: drive.

Task 1. Use the Disk Cleanup utility to free up disk space.
let us now Use the Disk Cleanup utility to free up disk space.
1. the Windows+I click.
2. Click the search charm.
3. type disk cleanup in the Apps text box, and then click the SUBMIT button to continue.
4. click setting.
5. click in the empty area of the screen.
6. click the free up disk space by deleting unnecssary files app in the search results.
7. select the offline webpages, Recycle Bin, and setup log files check boxes.
8. click the scroll down button.
9. select the Temprorary file and per user archived windows error report check boxes.
10. click the ok button.
11. click the delete files button.


Task 2. Defragment the C: drive.

1. click the search charm.
2. type defragment in the Apps text box, and then click the SUBMIT button to continue.
3. Click setting.
4. select the Deframnt and optimize your drives app in the search result.
5. click the otimize button.
6. click the close button after the defragmentation is complete.

2. Alex works as a PC technician at Contoso technologies. The company has purchased 20 new systems. All these systems have the Windows 8 operating system installed. Now, the IT Manager wants these computers to be added to the company network so that the employees can access shared resources, such as printers and databases. In addition, the IT Manager wants that the Network Administrator should be able to control the security settings and resource permissions for all the computers from a central server. You have been assigned the task to provide solutions for the preceding requirements. How will you accomplish the same?

To accomplish the desired objectives, you need to add the computers to the company domain.
Let us now add a computer to the company domain.

1. Click the search charm.
2. Click setting.
3. type system in the setting text box, and then click SUBMIT button to continue.
4. Click the system app in the search results.
5. click the change setting link.
6. click the change butting.
7. select the Domain option.
8. typr contoso.com in the text box below the Domain option, and then click the SUBMIT button to continue.
9. click the ok button.
10. type user name, such as administrator, in the user name text, box, and then click the SUBMIT. button to continue.
11. Type password@123, in the password text box, and then click the SUBMIT button to continue.
12. click the ok button.
13. click the ok button.
14. click the ok button.
15. Click the close button.
16. Click the Restart now button.
17. click the lock screen.
18. Click the switch user button.
19. click the other user icon.
20. type domain name\user name, such as contoso\administrator in the user name, text box, and then click the SUBMIT button the continue.
21.  type password, such as password@123 in the password text box, and then click the SUBMIT button to continue.
22. click the submit button.
23. click the Desktop tile.

3. Alex Francis works in an e-learning development company. He reports to the Network Administrator of the company that he is unable to connect his computer to the local network as well as to the Internet. He needs to access the www.niit.com website for some course-related information. The Network Administrator rules out general network and server errors because other users are able to connect to the network. What steps will you perform to troubleshoot the problem and connect Alex's computer to the local network as well as to the Internet?

To solve the stated problems, you need to perform the following tasks:
task 1. Check the satus of the network adapter.
task 2. View the TCP/IP confoguration of the network adapter.
task 3. Tast network connectivity.
task 4. Release and renew the IP configuration.
task 5. Verify the TCP/IP properties of the network adapter.

task 1. Check the satus of the network adapter.
1. Click the setting charm.
2. click control panel.
3. click the Network and internet link.
4. click the network and sharing center link.
5. click the Ethernet link.
6. click the close button.
7. close the network and sharing center window.


task 2. View the TCP/IP confoguration of the network adapter.

1. click the search charm.
2. type cmd in the apps text box, and then click the sumit button to continue.
3. click the command prompt app in the search results.
4. type ipconfig /all at the command prompt, and then press the enter key.


task 3. Tast network connectivity.

1. type ping 192.168.1.10 at command prompt,and then press the enter key.
2. type ping 192.168.1.2 at the command prompt, and then press the enter key.
3. type ping 192.168.1.1 at the command prompt. and then press the enter key.
4. type ping www.niit.com at the command prompt, and then ress the enter key.


task 4. Release and renew the IP configuration.

1. type iconfig / release at the command prompt, and then press the enter key.
2. Type ipconfig /renew at the command prompt, and then press the enter key.
3. close the adminitrator: command prompt window.


task 5. Verify the TCP/IP properties of the network adapter.

1. clcik the settings charm.
2. click conrtol panel.
3. click the network and internet link.
4. click the Network and charing center link.
5. click the change adapter setting link.
6. select properties.
7. click the scroll down button.
8. click the properties.
9. click the ok button.
10. click the close button.
11. close the network commection window.
12. close the network and sharing center window.

4. Praxis Corp. is an IT organization that frequently implements new hardware and software technologies to fulfill the latest requirements of its customers. For this, the management of the company often decides to upgrade the computer systems. As a result, some of the hardware components need to be replaced. These replaced hardware components must be properly managed and disposed of to ensure minimum risk of environmental damage. You have been assigned the task to device an appropriate solution for the preceding challenges. How will you accomplish the task?

Identifying Green ways of Disposing E-waste

Computer components can be difficult the dispose of. A number of computer components, such as CMOS battery.
cannot be easily disposed of. you need to task extreme precaution ans disose of computer components as per
the guidelines suggested by the manufacturer.
Computer components can be either disposed of or recycled. Depending on the type of computer component, you
need to task appropriate actions. For example, a monitor can be recyled by the computer manufacturer However, a CMOS
bettery cannot be recycled. therefore it needs to be properly disposed of.

Disposing computer Components

The life cycle of computer componenets is usually less then two years. thereafter. the parts become obsolete and are usually
discaeded. these obsolete computers, when dismantled. genrate E-waste in the form of hundreds of componenets.
Heavy metels, such as mercury and lead. and other toxic compounds in the e-waste to get into the environment and create health
problems, such as cancer. A proper way to dispose of E-waste is to drop it in specific E-Wastecollection centers set up by the
govemment agencies of equipment manufacturers. you can also donate them to some educational organizations where students can work
on these computer. the educations and Non-Govermmental Organizations (NGOs) do not require high-end equipment as compaered of those of
compared to those of companies. therefore, large companies donate old equipment to such organizations.

the united states Envinment protcation Agency (US EPA) encourages recycling and reusing of used electronic products by imposing less strigent
regulations for recycled and reused products. in contrast, the products disposed of in a hazardous manner face stingent regulations. in several
state that either the manufacturers provision for recovery programs are mandatory. in the US, the E-Waste laws state that either the manufacturers
provision for recycling programs or specifie items are not considered trash.

The European Umon and a few states in the Umted States, through legislation have made manutecturers of electronic equipment
responsible foe the recycling of these products. organizations must ensure that the their e-waste disposal process is in
accordance with the local laws and regulations to related to the disposal of e-waste some of the green disposal considerations for computer components are:
1. Laptop batteries deserve extra considerations while being disposed of as they contain toxic elements that are harmful to human health
   some electronic stores offer battery recycling programs.
2. Printer components, such as cartridges toner and ribbons deserve extra caution during disosal as they may contain residual ink particles. the priter ink
   particles may contain harmful chemicals and may be inflammable. Reusable cartridges and toners should be used to reduce wastage.
3. The disposal of CRL monitors is federally regulated because of the amount of lead they contain Disposing of more then a certain amount of CRL monitors
   can become costly because of the documentating required. state environmental laws also come into factor into disposal decisions and costs.

5. Acme Corp. is an IT organization that is facing stiff competition from its competitors. To succeed in such a competitive environment, the organization needs to ensure that it spends a minimum amount of resources on: Infrastructure investment Electrical power Operating expenses In addition, the organization wants to implement an environment-friendly solution as a social gesture. The Administrator of the organization has been assigned the task to find an appropriate solution to meet the preceding requirements. How will the Administrator accomplish the task?

Understanding Virtualization

Virtualization is a technology that helps in adstracting computer resources in a virtual form. It creates an
environment similar to a host mechine. It helps in saving both, hardware and software resources, by utilizaing the
same resource usedby the host machine. in virtualization, when you abstract the hardware resource by using an
application, the hardware resources become available to another computer that the runs the virtual state.
Virtualization is achieved by using an application or technology, such as VMware Workstation. virtual BOX, or
Hyper-V.

The virtual form of a computer is known as a virtual machine. A virtual machine operates like a physical
machine, but dose not require its own separate physical hardware. Depending on the hardware resources, such as
microprocessor, memory, and haed disk space, you can run multiple virtual mechine within a single physical
computer. therefore, depending on the hardware capabilities of a physical machine or a host machine, you may
be able to run a single vitual machine or simultaneously run multiple vtual machine on a comuter.

To understand this concept better. consider an example. Assume that you have a computer that has 8 GB of
RAM 500 gb of haed disk space, and a network adapter card. you run a client operating system, such as
Windows 7, on this computer, Now, you need to experiment with Linux. In the absence of vtialization. you can
format the existing Windows insallation and insall Linux or dual-boot with Windows and Linux Dual-bool
can enable you to have two or more operating systems on a single computer, but you can run only one of these
operating systems at a time.

However, by using vitualazation siftware, such as vitual box, you can run Linux in a vitual machine within Windows.
Vitualazation helps in green computing because only one physical computer consumes electical energy. Vitual machine
utilize resources from the physical machine, and therfore, do not require a separate energy channel to
be powered on. Due to this, large enterprises have turned to vitualizaion and converted their phusical servers
into vitual machines. Virtualization privider the following key benefits:


1. Reduced space requirements: Virtualization allows organization to consolidate multiple physical machines
   into a single physical machine. As a result, organization require less space for setting up comuters.
2. Optimal resource usege: Virtualization can lead to a better usage and distribution of computing resources
   among users. in case of multiple physical machine, the computing resources of each physical machine may
   not be used completely.
3. Energy conservation: Virtualization can lead to reduction in energy demands due to reduction in the amount
   of physical hardware component. the vitual machine. which are simulated on a physical machine. do not
   require any additional power. therefore multiple users can be supported by a single physical machine, with
   lessr power requirements. In case of multiple physical machine, each machine would require a separate
   power supply, and therefore, More power would be consumed pen user.
4. Consolidation of consolidation: Consolidation of servers is the process of adding multiple servers on a single host.
   for example, you can add vitual machine that act as a printer server, a Wab server a file server, and an
   email server on a single physical host. the consolidation of server also helps in consolidation multiple
   Underutilized servers on to a single, High-end, physical host.

NIIT Lab@Home 2 ACPC

1. John's parents and his brother, Brian, often use his computer to browse the Internet or to play games. John finds that while using the computer, his parents or brother often change the settings that he has configured to personalize the computer. He also does not want them to access or modify his personal files or folders. In addition, he wants to associate an image and a password with his user account.

To accomplish the stated objectives, you need to perform the following tasks:
Task 1. Create separate user acceunts for john's parents and brother.
Task 2. Manage the user account.

Task. 1. Create separate user acceunts for john's parents and brother.
Let us now create separate user account for john's parents and brother.

1. Click the setting Charm.
2. the change PC setting.
3. click the Users tab.
4. click the Add a user button.
5. Type Brlan in the User name text box, and then click the Submit button the cotinue.
6. Type Password@123 in the User name text box, and then click the Submit button the cotinue.
7. Type Password@123 in the Reenter password text box, and then click the Submit button the cotinue.
8. Type Password in the password hint text box, and then click the Submit button the cotinue.
9. click the Next button.
10. click the Finish Button.

Task 2. Manage the user account.
Let us now change the account picture.
1. click the personlize tab.
2. click the Account picture link.
3. click the Browse button.
4. select the desired picture.
5. the Chose the picture.
Let us change the account password.
1. The start.
2. the Alt+Ctrl+Delete.
3. click change a password.
4. Type password@123 in the Old password text box, and then click the SUBMIT button to continue.
5. type pass@123 in the New password text box, and then click the SUBMIT button to continue.
6. type pass@123 in the confirm password text box, and then click the SUBMIT button to continue.
7. click the submit button
8. click the ok button.
9. the start screen.
10. click the Desktop tile.

2. John has installed the Windows operating system on his computer. After installation, when he turned on the computer, he saw that the user interface of the operating system has been configured with the default settings. After using the computer for some time, he decided to customize the user interface according to his preferences. As part of the customization process, he decides to change the look and feel of the operating system. Help John to accomplish the desired tasks.

To customize windows, you need to perform the following tasks:
Task 1. Change the desktop background image.
Task 2. Change the color of window borders.
Task 3. Apply a screensaver.

Task 1. Change the desktop background image.
Let us now Change the desktop background image.
1. selectPersonlize.
2. Click the deskto Background link.
3. select the first image under the flowers section.
4. click the dror-down button of the change picture every drop-down list.
5. select the 5 Minutes option.
6. click the save the change button.
7. close the personallzation window.

Task 2. Let us now change the color of window borders.
1. Right-click an empty area on the desktop.
2. select personalize.
3. the personalization window is displayed.
4. click the color link.
5. the color and Appearance window is displayed.
6. select the sixth color in the first row of colors
7. click the save change button.
8. close the personalization window.

Task 3. Let now apply a screensaver.

1. Right-click an empty area on the desktop.
2. select personalize.
3. click the screen saver link.
4. the screen saver settings dialog box is displayed.
5. click the drop down list under the screen saver section.
6. select the 3D text option.
7. click the ok button.
8. close the personalization window. 

3. John's computer is always connected to the Internet. Recently, he noticed that the Internet download speed of his computer has slowed down considerably. On doing a little research on his computer, he found that there are many applications on his computer that continuously connect to the Internet, and upload and download information. Therefore, John decides to block these applications from connecting to the Internet. In addition, he decides to enable the automatic software update service to ensure that his computer is patched with critical updates and protected against the latest security threats. Help John accomplish the desired objectives.

To accomplish the desired objectives, you need to perform the following tasks:
Task 1. Configure windiws firwall.
Task 2. Configure windows update.

Task 1. Configure windiws firwall.
let us now Configure windiws firwall.
1. clcikthe seach charm.
2. click setting.
3. Type windows firewall in the setting text box, and then click the SUBMIT button the continue.
4. click the wondows firewall app in the seaech results.
5. click the turn windows firewall on or off link.
6. select the vlock all incoming connection, including those in the list of allowed apps under the public network setting section.
7. click the ok button.
8. close the windows firewall window.

Task 2. Let us now configure windows update.
1. the Windows_I click.
2. click the search charm.
3. click setting.
4. type windows Update in the setting text box, and then click the SUBMIT button the continue.
5. click in an empty area of the screen.
6. click the turn automatic updating on or off app in the setting search list.
7. click the drop-down in the important updates section.
8. select the check for updates but let me choose whether to download and install them option.
9. click the ok button.

NIIT Lab@Home 1 ACPC

1. Steve is a college graduate who has just joined as a trainee in the Technical Support department of a large organization. The organization is considering to upgrade the desktop computers used by employees. Therefore, Steve's supervisor has asked him to perform a market research and create a report that compares the specifications of the following hardware components from various vendors: Microprocessors RAM modules Hard disks Motherboard Help Steve to perform the desired task.

The following table lists the latest microprocessors from Intel and AMD.

                    Intel microprocessors

i7 Extreme processor
Features                                 Specification
1. Number of cores                           6
2. Number of threads                         12
3. clook speed                               3.5 Ghz
4. Internal cache                            15 MB
5. Data bus                                  64-bit
6. Max memory size                           64 GB
7. Memory type                               DDR3-1066/1333/1600
8. Memory bandwidth                          51.2 GB/s
9. Expansion option                          PCIe 2.0
10. Socket support                           FCLGA2011

                     AMD microprocessors


Features                                 Specification
1. Number of cores                            8
2. Clock speed                                4.2 Ghz
3. L2 cache                                   8 MB
4. L3 cache                                   8MB
5. Memory type                                DDR3-1333/1866
6. Expansion option                           PCIe 2.0
7. Socket suttort                             AM3+938-pin organic micro pin grid array (micro-PGA)

The following table lists the latest RAM modules modules from Kingston and Transend.

                         Kington RAM
HyperXBlu

Features                                 Specification
1. Caacity                                   Upto 16GB
2. Frequency                                 DDR2 up to 800MHz, DDR3,1333MHz- 1600MHz

                       Transcend RAM

Features                                 Specification
1. Capacity                                  Uto 16GB
2. Frequency                                 DDR3: 1333MHz-1600 MHz


The following table lists the latest hard disks from seagate and western Digital.

                       Seagate
ST4000DM000

Features                                 Specification
1. Capacity                                  4TB
2. Data transfer rate                        6GB/s
3. form factor                               3.5 inches

                      Western Digital

Black

Features                                 Specification
1. Capacity                                  4TB
2. Data transfer rate                        6 GB/s
3. from factor                               3.5 inches



The following table lists the latest motherboards from ASUS Intel.

                   ASUS

SABERTOOTH X79

Features                                 Specification
1. Chip Manufacturer                        Intel
2. Chipset                                  X79 Express
3. Form factor                              ATX
4. No.of PCIe slots                         4
5. Processor socket                         LGA-2011
6. Processor suppoted                       Intel i-7
7. No. of SATA interface                    8
8. No. of expansion slots                   6
9. No. of USB 3.0 Ports                  
10. No. of USB 2.0 Ports                    6
11. No of memory slots                      8
12. Memory technology                       DDR3 SDRAM
13. Audio                                   7.1

                    Intel

Desktop Board DX79SR
Features                                 Specification
1. Chip Manufacturer                        Intel
2. Chipset                                  X79 Express
3. Form factor                              ATX
4. No.of PCIe slots                         4
5. Processor socket                         LGA-2011
6. Processor suppoted                       Intel i-7 Extreme edition
7. No. of SATA interface                    8
8. No. of expansion slots                   6
9. No. of USB 3.0 Ports                     4
10. No. of USB 2.0 Ports                    14
11. No of memory slots                      8
12. Memory technology                       DDR3 SDRAM
13. Audio                                   10-channel (7.1+2 independent multi-streaming) audio subsystem

Java Lab_14_Ans_3

3. Write a Java main that creates a PathMatcher class and uses FileVisitor to recursively delete a file or directory pattern.

SOLUTION


1. Open the project RecursiveOeleteExercise m the practices director.-.
2. Expand the Source Packages folders.
3. Open the Delete .java class file. This is the class that contains the nain method. The mam class accepts two arguments: the first is the starting path and the other the pattern to delete.
4. You must code the remainder of this class. Look at the comments for hurts as to what to do.
a. Start by creating a PathMatcher object from tire search string passed in as tire second argument. To obtain a PatW’atcher instance, you will need to use tire FileSystems class to get a path matcher instance from tire default file system.
b. Create a Path object from tire first argument.
c. If tire starting path is a file, check it against tire pattern using tire PatW’atcher instance that you created. If there is a match, delete tire file, and then terminate tire application.
d. If tire starting path is a directory, create an instance of tire CeleteFile-ree With the Startmg directory and tire Pathllatcher object as initial arguments in tire constructor. Pass tire startmg directory and the file tree to a Files..isl<=ile7ree method to recursively look for the pattern to delete.
e. Fix air.- missing unports.
f. Save the Delete class.
5. Open the Delete'ileTree class file. This class unplements 'ileVisitor. This class recursively looks for instances of files or directories that match the Psth'iatcher object passed into the constructor. This class is complete with the exception of the delete method.
a. The delete method is called by the preVisitDirectory and
vis it File methods. You must check whether the file or directory reached by these methods matches the pattern.
b. We only want to match the path name at the node, so use the Path. getFile'Jane method to obtain the file name at the end of the full path.
c. If the name matches, use the Files, delete method to attempt to delete the file pattern and print a result statement, or print an error if an lOExcepticn is thrown.
d. Save the CeleteFileTree class.
6. Run the Delete application using a temporary directory.
a. For example, if you completed the first practice, you can delete all the Java class files from the D:\Tenp directory.
b. Right-click the project and select Properties.
c. Click Run and enter the following in the Arguments text field: D:\Tenp\exanples ♦.class
d. Run the project.

Java Lab_14_Ans_2

2. Write Java classes that use the FileVisitor class to recursively copy one directory to another.



SOLUTION


1. Open the project RecursiveCopyExercise in the directory D:\labs\ll-NI0.2\practices.
2. Expand the Source Package* folder and subfolders and look at the Copy, java class.
a. Note that the Copy, java class contains the mair method.
b. The application takes two arguments, a source and target paths.
c. If the target file or directory exists, the user is prompted whether to overwrite.
d. If the answer is yes (or the letter y). the method continues.
e. An instance of the CopyFileTree class is created with the source and target.
f. This mstance is then passed to the walkFileTree method (with the source Path object).
You will need to prcrnde method bodies for the methods in the CopyFileTree. java class.
3. Open the CopyFileTree. java class.
a. This class unplements the 'ileVisitcr interface. Note that FileVisitcr is a generic interface, and this interface is boxed with the Rath class. This allows the interface to denne the t>pe of the arguments passed to its methods.
b. The CopyFileTree implements all the methods denned by FiieVisitor.
c. Your task is to write method bodies for the oreVisitDirectory and visitFile methods. You will not need the po;tVi; it Directory method. and you have been provided a method body for the visitrileFailed metliod.
4. Write tlie metliod body for preVicitDirectory. This metliod is called for the starting node of tlie tree and every subdirectory. Therefore, you should copy tlie directory of tlie source to tlie target. If tlie file already exists, you can ignore that exception (because you are domg tlie cops- because tlie user elected to overwrite.)
a. Start by creatmg a new directors- that is relative to tlie target passed in. but is tlie node name from tlie source. The metliod call to do this is:
Path newdir = target.resolve(source.relativi:e(dir));
b. In a try block cops- tlie directors- passed to tlie oreVicitDirectory metliod to tlie newdir that you created.
c. You can ignore any File Already Exacts Except ion thrown, because you are overwrituig any existmg folders and files in tins cops-.
d. Catch air.- other IOExcepticnc. and use the 51CIP_SUBTPEE return to avoid repeated errors.
5. Write tlie metliod bods- for tlie /isitFiie metliod. This metliod is called when tlie node reached is a file. The file is passed as an argument to tlie metliod.
a. As with tlie preVisitOirectory. you must rationalize tlie file reached (source path) with tlie path that you wanted for tlie target. Use tlie same metliod call as above (only usmg -ile instead of dir):
b. As m the sreVisitDirectory method use the 'iles.copy method in a try block. Mala sure that you pass 3EPLACE_EXISTING m as an option to overwrite air.- existing file in the directory.
c. Catch air.- lOExceptico thrown and report an error.
d. Fix air.- missing unports.
e. Save your class.
6. Test your application by copymg a directory (ideally with subdirectories) to another location on the disk. For example, cops- the D: \labs\ll-NI0.2 directory to D: \Temp.
a. Right-click the project and select Properties.
b. Click Run.
c. Enter the following as Arguments:
D:\labs\ll-NI0.2 D:\Terp
d Click OK.
7. Run the project and you should see the follow mg message:
Successfully copied D:\labs\ll-NI0.2 to D:\Tenp
a. Run the project agaui and you should be prompted:
Target directory exists, ^.-erv.rite existing files? (yes/oo):

Java Lab_14_Ans_1

1. Use the Files. readAllLines method to read the entire contents of two files: a form template, and a list of names to send form letters to. After creating a form letter with a name from the name list, you will use the Files, write method to create the custom letter. You will also use the Pattern and Matcher classes that you saw in the "String Processing" lesson.


SOLUTION


1. Open the file FornTerplate in the resource: director.-.
Note that this is a form letter with a string <NAHE> that will be replaced by a name from the name list file.
2. Open the file NamesList.txt in the resources directory.
a. This file contains the names to send the form letters to.
b. Add your name to the end of the list.
c. Save the file.
3. Open the project ForntetterM-iier in the practices directory.
4. Expand the FornietterKricer class. Notice that this class contains the mam method, and that the application requires two parameters: One is the path to the form letter template, and the second is the path to the file containing the list of names to substitute in the form letter.
a. After checking for a valid number of arguments, the mam method then checks to see whether the Path objects point to valid files.
b. The mam method creates an instance of the FilcMerge class with the form letter Path object and the list of names =ath object.
c. In a try block the mam method calls the write! lergedF©™ method of the FileMerge class. This is the method that you will write in this practice.
5. Expand the FileMerge class.
a. Note the write!tergedForns method is empty. This is the method that you will write m this practice.
b. The merge Name method uses the Pattern object defined in the field declarations to replace the string from the form template (first argument) with a name from the name list (second argument). It returns a Strmg. For example, it replaces "Dear <MAME>,” with "Dear Wilscn Ball,”.
c. The naiToker method returns a boolean to indicate whether the string pa»>ed m contains the token This is useful to identify which string has the token to replace with the name from the name list.
6. Code the writeMergedForms method. The overall plan for this method is to read in the entire form letter, line by line, and then read in the entire list of names and merge the names with the form letter, replacing the placeholder in the template with a name from the list and then writing that out as a file. The net result should be that if you have ten names m the name list, you should end up with ten custom letter fries addressed to the names from the name list. These ten files will be written to the resources director.-.
a. Read in all of the Imes of the form letter into the -ormLet-er field, and all of the Imes from the name list into the nans List field.
Note: Because i%rite!lergedForni throws IC€xcepticn. you do not need to put these statements into a try block. The caller of this method is responsible for handlmg air.- exceptions thrown.
b. Create a ■'or loop to iterate through the list of names (nareList) strings.
c. Inside this for loop, create a new List object to Isold the strings of the form letter. You need tins new Lis-: to hold the modified form template strings to write out.
d. Still inside the -or loop, you will need to create a name for the custom letter. One easy way to do this is to use the name from the name list. You should replace air.- spaces in the name with underscores for readability of the file name. Create a new Path object relative to the form template path.
e. Create another -or loop, nested in the first loop, to iterate through the lines of the form template and look for the token string
(" NAME ”) to replace with the String name from the naneList. Use the haiTo<en method to look for the String that contains the token string and replace that string with one containing the name from the naneList. Use the mergeNane method to create the new String. Add the modified String and all of the Other Strings from the -ormLerser to the new custonLetter List.
f. Still inside the first ■'or loop, write the modified List of Strings that represents the customized form letter to the file system by using the 'lies...rite method. Prmt a message that the file write was successful and close the outer for loop.
g. Save the File!-«rge class.
7. Modify the FomLetterUriter project to pass the form letter file and the name list file to the mam method.
a. Right-click the project and select Properties.
b. Select Run.
c. In the Arguments text field, enter:
D:\labs\resources\=or«n7emplane. tx« D:\labs\resources\NamesList.txt
d. Click OK.
S. Run the project. You should >ee new files created with the names from the name list. Each file should be customized with the name from the name list. For example, the Tcm_McGinn.txt file should contain:
Dear Ton McGinn,
It has ccme to our attention that you would like to prove your lava Skills. May we reconnend that you consider certification fron Oracle? Oracle has globally recognised Certification exans that will test your lava krsowlesge and skills.
Start with the Oracle Certified lava Associate exam, and then continue to the Oracle Certified lava Prograrner Professional for a ccrrplete certification profile.

Java Lab_12_Ans_3

Write a Java program to perform the following tasks:
• Reading a text file
• Writing in a text file
• Searching in a text file

solution

1. Create a Java application. Chapter10_Exercise03.
2. Create a class. FileOperation. in the Java application. Chapter10_Exercise03.
3. Replace the existing code in the FileOperation.java file with the following code:

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Scanner;
public class FileOperation {
public void readFile() {
Scanner sc = new Scanner(System.in);
String fileName;
System.out.print("Enter the text file name that you want to read from the D:\\ drive: "); fileName = sc.nextLine();
try (BufferedReader br = new BufferedReader(new FileReader("D:\\" + fileName + ".txt "))) {
String s;
System.out.println("\nThe " + fileName + " contains the following text:\n");
System.out.println
while ((s = br.readLine()) != null) {
System.out.println(s);
}
} catch (Exception e) {
System.out.println("File does not exists."); menu();
}
}
public void writeFile() {
Scanner sc = new Scanner(System.in);
String fileName, text;
System.out.print("Enter the file name from the D:\\ drive in which you 'want to write: "); fileName = sc.nextLine ();
System.out.print("Enter the text you want to write in the " + fileName + " file: "); text = sc.nextLine();
try {
FileWriter fos = new FileWriter("D:\\" + fileName + ".txt", true);
BufferedWriter bw = new BufferedWriter(fos); bw.newLine(); bw.write(text);
bw.close (); fos.close();
System.out.println("\nThe text has been added in the file");
} catch (Exception e) {
System.out.println("File does not exists"); menu();
}
}
public void searchFileO {
Scanner sc = new Scanner(System.in);
String fileName, text; int counter = 0, flag = 0;
System.out.print("Enter the file name from the D:\\ drive in which you want to search: ");
fileName = sc.nextLine();
System.out.print("Enter the string you want to search in the " + fileName + " file: "); text = sc.nextLine();
try (BufferedReader br = new BufferedReader(new FileReader("D:\\" + fileName + ".txt "))) {
String s;
while ((s = br.readLine()) != null) {
String splitData() = s.split(" ");
{
for (int i = 0; i < splitData.length; i++) if (splitData(i].equals(text)) {
if (splitData(i].equals(text)) {
counter++; flag = 1;
}
}
} catch (Exception e) {
System.out.println("File does not exits"); menu () ;
}
if (flag == 1) (
if (counter == 1) {
System.out.println("\"" + text + "\" has occured " + counter + " time");
} else {
System.out.println("\"" + text + "\" has occured " + counter + " times");
}
} else {
System.out.println("The entered word doest not exist in the file.");
}

public void menu() { int option;
Scanner sc = new Scanner(System.in);
System, out. print In (" \n-----Menu---------") ;
System.out.println("1. Reading");
System.out.println("2. Writing");
System.out.println("3. Searching");
System.out.println("4. Exit");
System.out.print("\nChoose the option: ")
option = sc.nextInt();
switch (option) { case 1:
readFile(); menu(); break; case 2:
writeFile(); menu(); break; case 3:
searchFile();
menu(); break; case 4:
System.exit(0); break; default:
System.out.println("Incorrect menu option");
menu(); break;
}
}
public static void main(String!) args) {
FileOperation fo = new FileOperation() fo.menu();
}
}
4. Compile and execute the Chapter!0_Exercise03 Java application.