title-img


Java Factory Pattern

According to Wikipedia, a factory is simply an object that returns another object from some other method call, which is assumed to be "new". In this problem, you are given an interface Food. There are two classes Pizza and Cake which implement the Food interface, and they both contain a method getType(). The main function in the Main class creates an instance of the FoodFactory class. The FoodFactory class contains a method getFood(String) that returns a new instance of Pizza or Cake accor

View Solution →

Java Singleton Pattern

"The singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system." - Wikipedia: Singleton Pattern Complete the Singleton class in your editor which contains the following components: 1.A private Singleton non parameterized constructor. 2.A public String instance variable named str. 3.Write a static method named getSingleInstance that returns the single instance o

View Solution →

Covariant Return Types

Java allows for Covariant Return Types, which means you can vary your return type as long you are returning a subclass of your specified return type. Method Overriding allows a subclass to override the behavior of an existing superclass method and specify a return type that is some subclass of the original return type. It is best practice to use the @Override annotation when overriding a superclass method. You will be given a partially completed code in the editor where the main method tak

View Solution →

2D Array - DS

Given a 6*6 2D Array, arr: 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation: a b c d e f g There are 16 hourglasses in arr. An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6*6. Example: arr= -9 -9 -9 1 1 1 0

View Solution →