<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CS508 Assignment 3 Solution and Discussion Fall 2019]]></title><description><![CDATA[<p dir="auto">Assignment No. 03<br />
Semester Fall 2019<br />
CS508 - Modern Programming Languages	<br />
Total Marks: 20</p>
<p dir="auto">Due Date:16 January 2020<br />
Instructions<br />
Please read the following instructions carefully before solving &amp; submitting assignment:<br />
It should be clear that your assignment will not get any credit if:<br />
•	The assignment is submitted after due date.<br />
•	The submitted assignment does not open or file is corrupt.<br />
•	The assignment is completely or partially copied from (other student, handouts or internet).<br />
•	Student ID is not mentioned in the assignment File or name of file is other than student ID.<br />
•	The assignment is not submitted in .rar format.</p>
<p dir="auto">Submission details<br />
Following Files Must be submitted in a single .zip or .rar file.<br />
•	Code file(s) .java file only<br />
•	A .gif file which shows working of your Application (For Recording .gif a software named Screentogif is uploaded on LMS, or you can use any other gif recording tool as well)<br />
You are not required to submit the complete project, only copy these files from project folder. Please note if you submit doc or txt file you will be awarded 0 marks. Make sure to write your own VU ID in the assignment file(s) otherwise assignment will not be accepted.<br />
If you do not submit any of the above mentioned file 50% marks per file will be deducted.<br />
Objective<br />
The objective of this assignment is to give hands on practice on Java programming language.</p>
<p dir="auto">Lectures Covered: This assignment covers Lecture # 27 – 31</p>
<p dir="auto">Problem Statement:</p>
<p dir="auto">You are required to create a multithreaded java console application which will read a text file and write processed output in another text file.<br />
•	The program will be able to read the text file provided named input.txt using a separate thread.<br />
•	Calculate the number of characters in the file as per your student id.<br />
•	Last number of your student id is the character your program will calculate from the given list below.</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Last Number in ID</th>
<th>Character to calculate</th>
<th>Last Number in ID</th>
<th>Character to calculate</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>!</td>
<td>5</td>
<td>&amp;</td>
</tr>
<tr>
<td>1</td>
<td>@</td>
<td>6</td>
<td>(</td>
</tr>
<tr>
<td>2</td>
<td>#</td>
<td>7</td>
<td>)</td>
</tr>
<tr>
<td>3</td>
<td>$</td>
<td>8</td>
<td>_(Underscore)</td>
</tr>
<tr>
<td>4</td>
<td>%</td>
<td>9</td>
<td>=</td>
</tr>
</tbody>
</table>
<p dir="auto">•	Output the result on the screen.<br />
•	Create a new thread which will create an output file and store the result in that file.</p>
<p dir="auto">Output.gif has been attached with this Assignment file please observe this file carefully your program’s output must be like this output file.</p>
<p dir="auto"><a href="/assets/uploads/files/1578751140975-assignment-no-3.docx">Assignment No 3.docx</a><br />
<img src="https://i.imgur.com/ky8CGqy.gif" alt="output.gif" class=" img-fluid img-markdown" /><br />
<a href="/assets/uploads/files/1578751126724-inputfile.txt">inputFile.txt</a></p>
]]></description><link>https://community.secnto.com//topic/943/cs508-assignment-3-solution-and-discussion-fall-2019</link><generator>RSS for Node</generator><lastBuildDate>Tue, 09 Jun 2026 01:19:03 GMT</lastBuildDate><atom:link href="https://community.secnto.com//topic/943.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 11 Jan 2020 13:59:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CS508 Assignment 3 Solution and Discussion Fall 2019 on Fri, 17 Jan 2020 17:57:10 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://www.youtube.com/watch?v=j4mJTG4sWiU" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.youtube.com/watch?v=j4mJTG4sWiU</a></p>
]]></description><link>https://community.secnto.com//post/2853</link><guid isPermaLink="true">https://community.secnto.com//post/2853</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Fri, 17 Jan 2020 17:57:10 GMT</pubDate></item><item><title><![CDATA[Reply to CS508 Assignment 3 Solution and Discussion Fall 2019 on Fri, 17 Jan 2020 17:45:17 GMT]]></title><description><![CDATA[<p dir="auto">launcher.java Code</p>
<pre><code>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package launcher;

/**
 *
 * @author Accounts
 */
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;


public class Launcher {

