Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package employee;
- import java.util.*;
- import java.io.*;
- public class Employee <U,V> implements Comparable <Employee> {
- private U a;
- private V b;
- public Employee(U a, V b) {
- this.a = a;
- this.b = b;
- }
- public U getA() {
- return a;
- }
- public void setA(U a) {
- this.a = a;
- }
- public V getB() {
- return b;
- }
- public void setB(V b) {
- this.b = b;
- }
- public static void main(String[] args) {
- ArrayList <Employee> arr = new ArrayList<Employee>();
- arr.add (new Employee ("Ali",1));
- arr.add (new Employee ("Ahmad",2));
- arr.add (new Employee ("Xhmad",5));
- arr.add(new Employee (2,"Saim"));
- arr.add(new Employee (1,"Xaim"));
- arr.add(new Employee (9,"Gaim"));
- Collections.sort(arr);
- for(Employee x:arr)
- System.out.println(x.getA()+" "+x.getB());
- }
- @Override
- public int compareTo(Employee o) {
- String one="",two="";
- int a=0,b=0;
- if (o.getA() instanceof String && this.getA() instanceof String){
- one = (String) o.getA();
- two = (String) this.getA();
- return two.compareTo(one);
- }
- /* else
- if (o.getB() instanceof String && this.getB() instanceof String){
- one = (String) o.getB();
- two = (String) this.getB();
- return one.compareTo(two);
- }*/
- /* else
- if (o.getA() instanceof String && this.getB() instanceof String){
- one = (String) o.getA();
- two = (String) this.getB();
- return one.compareTo(two);
- }*/
- if(o.getA() instanceof Integer && this.getA() instanceof Integer)
- {
- a=(int) o.getA();
- //System.out.println(this.getA());
- b=Integer.parseInt((String.valueOf(this.getA())));
- return b-a;
- }
- return 0;
- }
- }
- Upper to Lower, Lower to Upper
- package st2;
- public class St2 {
- public static void main(String[] args) {
- String s="HelLo woRld @ 2017";
- int i;
- char[]c=s.toCharArray();
- char[] k=new char[100];
- int a=c.length;
- for(i=0;i<a;i++)
- {
- if(Character.isUpperCase(c[i]))
- {
- c[i]=Character.toLowerCase(c[i]);
- }
- else if(Character.isLowerCase(c[i]))
- {
- c[i]= Character.toUpperCase(c[i]);
- }
- }
- for(i=0;i<a;i++)
- {
- System.out.print(c[i]);
- }
- }
- }
- import java.io.*;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.StringTokenizer;
- /**
- * Created by test on 3/14/2017.
- */
- public class Main{
- public static void main(String[] args) throws Exception {
- File country = new File("out\\country.txt");
- File capital = new File("out\\capital.txt");
- File combine = new File("out\\combine.txt");
- FileReader f1 = new FileReader(country);
- BufferedReader bf1 = new BufferedReader(f1);
- String str = new String();
- ArrayList<String> list = new ArrayList<String>();
- int i = 0;
- while((str = bf1.readLine()) != null) {
- list.add(str);
- i++;
- }
- Collections.sort(list);
- bf1.close();
- f1.close();
- FileWriter wcountry= new FileWriter(country);
- BufferedWriter bwcountry = new BufferedWriter(wcountry);
- for (String ss: list) {
- bwcountry.write(ss + "\n");
- }
- bwcountry.close();
- wcountry.close();
- FileWriter w1 = new FileWriter(capital);
- BufferedWriter bw1 = new BufferedWriter(w1);
- String delimiter = " ";
- String comb = new String();
- for (int k = 0; k < i; k++) {
- int j =0;
- FileReader f2 = new FileReader(combine);
- BufferedReader bf2 = new BufferedReader(f2);
- while((comb = bf2.readLine()) != null) {
- StringTokenizer st = new StringTokenizer(comb, delimiter);
- String name = st.nextToken();
- String name2 = null;
- if(name.equals(list.get(k))) {
- name2 = st.nextToken();
- bw1.write(name2 + "\n");
- }
- j++;
- }
- bf2.close();
- f2.close();
- }
- bw1.close();
- w1.close();
- }
Add Comment
Please, Sign In to add comment