Untitled

 avatar
unknown
plain_text
2 years ago
6.3 kB
5
Indexable
package com.company.main;

import java.util.Scanner;

import static com.company.main.OccupationList.*;


public class Main {


    public static void main(String[] args) throws Exception {

        OccupationList myList = new OccupationList();

        //load Array
        myList.loadArray();

        // newly added to calculate Total of employment
        //myList.sum();

        // newly added to calculate Total Average of Occupations
        //myList.calcAvg();

        System.out.println("\n");
        
        //print the loaded array
        //myList.printArray();


        //toString message
        int i = 0;
        //System.out.print(OccupationList.Occu[i].toString());  // Prints another version of the data
        //This is what I could figure out and decided to go with.

        //menu
        Scanner kbInput = new Scanner(System.in);
        System.out.println();

        System.out.println("Enter Number: 1:Print List, 2:Number of People Employed, 3:Average of Salaries, 4:Search for an Occupation");
        int choice = Integer.parseInt(kbInput.nextLine());


        if (choice == 1) {
            System.out.println(printArray());
        } else if (choice == 2) {
            System.out.println(sum());
        } else if (choice == 3) {
            System.out.println(calcAvg());
        } else if (choice == 4) {
            System.out.println(myList.Occupation[i].toString());
        }

        }

}



package com.company.main;


import java.io.*;
import java.util.Scanner;

class OccupationList {

    OccupationList[] Occupation = new OccupationList[3320];


    // method to load array
    public static void loadArray() throws Exception {

        String inTitle;
        String inCOS;
        int inEmployment;
        int inSalary;


            File OccuFile = new File("D:\\CompSci\\CompSciWork\\Occupations.txt");
            Scanner inFile = new Scanner(OccuFile);


                while (inFile.hasNext()) {

                inCOS = inFile.nextLine();
                inTitle = inFile.nextLine();
                inEmployment = Integer.parseInt(inFile.nextLine().replace(",", ""));
                inSalary = Integer.parseInt(inFile.nextLine().replace(",", ""));


                int i = 0;
                Occupation[] OccupationList = new Occupation[3320];
                OccupationList[i] = new Occupation(inCOS, inTitle, inEmployment, inSalary);
            }

            inFile.close();
        }




    // test method to print data from the array of OccuList
    public static boolean printArray() {
        
        // print header above each row
        System.out.println("Data from the array of Occupations.\n");
        System.out.printf("%-22s%-12s%-22s%-22s%-12s%n", "COS", "Title", "Employment", "Salary","void");
        System.out.println("***************************************************************************************");

        //  print data in formatted columns, one square per row
        for (int i = 0; i < 1000; i++) {

            Occupation[] OccupationList = new Occupation[3320];
            System.out.printf("%-12s", OccupationList[i].getCOS());
            System.out.printf("%-12s", OccupationList[i].getTitle());
            System.out.printf("%-12s", OccupationList[i].getEmployment());
            System.out.printf("%-22s", OccupationList[i].getSalary());
        }
        return false;
    }


    // end printArray
    //***********************************************************************

    // method to calculate Sum of Employees
    public static boolean sum() {
        Occupation[] OccupationList = new Occupation[3320];
        System.out.println("Sum of Employees: ");
        int sum = 0;
        int i;

        for (i = 0; i < OccupationList.length; i++) {

            sum = sum + OccupationList[i].getEmployment();
            System.out.println(" Employee Total " + sum);
        }
        return false;
    }

    // method to calculate average of salaries
    public static boolean calcAvg() {
        Occupation[] OccupationList = new Occupation[3320];
        System.out.println("Salary Average of all Occupations: ");
        int sum = 0;
        int i;

        for (i = 0; i < OccupationList.length; i++) {

            sum = sum + OccupationList[i].getSalary();
            System.out.println(" Employee Salary Average " + sum / OccupationList.length);
        }
        return false;
    }
}// end class OccupationList
//***************************************************************************

package com.company.main;

public class Occupation {

    //declare properties
    private String COS;
    private String title;
    private int employment;
    private int salary;

    // constructor methods
    public Occupation(String COS, String title, int employment, int salary) {
        this.COS = COS;
        this.title = title;
        this.employment = employment;
        this.salary = salary;

    } //end com.company.main.Occupation()


    // accessor methods
    public String getTitle() {
        return this.title;
    } //end getTitle()

    public String getCOS() {
        return this.COS;
    } // end getCOS

    public int getEmployment() {
        return this.employment;
    } // end getEmployment

    public int getSalary() {
        return this.salary;
    }  //end getSalary

    // mutators methods

    public void setTitle(String titleIn) {
        this.title = titleIn;
    }

    public void setCOS(String COSIn) {
        this.COS = COSIn;
    }

    public void setEmployment(int employIn) {
        this.employment = employIn;
    }

    public void setSalary(int salaryIn) {
        this.salary = salaryIn;
    }


    // method to return info about com.company.main.com.company.main.OccupationList as String
    public String toString(){
        return ("COS: " + this.COS+ " " + "Title: " + this.title + " " + "Employment: " +
                this.employment + " " + "Salary: " + this.salary);
    } // end to String()


}// end class com.company.main.com.company.main.OccupationList







Editor is loading...