  public static void main(String[] args) {

    BlockingQueue&lt;Integer&gt; queue = new ArrayBlockingQueue&lt;Integer&gt;(1024);

    ReaderThread reader = new ReaderThread(queue);
    WriterThread writer = new WriterThread(queue);

    System.out.println("My ID is BS00000000 and special character to read is 'B'");
    new Thread(reader).start();
    new Thread(writer).start();    
    
    
    }

 } 

</code></pre>
<p dir="auto">ReaderThread.java Class code</p>
<pre><code>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package launcher;

/**
 *
 * @author Accounts
 */
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;

public class ReaderThread implements Runnable{

  protected BlockingQueue&lt;Integer&gt; blockingQueue ;

  public ReaderThread(BlockingQueue&lt;Integer&gt; blockingQueue){
    this.blockingQueue = blockingQueue;     
  }

  @Override
  public void run() {
      
      System.out.println("Reader Thread is Started");
      
    BufferedReader br = null;
     try {
            br = new BufferedReader(new FileReader(new File("./inputFile.txt")));
            int buffer =0;
            char match = 'B';
            
            while((buffer=br.read())!= -1){
                
                if ((char)buffer == match){
                blockingQueue.put(buffer);
                }
               
            }
            
            blockingQueue.put(0);  //When end of file has been reached
             System.out.println("Reader Thread ended");
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        } catch(InterruptedException e){

        }finally{
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


  }



}

</code></pre>
<p dir="auto">WriterThread.java class code</p>
<pre><code>
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package launcher;

/**
 *
 * @author Accounts
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.concurrent.BlockingQueue;

public class WriterThread implements Runnable{

  protected BlockingQueue&lt;Integer&gt; blockingQueue;

  public WriterThread(BlockingQueue&lt;Integer&gt; blockingQueue){
    this.blockingQueue = blockingQueue;     
  }

  @Override
  public void run() {
      
      System.out.println("Writer Thread is Started");
      
    PrintWriter writer = null;
    char match;
    int no = 0;
    try {
        writer = new PrintWriter(new File("outputFile.txt"));

        while(true){
            int buffer = blockingQueue.take();
            
            match = (char)buffer;
            no++;
            
            if(buffer == (0)){ 
                break;
            }
            
            writer.println(no);
            System.out.println("'"+match+"'" + " Found so Far :" + no);
            
        }               
        System.out.println("Writer Thread ended");
        System.out.println("Total number of Special character "+"'Blue'"+" in the file are :"+ (no-1));
    } catch (FileNotFoundException e) {

        e.printStackTrace();
    } catch(InterruptedException e){

    }finally{
        writer.close();
    } 

  }


}

</code></pre>
]]></description><link>https://community.secnto.com//post/2852</link><guid isPermaLink="true">https://community.secnto.com//post/2852</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Fri, 17 Jan 2020 17:45:17 GMT</pubDate></item><item><title><![CDATA[Reply to CS508 Assignment 3 Solution and Discussion Fall 2019 on Fri, 17 Jan 2020 16:12:39 GMT]]></title><description><![CDATA[<p dir="auto">Error: Could not find or load main class Cs508bs0000000.Cs508bs0000000</p>
]]></description><link>https://community.secnto.com//post/2851</link><guid isPermaLink="true">https://community.secnto.com//post/2851</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Fri, 17 Jan 2020 16:12:39 GMT</pubDate></item><item><title><![CDATA[Reply to CS508 Assignment 3 Solution and Discussion Fall 2019 on Tue, 14 Jan 2020 10:19:29 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://youtu.be/zeAwdRvkfqI" target="_blank" rel="noopener noreferrer nofollow ugc">https://youtu.be/zeAwdRvkfqI</a></p>
]]></description><link>https://community.secnto.com//post/2658</link><guid isPermaLink="true">https://community.secnto.com//post/2658</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Tue, 14 Jan 2020 10:19:29 GMT</pubDate></item><item><title><![CDATA[Reply to CS508 Assignment 3 Solution and Discussion Fall 2019 on Tue, 14 Jan 2020 10:19:17 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://youtu.be/cBSNINNNru0" target="_blank" rel="noopener noreferrer nofollow ugc">https://youtu.be/cBSNINNNru0</a></p>
]]></description><link>https://community.secnto.com//post/2657</link><guid isPermaLink="true">https://community.secnto.com//post/2657</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Tue, 14 Jan 2020 10:19:17 GMT</pubDate></item></channel></rss>