Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions