Question: Using array list or Linked list. All the StdOut prints can be change to system. Also, we use algs4.java from princeton, dont know how to

Using array list or Linked list.

All the StdOut prints can be change to system. Also, we use algs4.java from princeton, dont know how to send the file for that.

package m01;

/** * Represents a freight container that is defined by its length, * width, and country of origin. * * @author StarterCode + ........... * */

public class Container {

private String country; // country of origin

private int id; // identification number

private int length; // in ft

private double weight; // in tons

public Container(int id, int length, double weight, String country ) {

this.id = id;this.length = length;

this.weight = weight;

this.country = country;

}

public int getId() {

return id;

}

public int getLength()

{return length;

}public double getWeight()

{return weight;

}

public String getCountry()

{

return country;

}

@Override

public String toString() {

return String.format("%4d: %2dft %ft %s", id, length, weight, country);

}

}

---------------------------------------------------------------------------------------

package m01;

import edu.princeton.cs.algs4.StdOut;

/** * CSIS-2420 Midterm1

*

* @author StarterCode + ............... * */

public class Midterm1 {

public static void main(String[] args) {

Container[] containers = {

new Container(1234, 20, 1.9, "China"),

new Container(1235, 40, 3.97, "USA"),

new Container(1236, 40, 4.22, "China"),

new Container(1237, 20, 2.16, "Ghana"),

new Container(1238, 20, 2.1, "USA"),

new Container(1239, 40, 4.08, "Italy"),

new Container(1240, 40, 3.81, "China"),

new Container(1241, 40, 4.2, "USA"),

new Container(1242, 20, 1.82, "Italy")

};StdOut.println("Containers: ");

StdOut.println("=========== ");

for(Container c : containers) {

StdOut.println(c);

}

System.out.println();

StdOut.println("= = = = Part 1 = = = = ");

StdOut.println("Containers by natural order:");

StdOut.println("============================");

StdOut.println("Containers in reverse order:");

StdOut.println("============================");

StdOut.println("= = = = Part 2 = = = = ");

StdOut.println("Foreign Containers:");

StdOut.println("===================");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!