Java oop组合arraylist [英] Java oop composition arraylist

查看:62
本文介绍了Java oop组合arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Main Class
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {


        ArrayList<Employee> employeesList = new ArrayList<Employee>();
        Employee n1 = new Employee("soiri", 88753, "09645324");
        Employee n2 = new Employee("sofia", 42455, "09645324");
        Employee n3 = new Employee("bolira", 678312, "09645324");
        Employee n4 = new Employee("kobi", 342423, "09645324");
        Employee n5 = new Employee("kestin", 3434, "09645324");
        Employee n6 = new Employee("madrid", 88753, "09645324");
        Employee n7 = new Employee("rob", 524622, "09645324");
        Employee n8 = new Employee("sosi", 143432523, "09645324");
        Employee n9 = new Employee("coli", 2525141, "09645324");
        Employee n10 = new Employee("ban", 2525252, "09645324");
        employeesList.add(n1);
        employeesList.add(n2);
        employeesList.add(n3);
        employeesList.add(n4);
        employeesList.add(n5);
        employeesList.add(n6);
        employeesList.add(n7);
        employeesList.add(n8);
        employeesList.add(n9);
        employeesList.add(n10);






        Invoice invoice = new Invoice(500,"David",n1);



        ArrayList<DayWorking> workingOfDay = new ArrayList<DayWorking>();
        DayWorking d1 = new DayWorking(n1,n2,n3);
        DayWorking d2 = new DayWorking(n2,n4,n6);
        DayWorking d3 = new DayWorking(n7,n8,n9);
        DayWorking d4 = new DayWorking(n3,n1,n10);
        DayWorking d5 = new DayWorking(n5,n8,n9);
        DayWorking d6 = new DayWorking(n10,n5,n2);
        workingOfDay.add(d1);
        workingOfDay.add(d2);
        workingOfDay.add(d3);
        workingOfDay.add(d4);
        workingOfDay.add(d5);
        workingOfDay.add(d6);



        ArrayList<WorkSchedule> week = new ArrayList<WorkSchedule>();
        WorkSchedule w1 = new WorkSchedule(d1);
        week.add(w1);





        invoice.printDetails();


        w1.printWorking();




        //week.printWorking(); //loop
    }

}


public class Employee {

    private String namePurchaseOrder;
    private int id;
    private String phoneNumber;


    public Employee() {

    }

    public Employee(String namePurchaseOrder, int id, String phoneNumber) {

        this.namePurchaseOrder = namePurchaseOrder;
        this.id = id;
        this.phoneNumber = phoneNumber;
    }

    public String getNamePurchaseOrder() {
        return this.namePurchaseOrder;
    }

    public void setNamePurchaseOrder(String namePurchaseOrder) {
        this.namePurchaseOrder = namePurchaseOrder;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }


    public String getPhoneNumber() {
        return this.phoneNumber;
    }


    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }



}

public class Invoice {

        private int price;
        private String clientName;
        private Employee seller;


        public Invoice () {

        }

        public Invoice(int price, String clientName, Employee seller) {
            this.price = price;
            this.clientName = clientName;
            this.seller = seller;
        }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getClientName() {
        return clientName;
    }

    public void setClientName(String clientName) {
        this.clientName = clientName;
    }

    public Employee getSeller() {
        return seller;
    }

    public void setSeller(Employee seller) {
        this.seller = seller;
    }

    public void printDetails() {

        System.out.println("Price: "+ price);
        System.out.println("Client Name: "+ clientName);
        System.out.println("Seller: "+ seller);

    }

}



public class WorkSchedule {

   private DayWorking d1;
   private DayWorking d2;
   private DayWorking d3;
   private DayWorking d4;
   private DayWorking d5;
   private DayWorking d6;

    public WorkSchedule(DayWorking d1) {
        this.d1 = d1;
    }



    public WorkSchedule(DayWorking d1, DayWorking d2, DayWorking d3, DayWorking d4, DayWorking d5, DayWorking d6) {
        this.d1 = d1;
        this.d2 = d2;
        this.d3 = d3;
        this.d4 = d4;
        this.d5 = d5;
        this.d6 = d6;
    }

    public DayWorking getD1() {
        return d1;
    }

    public void setD1(DayWorking d1) {
        this.d1 = d1;
    }

    public DayWorking getD2() {
        return d2;
    }

    public void setD2(DayWorking d2) {
        this.d2 = d2;
    }

    public DayWorking getD3() {
        return d3;
    }

    public void setD3(DayWorking d3) {
        this.d3 = d3;
    }

    public DayWorking getD4() {
        return d4;
    }

    public void setD4(DayWorking d4) {
        this.d4 = d4;
    }

    public DayWorking getD5() {
        return d5;
    }

    public void setD5(DayWorking d5) {
        this.d5 = d5;
    }

    public DayWorking getD6() {
        return d6;
    }

    public void setD6(DayWorking d6) {
        this.d6 = d6;
    }


    public void printWorking() {

        System.out.println("The name of the Working monday: " + d1);
        System.out.println("The name of the Working sunday: " + d2);
        System.out.println("The name of the Working thursday: " + d3);
        System.out.println("The name of the Working tuesday: " + d4);
        System.out.println("The name of the Working wednesday: " + d5);
        System.out.println("The name of the Working saturday: " + d6);

    }


}


public class DayWorking {

    private Employee morning;
    private Employee noon;
    private Employee evening;


    public DayWorking() {

    }


    public DayWorking(Employee morning, Employee noon, Employee evening) {
        this.morning = morning;
        this.noon = noon;
        this.evening = evening;
    }

    public Employee getMorning() {
        return morning;
    }

    public void setMorning(Employee morning) {
        this.morning = morning;
    }

    public Employee getNoon() {
        return noon;
    }

    public void setNoon(Employee noon) {
        this.noon = noon;
    }

    public Employee getEvening() {
        return evening;
    }

    public void setEvening(Employee evening) {
        this.evening = evening;
    }
}





我的尝试:



我需要做什么..

在输出中我得到NULL值为什么?

感谢您的帮助!



在服装店写一个代表购买发票的部门。发票应包含以下字段: - 购买金额 - 购买者的身份 - 代表进行销售的员工的对象。对于这样的对象,我们将编写一个全名,身份证和电话号码的部门。接下来,您必须编写一个代表该商店中工作板的部门。每天应该有三名员工在店里工作,这个部门应该描述每天工人的身份。对于每一天,键入一个类,工作板由该类中的一组对象组成。



What I have tried:

Its what i need to do..
On the output i get NULL value why ?
Thanks for help!

Write a department representing a purchase invoice in a clothing store. The invoice should have the following fields: - The amount of the purchase - The identity of the purchaser - Object representing the employee who made the sale. For such an object, we will write a department with a full name, identity card and phone number. Next, you must write a department that represents the work board in that store. Three employees are supposed to work at the shop each day, and this department should describe who the workers will be each day. For each day, type a class, with the work board composed of an array of objects from that class.

推荐答案

引用:

在输出中我得到NULL值为什么?

On the output i get NULL value why ?



你没有给我们任何有用的信息,比如哪个输出是NULL,或者代码在哪里。 br />
你的部分工作也是找到并纠正错误。调试器是帮助您完成此活动的首选工具。

注意:每个认真的程序员都必须知道调试器。

-----

你的代码没有你想象的那样,你不明白为什么!



有一个几乎通用的解决方案:运行你的代码调试器一步一步,检查变量。

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

有在调试器中没有魔法,它不知道你应该做什么,它没有找到错误,它只是通过向你展示正在发生的事情来帮助你。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。

调试器 - 维基百科,免费的百科全书 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows /jdb.html [ ^ ]

https: //www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]

调试器仅显示您的代码正在执行的操作,您的任务是与什么进行比较它应该这样做。



PS:我没有给你更好的提示你的问题,因为我的PC上没有Java。


You gave us no useful information like which output is NULL, or where in code.
Part of your job is also to find and correct bugs. The debugger is the tool of choice to help you on this activity.
Note: Knowing the debugger is mandatory for every serious programmer.
-----
Your code do not behave the way you expect, and you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.

PS: I didn't gave you better hint about your problem because I don't have Java on my PC.


这篇关于Java oop组合arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