Problem Statement:                                                        
You are required to write a java program which contains two classesnamed as “Employee” and “Test” and one text file as input.txt.
Note: There should be single java file which contains both classes.
Employee class must have the following data members:
  • empId
  • empName
  • costPrHour
  • salary
Employee class must have the following member methods:
  • Parameterized constructor
  • Getter functions for each data member
Detailed Description:
Parameterized constructor: It should take four parameters (empId, empName, costPrHour, salary) andset the values of data members with the passed parameters.
Getter Functions: You will have to define the getter function for each data member (empId, empName,costPrHour, salary). There will be a separate getter function for each data member. Such as getEmpID(), getEmpName(),getCostPrHour() and getSalary( ).
Input text file contains the Employee data which has three columns and as many rows as you want. First column contains EmployeeempId, second column contains EmployeeempNameand third column contains EmployeeCostprHour. All three columns are separated by space.
1 Ali 100
2 Noman 200
3 waqar 300
4 Toqeer 400
5 Waqas 500

input.txt

Testis a public driver class that contains the main() method. The name of your file should be Test as it is a public class in your program.
Within main() method, you are required to enter the  value of working hours in a week 
and read the Employee record one by one from input.txt file.
Calculate the monthly Salary of each employee based on the working hours in a week and cost per hour.
salary = costPrHour*workinghoursprweek*4;
then display the Employee information (empId, empName, costPrHour, salary) on the command prompt and GUI (Graphical User Interface). You have to display the information in the same format as was in input.txt file.
solution

import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
class employee
{
int empid;
String empname;
int costprhour;
int salary;
public employee()
{
empname = null;
empid =0;
costprhour= 0;
salary = 0;
}

public employee(String n,int i,int c ,int s)
{
empname = n;
empid = i;
costprhour = c;
salary = s;
}
public int getempid()
{
return empid;
}
public String getempname()
{
return empname;
}
public int getcostprhour()
{
return costprhour;
}
public int getsalary()
{
return salary;
}
}

class test
{

  public static void main(String[] args){
FileReader fr = null;
BufferedReader br = null;
ArrayList emp = new ArrayList();
int count =0;
String d = JOptionPane.showInputDialog(null ,"enter number of hours per week:");
int duration = Integer.parseInt(d);
try
{
fr = new FileReader("input.txt");
br = new BufferedReader(br);
String[]tokens;
String line = br.readLine();
while( line != null)
{
tokens = line.split( " " );
String i = tokens[0];
String nm = tokens[1];
String c = tokens[2];
int id = Integer.parseInt(i);
int cost =Integer.parseInt(c);
int salary = cost*duration*4;
employee e = new employee (nm,id,cost,salary);
System.out.println("emp id  : " +id + "name :" +nm + "per hour cst:" + cost + "montly salary :"+ salary);
emp.add(e);
line = br.readLine();
count++;
}
}
catch(IOException e)
{
System.out.println(e);
}
int size = emp.size()+ 2;
JFrame frame = new JFrame();
JLabel l1,l2,l3,l4;
Container c = frame.getContentPane();
frame.setLayout(new GridLayout(size,4));
c.add(new JLabel("employee id"));
c.add(new JLabel("employee name"));
c.add(new JLabel("employee cost per hour"));
c.add(new JLabel("monthly salary"));
for(int i =0;i<emp.size();i++)
{
employee s = (employee)emp.get(i);
l1 = new JLabel (" " + s.getempid());
l2 = new JLabel (" " + s.getempname());
l3 = new JLabel (" " + s.getcostprhour());
l4 = new JLabel (" " + s.getsalary());
c.add(l1);
c.add(l2);
c.add(l3);
}
frame.setSize(400 , 300 );
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}


}


sample output


sample 

Question: 
Write a console application in C# with following requirements:
Program Design Requirements:
It should declare a namespace with name RollNo_Extraction
In the above namespace, it should declare a class with the same name (i.e. name of class should be RollNo_Extraction)
Class should contain an “Extract” method, which should accept a string i.e. roll number. Input from user is passed as argument to this method. Method will extract different information from the roll number.
For Example, if the roll number is 
BC120412345
Here 
BC (first two characters from left) represents enrolled program which Is Bachelor, It can be BC, MC and MS where BC represents BCS, MC represents MCS and MS represents MS program. For any other it should display “Other Program”
12 (3rd and 4th characters from left) represents enrollment year (this value should be greater than or equal to 02 and less than or equal to 15)
04 (5th and 6th characters from left) represents enrolled semester. Here either it would be 02 or 04. 02 represent Spring semester and 04 represents Fall semester
12345 (last 5 characters) represents student unique id.
All the above information can vary as each student have different roll number.
Main function will declare Object of the Class and will call its Extract method by providing student roll number as input to this method. Extract method will then extract the information (Program, Enrollment year, Enrolled Semester and Unique ID) and will return true if the provided roll number is valid along with displaying the extracted information. Otherwise if the provided roll number is invalid, Extract method will return false. Main method will then print the success or failure message on the basis of true/false value returned by Extract method. 
Note: Roll number will be considered invalid if any of the sub-fields in the roll number is invalid.


