MuhammadimYusoff

VSCode javax.swing error 'package does not exist'

Mar 1st, 2020
1,990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.68 KB | None | 0 0
  1. import javax.swing.*; //? Error Here, 'Package javax.swing does not exist' <----- ERROR HERE
  2. import java.io.BufferedReader;
  3. import java.io.FileReader;
  4. import java.util.LinkedList;
  5. import java.util.StringTokenizer;
  6.  
  7. public class Employment_Info {
  8.  
  9.     //? declare attributes
  10.     String name, gender, marital_status, jobClass;
  11.     int age, health;
  12.     double wage;
  13.  
  14.     //* constructor with param
  15.     public Employment_Info(String name, String gender, String marital_status, String jobClass, int age, int health, double wage) {
  16.         this.marital_status = marital_status;
  17.         this.age = age;
  18.         this.gender = gender;
  19.         this.health = health;
  20.         this.jobClass = jobClass;
  21.         this.name = name;
  22.         this.wage = wage;
  23.     }
  24.  
  25.     //? mutator
  26.  
  27.     public void setGender(String gender) {
  28.         this.gender = gender;
  29.     }
  30.  
  31.     public void setMarital_status(String marital_status) {
  32.         this.marital_status = marital_status;
  33.     }
  34.  
  35.     public void setName(String name) {
  36.         this.name = name;
  37.     }
  38.  
  39.     public void setAge(int age) {
  40.         this.age = age;
  41.     }
  42.  
  43.     public void setHealth(int health) {
  44.         this.health = health;
  45.     }
  46.  
  47.     public void setJobClass(String jobClass) {
  48.         this.jobClass = jobClass;
  49.     }
  50.  
  51.     public void setWage(double wage) {
  52.         this.wage = wage;
  53.     }
  54.  
  55.     //? accessor
  56.  
  57.     public String getGender() {
  58.         return gender;
  59.     }
  60.  
  61.     public String getMarital_status() {
  62.         return marital_status;
  63.     }
  64.  
  65.     public String getJobClass() {
  66.         return jobClass;
  67.     }
  68.  
  69.     public double getWage() {
  70.         return wage;
  71.     }
  72.  
  73.     public String getName() {
  74.         return name;
  75.     }
  76.  
  77.     public int getAge() {
  78.         return age;
  79.     }
  80.  
  81.     public int getHealth() {
  82.         return health;
  83.     }
  84.  
  85.     @Override
  86.     public String toString() {
  87.         return "Employment_Info{" +
  88.                 "name='" + name + '\'' +
  89.                 ", gender='" + gender + '\'' +
  90.                 ", marital_status='" + marital_status + '\'' +
  91.                 ", jobClass='" + jobClass + '\'' +
  92.                 ", age=" + age +
  93.                 ", health=" + health +
  94.                 ", wage=" + wage +
  95.                 '}';
  96.     }
  97.  
  98.     public static void main (String[]args)
  99.     {
  100.         try {
  101.             //create reader to read input file
  102.             BufferedReader in = new BufferedReader(new FileReader("C:/Users/deena/IdeaProjects/SWC4133_Lab Exercise 1/src/employeeList.txt"));
  103.             //create linkedlist
  104.             LinkedList<Employment_Info> employeeList = new LinkedList<>();
  105.  
  106.             String indata = null; //represent a line of data in input file
  107.             Employment_Info employment_info;
  108.  
  109.             //read file
  110.             while((indata = in.readLine())!=null)
  111.             {
  112.                 System.out.println (indata);
  113.                 StringTokenizer st = new StringTokenizer(indata, ";");
  114.                 String name = st.nextToken();
  115.                 String gender = st.nextToken();
  116.                 String marital_status = st.nextToken();
  117.                 String jobClass = st.nextToken();
  118.                 int age = Integer.parseInt(st.nextToken());
  119.                 int health = Integer.parseInt(st.nextToken());
  120.                 double wage = Double.parseDouble(st.nextToken());
  121.  
  122.                 //create object
  123.                 employment_info = new Employment_Info(name, gender, marital_status,jobClass, age, health, wage);
  124.                 //add object into employeeList
  125.                 employeeList.add (employment_info);
  126.             }
  127.             in.close(); //close reader
  128.  
  129.             int menu = 0;
  130.             do{
  131.                 menu = Integer.parseInt(JOptionPane.showInputDialog("Choose menu: \n 1: Add new data \n 2: Edit data \n 3: Delete data \n 4: Display data"));
  132.  
  133.                 if (menu == 1)
  134.                 {
  135.                     String name = JOptionPane.showInputDialog("Enter name");
  136.                     String gender = JOptionPane.showInputDialog("Enter gender");
  137.                     String marital_status = JOptionPane.showInputDialog("Enter marital status");
  138.                     String jobClass = JOptionPane.showInputDialog("Enter job class");
  139.                     int age = Integer.parseInt(JOptionPane.showInputDialog("Enter age"));
  140.                     int health = Integer.parseInt(JOptionPane.showInputDialog("Enter health"));
  141.                     double wage = Double.parseDouble(JOptionPane.showInputDialog("Enter wage"));
  142.  
  143.                     //create object
  144.                     employment_info = new Employment_Info(name, gender, marital_status, jobClass, age, health, wage);
  145.                     //add object into employeeList
  146.                     employeeList.add (employment_info);
  147.                 }
  148.  
  149.                 else if (menu == 2)
  150.                 {
  151.                     //ask user which object they want to edit
  152.                     //enter employee name
  153.                     String name = JOptionPane.showInputDialog("Enter name");
  154.                     //find the object
  155.                     for (int i = 0; i<employeeList.size(); i++)
  156.                     {
  157.                         //get the object from employeeList
  158.                         employment_info = employeeList.get(i); //use method to retrieve object
  159.                         if (employment_info.getName().equalsIgnoreCase(name)) //if true
  160.                         {
  161.                             int choice = 0;
  162.                             do {
  163.                                 choice = Integer.parseInt(JOptionPane.showInputDialog("Choose menu: \n 1: Edit gender \n 2: Edit Marital Status\n 3: Edit Job Class \n 4: Edit age \n 5: Edit Health \n 6: Edit Wage"));
  164.                                 if (choice == 1) //edit gender
  165.                                 {
  166.                                     String newgender = JOptionPane.showInputDialog("Enter new gender");
  167.                                     //update object using mutator method
  168.                                     employment_info.setGender(newgender);
  169.                                     //update object in employeeList
  170.                                     employeeList.set(i, employment_info);
  171.                                 }
  172.                                 else if (choice == 2) //edit marital status
  173.                                 {
  174.                                     String newmarital_status = JOptionPane.showInputDialog("Enter new marital status");
  175.                                     //update object using mutator method
  176.                                     employment_info.setMarital_status(newmarital_status);
  177.                                     //update object in employeeList
  178.                                     employeeList.set(i, employment_info);
  179.                                 }
  180.                                 else if (choice == 3) //edit job class
  181.                                 {
  182.                                     String newjobClass = JOptionPane.showInputDialog("Enter new job class");
  183.                                     employment_info.setJobClass(newjobClass);
  184.                                     employeeList.set(i, employment_info);
  185.                                 }
  186.                                 else if (choice == 4) //edit age
  187.                                 {
  188.                                     int newage = Integer.parseInt(JOptionPane.showInputDialog("Enter new age"));
  189.                                     employment_info.setAge(newage);
  190.                                     employeeList.set(i, employment_info);
  191.                                 }
  192.                                 else if (choice == 5) //edit health
  193.                                 {
  194.                                     int newhealth = Integer.parseInt(JOptionPane.showInputDialog("Enter new health"));
  195.                                     employment_info.setHealth(newhealth);
  196.                                     employeeList.set(i, employment_info);
  197.                                 }
  198.                                 else if (choice == 6) //edit wage
  199.                                 {
  200.                                     double newwage = Double.parseDouble(JOptionPane.showInputDialog("Enter new wage"));
  201.                                     employment_info.setWage(newwage);
  202.                                     employeeList.set(i, employment_info);
  203.                                 }
  204.                             } while (choice !=7);
  205.                         }
  206.                     }
  207.                 }
  208.                 else if (menu == 3)
  209.                 {
  210.                     //ask user which object they want to delete
  211.                     //enter employee name
  212.                     String name = JOptionPane.showInputDialog("Enter name");
  213.                     //find the object
  214.                     for (int i = 0; i<employeeList.size(); i++)
  215.                     {
  216.                         //get object
  217.                         employment_info = employeeList.get(i);
  218.                         if (employment_info.getName().equalsIgnoreCase(name))
  219.                         {
  220.                             employeeList.remove(i); //use method remove
  221.                         }
  222.                     }
  223.                 }
  224.                 else if (menu == 4)
  225.                 {
  226.                     //display data
  227.                     System.out.println ("List all employee in Employee List");
  228.                     for (int i = 0; i<employeeList.size(); i++)
  229.                     {
  230.                         System.out.println (employeeList.get(i));
  231.                     }
  232.                 }
  233.             }
  234.             while (menu != 5);
  235.         }
  236.         catch (Exception ex)
  237.         {
  238.             System.out.println (ex.getMessage());
  239.         }
  240.     }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment