Java OOP; creating array of objects

I’d like to create an array of objects where 3 objects are from one class, and a 4th is from second class. In the first class I did the following: public class Pupil { public int n= 0; …

How to create objects for parameterized constructors in Java, when we have two classes with the same attributes?

I have class Student, that has first name, last name and age, and a method to print the name and the age of the student. public class Student { private String firstName; private String …

Swapping elements in an array Java

I am working on a classes challenge in school. We have to great a Boat class and Harbor class. I have gotten every test to work except the final test of where boats are parked in the Harbor. The …

Print user inputs from 2D array using another class in Java?

I am trying to print user inputs in another class in Java. I have made a chessboard which asks the user to input strings on the board, and then, when these strings are printed on screen, I would like …

Casting an Object into a Class of type T

Let’s say I have an empty class called ClsA(), and a subclass of it called ClsB() like so: public static class ClsA {} public static class ClsB extends ClsA {} Supposing that we now have an …

Object array with variable from another class

Worksheet Question: The question said to declare an array of 5 objects of the class Node in the main Class – I managed to this as shown below But then the question continues populate the array by …

Variable value not being passed into another class

I’m trying to let the user to choose which option is in their menu, and setting the variables based on the option that the customer choose, but when I go to another class and retrieve it, there is no …

Problem at calling a constructor if the java class is in a different path

I want to save the java classes in a folder called Classes, so on NetBeans, I have created that folder, and then I have saved it the class called Jugadores.java but after doing that i am having issues …

Static method to count occurrences of a letter in a lower case word using maps

I have to create a class called MakeMap with a single static method called countLetters(). The method should take as a parameter a word formed of lowercase letters and return a map of the counts of …

How to create a new object of Public Class

I am a newbie in Java, although I have knowledge of Object Oriented Programming from Python but I’m currently having problem understanding this example on creating public class either combining the …