Package main

Source Code of main.Main

/*
* 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 main;

import main.company.Driver;
import main.company.Manager;
import main.company.MyCompany;
import main.company.Worker;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author codefire
*/
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
        MyCompany company = new MyCompany();
        while(true){
        System.out.println("Welcome!\nThis application represents your company.\n\nPlease choose an option:"
                + "\n1. Add worker.\n2. Get worker.\n3. Delete worker.\n4. Show all workers.\n5. Show all workers sorted by salary.\n6. Exit.");
        int option = Integer.parseInt(keyboard.readLine());
        switch(option){
            default:
                System.out.println("\n\nWrong option! Try again please!\n\n");
                break;
            case 6:
                System.exit(0);
                break;
            case 1:
                System.out.println("Choose the type of worker:\n1. Simple worker.\n2. Driver.\n3. Manager.");
                int workerType = Integer.parseInt(keyboard.readLine());
                switch(workerType){
                    default:
                        System.out.println("\n\nWrong worker type! Try again!\n");
                        break;
                    case 1:
                        Worker worker = new Worker(keyboard.readLine(),Double.parseDouble(keyboard.readLine()));
                        company.addWorker(worker);
                        if(company.addWorker(worker)){
                            System.out.println("\n\nWorker was added to company.\n");
                        }else{
                            System.out.println("\n\nWorker wasn't added to company! Try again!\n");
                        }
                        break;
                    case 2:
                        Driver driver = new Driver(keyboard.readLine(),Double.parseDouble(keyboard.readLine()),Boolean.parseBoolean(keyboard.readLine()));
                        company.addWorker(driver);
                        if(company.addWorker(driver)){
                            System.out.println("\n\nDriver was added to company.\n");
                        }else{
                            System.out.println("\n\nDriver wasn't added to company! Try again!\n");
                        }
                        break;
                    case 3:
                        Manager manager = new Manager(keyboard.readLine(),Double.parseDouble(keyboard.readLine()),Double.parseDouble(keyboard.readLine()));
                        company.addWorker(manager);
                        if(company.addWorker(manager)){
                            System.out.println("\n\nManager was added to company.\n");
                        }else{
                            System.out.println("\n\nManager wasn't added to company! Try again!\n");
                        }
                        break;
                }
                break;
            case 2:
                System.out.print("Please input the number of wanted worker/driver/manager: ");
                int index = Integer.parseInt(keyboard.readLine());
                company.getWorker(index);
               break;
            case 3:
                System.out.println("Please input the number of worker/driver/manager you want to delete: ");
                int delIndex = Integer.parseInt(keyboard.readLine());
                company.delWorker(delIndex);
        }
           
      
       
       
//        1. example
//        Worker worker = new Worker("Ivan", 2500.0);
//        System.out.println("name: " + worker.getName());
//        System.out.println("salary: " + worker.getSalary());
//        System.out.println();
       
//        2. example
//        Driver driver = new Driver("Petr", 2750, true);
//        driver.showInfo();
//        System.out.println();
//       
//        Manager manager = new Manager("Sidor", 3500.0, 55000.0);
//        manager.showInfo();
//        System.out.println();
       
//        3. example
//        Worker first = new Driver("Petr", 2750, true);
//        first.showInfo();
//        System.out.println();
//       
//        Worker second = new Manager("Sidor", 3500.0, 55000.0);
//        second.showInfo();
//        System.out.println();
//       
//        Worker[] workers = {first, second};
//        for (int i = 0; i < workers.length; i++) {
//            Worker worker = workers[i];
//            worker.showInfo();
//            System.out.println();
//        }
       
//      4 .example
        /*Worker[] workers = {
            new Driver("Petr", 2750, true),
            new Manager("Sidor", 3500.0, 55000.0),
            new Driver("Ivan", 2150, false),
        };
        for(int i = 0; i < workers.length; i++) {
            System.out.println(workers[i]); // .toString()
            System.out.println();
        }*/
       
//        5. example
//        if(driver instanceof Worker){
//            System.out.println("Driver is Worker!");
//        }
//        if(manager instanceof Worker){
//            System.out.println("Manager is Worker!");
//        }
       
        //MyCompany company = new MyCompany();
        //company.getAllWorkers();
    }
    }
}
TOP

Related Classes of main.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.