我的代码无法打印

时间:2018-01-24 19:58:38

标签: java object constructor println

我是计算机编程的新手,而我所分配的项目对我来说非常困惑。我到目前为止编写的代码没有错误,但它不会打印。

这是项目:

类和对象程序

  1. 使用方法和实例字段(状态变量)

  2. 创建一个Employee对象
  3. 构造函数采用字符串,int和double(名称,社会安全号码和小时工资)

  4. 将int转换为格式为123-45-6789

  5. 的字符串
  6. 雇用五名新员工(5个对象)

  7. 创建扫描仪

  8. 创建一个循环,为每个对象输入以下数据

    一个。 SS#或名称

    湾工作时间

    ℃。至少有一名员工工作超过40小时

  9. 打印员工的工资核算报告

  10. 这是我的代码:

    package Employee;
    import java.io.*;
    import java.util.Scanner;
    import java.util.Random;
    
    
    /**
      * Write a description of class Employee here.*
      *  @author (your name)
      *  @version (a version number or a date)
      */
    
    public class Employee{
        public static void main (String[] args)
        {
            Scanner scanner = new Scanner(System.in);
            String NAME = scanner.nextLine();
            int hrs = scanner.nextInt();
        }
    
        /**
          *  Constructor for objects of class Employee
          */
        public Employee(String name, int employeenumber, double hourlypay)
        {
            socialsecurity = employeenumber;
            employeename= name;
            rate= hourlypay;
            TaxRate =.2;
        }
    
        public String SSN() {
            return  String.format("Social Security Number: ",
                (int) socialsecurity / 1000000,
                (int)(socialsecurity % 1000000) / 10000, 
                socialsecurity % 10000);
    
                //return " ";
        }
    
        public double paycheck(double h)//pay
        {
            return paycheck;
        }
    
        private int socialsecurity;
        public String employeename;
        private double rate;
        public double paycheck;
        public double TaxRate;
    
    }
    
    /**
      *  Company X payroll program**  Vincent Wrencher
      *  the Dark Side provided assistance**  1/24/2018
      */
    class Tester
    {
        public static void main (String arg[])
        {
            double hours;
            int hoursworked = 1;
            String printout = " Name /t /t /t/t SS# /t /t Pay /n -----------------------------/n";
    
            Employee e1 = new Employee(" Kat",100805600, 10.50);
            System.out.println("Number Of Hours Worked: " +  e1.employeename);
    
            Employee e2 = new Employee("Genesis", 123-456789, 11);
            System.out.println("Number Of Hours Worked: " +  e2.employeename);
    
            Employee e3 = new Employee("Falcore", 987654321, 11);
            System.out.println("Number Of Hours Worked: " +  e3.employeename);
    
            Employee e4 = new Employee("Alexandria", 132435465, 11);
            System.out.println("Number Of Hours Worked: " +  e4.employeename);
    
            Employee e5 = new Employee("Evangeline", 543264397, 11);
            System.out.println("Number Of Hours Worked: " +  e5.employeename);
        }
    }
    

1 个答案:

答案 0 :(得分:0)

您在Employee类(公共类)中有公共main()方法。执行此方法而不是Tester类中的方法。您可以从Employee类中删除main(),它将起作用。可以看出,Employee类中的main()不会打印任何内容。