I am doing homework of making a simple calculator using java and interface in java. but the class that implements java gives error saying here is the code Answer There are a couple of issues here. First, since BasicCalculator is a public class, it needs to be defined in its own file named BasicCalculator.java. Second, the method names in BasicCalculator
Tag: methods
Java – generate and rotate matrix
recently I’m trying to learn Java a bit and currently, I’m working on a simple program that should generate a matrix and then rotate it. I’m stuck at the first part. What exactly is the problem? The logic of my code seems to be fine, but anyway program is returning not what I would expect. The code: Output: Please, enter
I have a HashSet pre. Is there a fast way to do HashSet PreIDs = for each x do x.getID in Pre? (in Java)
There is a class Prerequisite, it has a method getID(). Instead of doing is there a more efficient or more concise way to call a method over a HashSet? Answer As @ernest_k said, there isn’t any more efficient way in my opinion too. But we can write that whole logic in one line as below (if you are using Java
Having issues calling a decorator method (Java)
Working on a group project that is essentially a text-based Pokemon rip-off. My classmates and I were given a UML to work from so I can’t accept any solutions that would add methods or change their parameters. But essentially the issue we’re running into is this: There is a singleton PokemonGenerator class, that has a method generateRandomPokemon(int level) that picks
Call method in Fragment from some class
I’ve been working on Android App in AndroidStudio. Application has Fragment, let’s call it MainFragment, and seperate Java Class file, let’s call it SQLiteControler.class The problem is when i try to call method from Fragment in SQLiteController im getting null object reference as error Here is some minified code: MainFragment SQLiteController Note: This is minified code I have tried, a
how to pass variables between three different methods in java
hello I need to pass value from method A() to Method C() then after call Method C() inside the method B(). please any one show me the syntax. for example: I need this payerPhone the next follow method called onActivityResult() Answer Firstly I strongly recommend you to gain some teoretical knowledge about java (follow some tutorials, read documentation etc) As
How to write a method which will take item array as input and return item with least price (considering discount as well)?
I am new to Java, and I am trying to declare another method in this class called getItemPrice, which will take item array as input and return item with least price (considering discount as well). So far, I have declared an array of 2 item objects in main method. This is my main method: As you can see above, each
Return type method “Return value of the method is never used” problem
i have a task to complete. I have to create a return type method takes String array as an argument and returns to int. So my method works completely fine i will use it to count multiple elements of an element in an array but on method name it says “Return value of the method is never used”. I just
Issue with addressing variables from different method
I am just learning to code in Java and ran into a problem. The task description was following: “The class SalaryCountingWithMethods below asks for three floating point numbers (work hours, salary per hour and tax percent) and then counts the salary before and after taxes as well as the tax part of the salary based on the information given to
Accessing array attributes from other classes with setter/getter
I’m new to Java and was wondering how to access attributes from other classes with setter/getter if they are arrays. Currently, I have one date class that sets a date with parameters for month/day/year. I need to make another class that uses the date class to set a date of hire to store as an attribute, alongside others. My code