solution:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
       
        static void Main(string[] args)

        {

            String sub, sub1;
            
            Program obj = new Program();
            string rollno = string.Empty;
            bool test = false;
            Console.Write("Enter Roll no");
            rollno = Console.ReadLine();
            sub = Convert.ToString(rollno.Substring(0, 2));
            if(sub == "BS")
            {
                Console.WriteLine("BCS PROGRAM");
            }
            else if (sub == "MS")
            {
                Console.WriteLine("MS PROGRAM");
            }
            else
            {
                Console.WriteLine("other program" );
            }
            sub1 = Convert.ToString(rollno.Substring(2, 2));
           int sub3 = Convert.ToInt32(rollno.Substring(6, 5));
           int sub2 = Convert.ToInt32(rollno.Substring(4, 2));
            int x = 0;
            x= sub2%2;
            if( sub2 == x)
            {
                Console.WriteLine("spring");
            }
            else{
                Console.WriteLine("Fall");
            }
           


            Console.WriteLine("student rollno is {0}.",rollno );
            Console.WriteLine("program  is {0}.", sub);
            Console.WriteLine("enrollement year is {0}.", sub1);
            Console.WriteLine("enrollemnt sem is {0}.", sub2);
            Console.WriteLine("student unique id is {0}.", sub3);
            test = obj.Extract(rollno);


            if (test)
            {
                Console.WriteLine("success");
            }
            else
            {
                Console.WriteLine("error in result");
            }
            Console.ReadKey();

            Console.WriteLine();
        }
        public bool Extract (String rollno)
        {
            string val = rollno;
            bool check = false;
            if (!val.Substring(0, 2).All(char.IsLetter))
            {
                return false;
            }
            else return true;
            if (!val.Substring(2, 2).All(char.IsDigit))
            {
                return false;
            }
            else
            {
                int num = Convert.ToInt32(val.Substring(2, 2));
                if(num >= 2 && num <= 15)
                {
                    check = true;
                }
                else
                {
                    return false;
                }
            }
            if (!val.Substring(4, 2).All(char.IsDigit))
            {
                return false;
            }
            else
            {
                int num = Convert.ToInt32(val.Substring(4, 2));
                {
                    if(num > 0)
                    {
                        check = true;
                    }
                    else
                        return false;
                }
                return check;
            }

        }
    }
}


Java's System.out.printf function can be used to print formatted output. The purpose of this exercise is to test your understanding of formatting output using printf.
To get you started, a portion of the solution is provided for you in the editor; you must format and print the input to complete the solution.
Input Format
Every line of input will contain a String followed by an integer
Each String will have a maximum of <span class="MathJax" data-mathml="10" id="MathJax-Element-15-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">1010 alphabetic characters, and each integer will be in the inclusive range from <span class="MathJax" data-mathml="0" id="MathJax-Element-16-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">00 to <span class="MathJax" data-mathml="999" id="MathJax-Element-17-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">999999.
Output Format
In each line of output there should be two columns: 
The first column contains the String and is left justified using exactly <span class="MathJax" data-mathml="15" id="MathJax-Element-18-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">1515 characters. 
The second column contains the integer, expressed in exactly <span class="MathJax" data-mathml="3" id="MathJax-Element-19-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">33 digits; if the original input has less than three digits, you must pad your output's leading digits with zeroes.
Sample Input
java 100
cpp 65
python 50
Sample Output
================================
java 100
cpp 065
python 050
================================
Explanation
Each String is left-justified with trailing whitespace through the first <span class="MathJax" data-mathml="15" id="MathJax-Element-20-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">1515 characters. The leading digit of the integer is the <span class="MathJax" data-mathml="16th" id="MathJax-Element-21-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">16th16th character, and each integer that was less than <span class="MathJax" data-mathml="3" id="MathJax-Element-22-Frame" role="presentation" style="border: 0px; direction: ltr; display: inline; float: none; font-family: inherit; font-stretch: inherit; font-variant: inherit; line-height: normal; margin: 0px; max-height: none; max-width: none; min-height: 0px; min-width: 0px; outline: 0px; padding: 0px; position: relative; vertical-align: baseline; white-space: nowrap; word-break: break-word; word-spacing: normal; word-wrap: normal;" tabindex="0">33 digits now has leading z 


   
18
import java.util.Scanner;
19
20
public class Solution {
21
22
    public static void main(String[] args) {
23
            Scanner sc=new Scanner(System.in);
24
            System.out.println("================================");
25
            for(int i=0;i<3;i++)
26
            {
27
                String s1=sc.next();
28
                int x=sc.nextInt();
29
                System.out.printf("%-15s%03d%n", s1, x);
30
            }
31
            System.out.println("================================");
32
33
    }
34
}
35