
import java.text.DecimalFormat;
import java.io.*;
import java.util.*;
public class Container {
private List<Object> objects = new ArrayList<>(); implement the tasks for the following code.
public void add(Object object) {
objects.add(object);
}
public Object remove() {
if (!objects.isEmpty()) {
return objects.remove(objects.size() - 1);
}
return null;
}
public int getSize() {
return objects.size();
}
public Order top() {
if (!objects.isEmpty() && objects.get(objects.size() - 1) instanceof Order) {
return (Order) objects.get(objects.size() - 1);
}
return null;
}
}
class Queue extends Container {
public Queue(List<Order> orders) {
for (Order order : orders) {
if (order.getTotalAmount() >= 1500) {
super.add(order);
}
}
}
@Override
public void add(Object obj) {
if (((Order) obj).getTotalAmount() >= 1500) {
super.add(obj);
}
}
public Order remove() {
if (getSize() > 0) {
Order order = (Order) super.top();
super.remove();
return order;
}
return null;
}
public Order top() {
if (getSize() > 0) {
return (Order) super.top();
}
return null;
}
}
class Stack extends Container {
public Stack(List<Order> orders) {
for (Order order : orders) {
if (order.getTotalAmount() < 1500) {
super.add(order);
}
}
}
@Override
public void add(Object obj) {
if (((Order) obj).getTotalAmount() < 1500) {
super.add(obj);
}
}
public Object remove() {
if (getSize() > 0) {
Order order = (Order) super.top();
super.remove();
return order;
}
return null;
}
public Order top() {
if (getSize() > 0) {
return (Order) super.top();
}
return null;
}
}
class IOHandler {
public static List<String> readFile(String fileName) {
List<String> content = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = br.readLine()) != null) {
content.add(line);
}
} catch (FileNotFoundException e) {
System.err.println("File not found: " + fileName);
} catch (IOException e) {
System.err.println("Error reading file: " + e.getMessage());
}
return content;
}
public static void writeFile(String fileName, List<String> content) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(fileName))) {
for (String line : content) {
bw.write(line);
bw.newLine();
}
} catch (IOException e) {
System.err.println("Error writing to file: " + e.getMessage());
}
}
}
class Order {
private int orderId;
private String customerName;
private String productName;
private int quantity;
private double unitPrice;
public Order(int orderId, String customerName, String productName, int quantity, double unitPrice) {
this.orderId = orderId;
this.customerName = customerName;
this.productName = productName;
this.quantity = quantity;
this.unitPrice = unitPrice;
}
public double getTotalAmount() {
return quantity * unitPrice;
}
@Override
public String toString() {
DecimalFormat df = new DecimalFormat("#.##");
return "Order ID: " + orderId +
"\nCustomer Name: " + customerName +
"\nProduct Name: " + productName +
"\nQuantity: " + quantity +
"\nUnit Price: $" + df.format(unitPrice) +
"\nTotal Amount: $" + df.format(getTotalAmount());
}
}


to generate a solution
a solution
- import java.util.Scanner; public class LabProgram { public static Roster getInput(){ /* Reads course title, creates a roster object with the input title. Note that */ /* the course title might have spaces as in "COP 3804" (i.e. use nextLine) */ /* reads input student information one by one, creates a student object */ /* with each input student and adds the student object to the roster object */ /* the input is formatted as in the sample input and is terminated with a "q" */ /* returns the created roster */ /* Type your code here */ } public static void main(String[] args) { Roster course = getInput(); course.display(); course.dislayScores(); }} public class Student { String id; int score; public Student(String id, int score) { /* Student Employee */ /* Type your code here */ } public String getID() { /* returns student's id */…arrow_forwardStringFun.java import java.util.Scanner; // Needed for the Scanner class 2 3 /** Add a class comment and @tags 4 5 */ 6 7 public class StringFun { /** * @param args not used 8 9 10 11 12 public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter your first name: "); 13 14 15 16 17 18 System.out.print("Please enter your last name: "); 19 20 21 //Output the welcome message with name 22 23 24 //Output the length of the name 25 26 27 //Output the username 28 29 30 //Output the initials 31 32 33 //Find and output the first name with switched characters 34 //All Done! } } 35 36 37arrow_forwardJava language Use arrays in creating your class. Stack Interface (LIFO) void push(Object) Object pop() String toString() boolean isEmpty() boolean equals(Object) getIndexOf get remove private static void arrayListTests() { System.out.println("ArrayList Tests"); // todo: make more tests here ArrayList a = new ArrayList(); System.out.println("Check empty array isEmpty:" + a.isEmpty()); a.insert('B', 0); a.insert('a', 0); a.insert('t', 1); System.out.println("Check non-empty array isEmpty:" + a.isEmpty()); System.out.println(a.toString()); while (a.isEmpty() == false) { System.out.println(a.remove(0)); } // Fill over initial capacity and check that it grows for (int i = 0; i < 110; i++) { a.append(new Integer(i)); } System.out.println("Size of array after 110 adds: "+ a.size()); System.out.println("Value of last element: "+ a.get(a.size()-1)); System.out.println("Insert past end of list"); a.insert('z', 200); System.out.println("Insert negative index"); a.insert('z', -3);…arrow_forward
- JavaTimer.java: import java.util.Arrays;import java.util.Random; public class JavaTimer { // Please expand method main() to meet the requirements.// You have the following sorting methods available:// insertionSort(int[] a);// selectionSort(int[] a);// mergeSort(int[] a);// quickSort(int[] a);// The array will be in sorted order after the routines are called!// Be sure to re-randomize the array after each sort.public static void main(String[] args) {// Create and initialize arraysint[] a = {1, 3, 5}, b, c, d;// Check the time to sort array along startTime = System.nanoTime();quickSort(a);long endTime = System.nanoTime();long duration = (endTime - startTime) / 1000l;// Output resultsSystem.out.println("Working on an array of length " + a.length + ".");System.out.println("Quick sort: " + duration + "us.");}// Thanks to https://www.javatpoint.com/insertion-sort-in-javapublic static void insertionSort(int array[]) {int n = array.length;for (int j = 1; j < n; j++) {int key = array[j];int…arrow_forwardExercise 2: Consider the following class: public class Sequence { private ArrayList values; public Sequence() { values = new ArrayList(); } public void add(int n) { values.add(n); } public String toString() { return values.toString(); } } Add a method public Sequence merge(Sequence other) that merges two sequences, alternating ele- ments from both sequences. If one sequence is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer sequence. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then a.merge(b) returns the sequence 1 9 4 7 9 4 16 9 11 without modifying a or b.arrow_forwardimport java.util.* ; public class Averager { public static void main(String[] args) { //a two dimensional array int[][] a = {{5, 9, 3, 2, 14}, {77, 44, 22, 15, 99}, {14, 2, 3, 9, 5}, {88, 15, 17, 121, 33}} ; System.out.printf("Average = %.2f\n", average(a)) ; System.out.println("EXPECTED:") ; System.out.println("Average = 29.85") ; System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ; System.out.println("EXPECTED:") ; System.out.println("Average of evens = 26.57") ; Random random = new Random(1) ; a = new int[100][1] ; for (int i = 0 ; i < 100 ; i++) a[i][0] = random.nextInt(1000) ; System.out.println("For an array of random values in range 0 to 999:") ; System.out.printf("Average = %.2f\n", average(a)) ; System.out.printf("Average of evens = %.2f\n", averageEvens(a)) ; } /** Find the average of all elements of a two-dimensional array @param aa the two…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





