About Java

Asked 1 years ago, Updated 1 years ago, 32 views

A generates B's object and returns B
B adds records
C has an object of B in the argument, creates the file with the added record, and returns the file name

A and B are done, but I don't know how to pass the list created by B to C

public class A {
    public B create() {
        Bb = new B()
        return b;
    }
}

B is

public class B{
    private ArrayList list = new ArrayList();

    publc void add(inta, intb, String c) {
        list.add(a);
        list.add(b);
        list.add(c);
        System.out.println(list);
    }
}

Let's say
For X,

public classx{
    public void test {
        Aa = new A();
        Bb = a.create();
        b.add(000001,1234, "Test Data";
    }
}

The expected results have now been printed.
After that, if you can create a method of C and call it X, it will be done

In C,

public class C{
    public String createFile (Badd) {
        // Create file
    }
}

What should I do to give the information of B's add to create this part of C?

java

2022-09-30 21:14

1 Answers

As it is a stub, I will explain that I don't know how to contour the class, not the real code part of the process of adding records or generating files.

Java classes need to be instantiated, so to use A, B, and C classes, you need to instantiate them as follows:

Aa=newA();
Bb = new B();
Cc = new C();

Also, you must define a method for the class to do something.

  • Class A requires the "Generate Object B" method
  • Class B requires the "Add Record" method and the "Retrieve Record" method that Class C calls when creating a file
  • C class requires "Generate file and return file name" method

Based on these, I think the class definitions of A, B, and C are as follows.

Class A:

public class A
{
    /** Generate B object */
    public void createB()
    {
        return new B();
    }
}

Class B:

public class B
{
    /** Add Record*/
    public void addRecord (Object object)
    {
    }

    /** Retrieve records*/
    public Object getRecord()
    {
    }
}

Class C:

public class C
{
    public String createFile (Bb)
    {
        // Get Record Created
        Object object = b.getRecord();
        // file creation process
        ・・・
        return "filename";
    }
}

If you want to use them, you will see the following:

Aa=newA();
// Generating B Objects
Bb = a.createB();
// Adding Records
b.addRecord(/*something that represents record information*/);
// file generation
Cc = new C();
String fileName = c.createFile(b);

The input information is not provided, so the arguments are appropriate.


2022-09-30 21:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.