[text] jcubical

Viewer

copydownloadembedprintName: jcubical
  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6.  
  7. public class Solution {
  8.    public static void main(String[] args) {
  9.         int id,cub;
  10.         String dep,name;
  11.         double sal;
  12.         Scanner sc= new Scanner(System.in);
  13.         Office o[]=new Office[5];
  14.         for(int i=0;i<5;i++)
  15.         {
  16.             id=sc.nextInt();
  17.             cub=sc.nextInt();
  18.             dep=sc.nextLine();
  19.             sc.next();
  20.             o[i]=new Office(id, cub, dep);
  21.         }
  22.         
  23.         Employee e[]=new Employee[5];
  24.         for(int i=0;i<5;i++)
  25.         {
  26.             id=sc.nextInt();
  27.             sc.nextLine();
  28.             name=sc.nextLine();
  29.             sal=sc.nextDouble();
  30.             e[i] = new Employee(id, name, sal);
  31.         }
  32.         int c=sc.nextInt();
  33.         Employee[] esort = sortEmployeeAsceName(e);
  34.         for(int i=0;i<esort.length;i++)
  35.         {
  36.             System.out.println(esort[i].getEmployeeId()+" "+esort[i].getName());
  37.         }
  38.         Employee emp = employeeDetailsBasedOnCubicalNo(o,e,c);
  39.         if(emp==null)
  40.             System.out.println("No one sit on this cubical.");
  41.         else
  42.         System.out.println(emp.getEmployeeId()+" "+emp.getName()+" "+emp.getSalary());
  43.     }
  44.     
  45.     public static Employee[] sortEmployeeAsceName(Employee e[])
  46.     {
  47.         
  48.          Employee temp;
  49.   
  50.         for(int i=0;i<e.length-1;i++)
  51.         {
  52.             for(int j=i+1;j<e.length;j++)
  53.             {
  54.             if(e[i].getName().compareToIgnoreCase(e[j].getName())>0)
  55.             {
  56.                 temp=e[i];
  57.                 e[i]=e[j];
  58.                 e[j]=temp;
  59.                 
  60.             }
  61.             }
  62.         }
  63.             return e;
  64.     }
  65.     
  66.     public static Employee employeeDetailsBasedOnCubicalNo(Office o[], Employee[] e, int c)
  67.     {
  68.             int count=0;
  69.             int p=0;
  70.             for(int i=0;i<o.length;i++)
  71.             {
  72.                 if(o[i].getCubicalNo()==c)
  73.                 {
  74.                     p=o[i].getEmployeeId();
  75.                     count=1;
  76.                     
  77.                     
  78.                 }
  79.             }
  80.             Employee temp=null;
  81.             int l=0;
  82.             for(int i=0;i<e.length;i++)
  83.             {
  84.                 
  85.                     if(e[i].getEmployeeId()==p)
  86.                     {
  87.                         temp=e[i];
  88.                     }
  89.             }
  90.  
  91.             if(count==0)
  92.             {
  93.                 return null;
  94.             }
  95.             
  96.                 return temp;
  97.             
  98.             
  99.         }
  100.         
  101.     
  102.    
  103. }
  104.  
  105. class Employee
  106. {
  107.     
  108.     public Employee(int employeeId, String name, double salary) {
  109.         super();
  110.         this.employeeId = employeeId;
  111.         this.name = name;
  112.         this.salary = salary;
  113.     }
  114.     public int getEmployeeId() {
  115.         return employeeId;
  116.     }
  117.     public void setEmployeeId(int employeeId) {
  118.         this.employeeId = employeeId;
  119.     }
  120.     public String getName() {
  121.         return name;
  122.     }
  123.     public void setName(String name) {
  124.         this.name = name;
  125.     }
  126.     public double getSalary() {
  127.         return salary;
  128.     }
  129.     public void setSalary(double salary) {
  130.         this.salary = salary;
  131.     }
  132.     private int employeeId;
  133.     private String name;
  134.     private double salary;
  135. }
  136.  
  137. class Office
  138. {
  139.     
  140.     public Office(int employeeId, int cubicalNo, String department) {
  141.         super();
  142.         this.employeeId = employeeId;
  143.         this.cubicalNo = cubicalNo;
  144.         this.department = department;
  145.     }
  146.     public int getEmployeeId() {
  147.         return employeeId;
  148.     }
  149.     public void setEmployeeId(int employeeId) {
  150.         this.employeeId = employeeId;
  151.     }
  152.     public int getCubicalNo() {
  153.         return cubicalNo;
  154.     }
  155.     public void setCubicalNo(int cubicalNo) {
  156.         this.cubicalNo = cubicalNo;
  157.     }
  158.     public String getDepartment() {
  159.         return department;
  160.     }
  161.     public void setDepartment(String department) {
  162.         this.department = department;
  163.     }
  164.     private int employeeId;
  165.     private int cubicalNo;
  166.     private String department;
  167.  
  168. }

Editor

You can edit this paste and save as new:


File Description
  • jcubical
  • Paste Code
  • 29 Jan-2020
  • 4.15 Kb
You can Share it: