67,516
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
import java.io.*;
public class Employ{
/**
* 职工信息定义类
*
* @author Yu
*
*/
class Emp {
private String name;
private String age;
private float sal;
private String id;
public Emp(String id, String name, String age, float sal) {
this.age = age;
this.id = id;
this.sal = sal;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public float getSal() {
return sal;
}
public void setSal(float sal) {
this.sal = sal;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
/**
* 职工信息管理类
*
* @author Yu
*
*/
class EmployM {
ArrayList a = null;
public EmployM() {
a = new ArrayList();
}
// 增加一个职工
public void addEmp(Emp emp) {
a.add(emp);
}
// 查询
public void showEmp(String id) {
for (int i = 0; i < a.size(); i++) {
Emp emp = (Emp) a.get(i);
if (emp.getId().equals(id)) {
System.out.println("查询的员工名字是" + emp.getName());
System.out.println("工资" + emp.getSal());
System.out.println("年龄" + emp.getAge());
System.out.println("性别" + emp.getId());
}
}
}
// 删除
public void deleteEmp(String id) {
for (int i = 0; i < a.size(); i++) {
Emp emp = (Emp) a.get(i);
if (emp.getId().equals(id)) {
a.remove(i);
a.remove(emp);
}
}
}
// 更新
public void updateEmp(String id, float newsal) {
for (int i = 0; i < a.size(); i++) {
Emp emp = (Emp) a.get(i);
if (emp.getId().equals(id)) {
emp.setSal(newsal);
}
}
}
}
/**
* 主函数
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Employ employ = new Employ();
EmployM employm = employ.new EmployM();// 此处显示错误????为什么呀?????????
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("请输入你的选择:");
System.out.println("1添加雇员:");
System.out.println("2删除雇员:");
System.out.println("3查询雇员:");
System.out.println("4修改工资:");
String operType = br.readLine();
if (operType.equals("1")) {
System.out.println("请输入编号:");
String id = br.readLine();
System.out.println("请输入名字:");
String name = br.readLine();
System.out.println("请输入性别:");
String age = br.readLine();
System.out.println("请输入工资:");
float sal = Float.parseFloat(br.readLine());
Emp emp = employ.new Emp(id, name, age, sal);// 此处显示错误????为什么呀?????????
employm.addEmp(emp);
} else if (operType.equals("2")) {
String id = br.readLine();
employm.deleteEmp(id);
} else if (operType.equals("3")) {
String id = br.readLine();
employm.showEmp(id);
} else if (operType.equals("4")) {
String id = br.readLine();
float sal = Float.parseFloat(br.readLine());
employm.updateEmp(id, sal);
} else if (operType.equals("5")) {
System.exit(-1);
}
}
}
}
public class Employ {
int a =1;
public static void main(String[] args)
{
System.out.println(a);
}
}
报错
public class Employ {
int a = 1;
public static void main(String[] args)
{
Employ employ =new Employ();
System.out.println(employ.a);
}
}
和
public class Employ {
public static void main(String[] args)
{
int a = 1;
System.out.println(a);
}
}
import java.util.*;
import java.io.*;
public class Employ {
/**
* 主函数
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
EmployM employm = new EmployM();// 此处显示错误????为什么呀?????????
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("请输入你的选择:");
System.out.println("1添加雇员:");
System.out.println("2删除雇员:");
System.out.println("3查询雇员:");
System.out.println("4修改工资:");
String operType = br.readLine();
if (operType.equals("1")) {
System.out.println("请输入编号:");
String id = br.readLine();
System.out.println("请输入名字:");
String name = br.readLine();
System.out.println("请输入性别:");
String age = br.readLine();
System.out.println("请输入工资:");
float sal = Float.parseFloat(br.readLine());
Emp emp = new Emp(id, name, age, sal);// 此处显示错误????为什么呀?????????
employm.addEmp(emp);
} else if (operType.equals("2")) {
String id = br.readLine();
employm.deleteEmp(id);
} else if (operType.equals("3")) {
String id = br.readLine();
employm.showEmp(id);
} else if (operType.equals("4")) {
String id = br.readLine();
float sal = Float.parseFloat(br.readLine());
employm.updateEmp(id, sal);
} else if (operType.equals("5")) {
System.exit(-1);
}
}
}
}
/**
* 职工信息定义类
* Emp是个内部类
* @author Yu
*
*/
class Emp {
private String name;
private String age;
private float sal;
private String id;
public Emp(String id, String name, String age, float sal) {
this.age = age;
this.id = id;
this.sal = sal;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public float getSal() {
return sal;
}
public void setSal(float sal) {
this.sal = sal;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
/**
* 职工信息管理类
* EmployM也是个内部类
* @author Yu
*
*/
class EmployM {
ArrayList a = null;
public EmployM() {
a = new ArrayList();
}
// 增加一个职工
public void addEmp(Emp emp) {
a.add(emp);
}
// 查询
public void showEmp(String id) {
for (int i = 0; i < a.size(); i++) {
Emp emp = (Emp) a.get(i);
if (emp.getId().equals(id)) {
System.out.println("查询的员工名字是" + emp.getName());
System.out.println("工资" + emp.getSal());
System.out.println("年龄" + emp.getAge());
System.out.println("性别" + emp.getId());
}
}
}
// 删除
public void deleteEmp(String id) {
for (int i = 0; i < a.size(); i++) {
Emp emp = (Emp) a.get(i);
if (emp.getId().equals(id)) {
a.remove(i);
a.remove(emp);
}
}
}
// 更新
public void updateEmp(String id, float newsal) {
for (int i = 0; i < a.size(); i++) {
Emp emp = (Emp) a.get(i);
if (emp.getId().equals(id)) {
emp.setSal(newsal);
}
}
}
}