Hello! I'm doing my first homework assignment with abstract classes and interfaces.

I have a few questions:
(1) I know that a class must be saved on the computer as, for example, Class.java. Is this the same for abstract classes? How are interfaces supposed to be saved? Do they need to be in the same folder or anything as the classes that implement them?

(2) I'm writing a class that simulates a bank account, including an online transfer between two accounts. To make it realistic, I'm having the class ask for the account number, amount, and purpose for the transfer, even though that doesn't influence the calculation involved in the transfer. For that, I obviously need to introduce a scanner - does that sort of thing get written in the interface as well? The scanner will be used in the main method for the bank account class, so I was thinking not - as the main method isn't written in the interface normally. I'm just not sure, and I thought maybe someone could explain that!

(3)This may be an idiotic question, but I'll ask it nonetheless. If I want to print an object and I already have a print() method, I can type

object.print()

to do just that. However, what if I have a method that takes in a certain variable (such as

calculateTransfer(double transfer)

) ? When I call that method, do I write:

transfer.calculateTransfer();

or should it be:

transfer.calculateTransfer(double transfer)

That seems like overkill, but - I'm just not sure. The lecture for this class is all about the history of Java, and all of the homework assignments are kind of a free-for-all, hope-you-find-all-the-information-you-need assignments. So, basically, thank you so much in advance!

Hello! I'm doing my first homework assignment with abstract classes and interfaces.

I have a few questions:
(1) I know that a class must be saved on the computer as, for example, Class.java. Is this the same for abstract classes? How are interfaces supposed to be saved? Do they need to be in the same folder or anything as the classes that implement them?

...
is this a serious question? Yes, they all need to be saved and they all need to be compiled before you'll be able to use them. how they should be saved? well, usually file > save ( as ) does the trick.
no, they don't need to be in the same folder as the classes implementing them. but, if they're not in the same folder (also called 'package') you'll need to implement the correct package using an import statement.

(2) I'm writing a class that simulates a bank account, including an online transfer between two accounts. To make it realistic, I'm having the class ask for the account number, amount, and purpose for the transfer, even though that doesn't influence the calculation involved in the transfer. For that, I obviously need to introduce a scanner - does that sort of thing get written in the interface as well? The scanner will be used in the main method for the bank account class, so I was thinking not - as the main method isn't written in the interface normally. I'm just not sure, and I thought maybe someone could explain that!

no. you write no functional code within an interface, nor do you write bodies for methods in interfaces. you can use a scanner (and no, this doesn't HAVE to be done in the main method), but there are other ways too, for instance, the JOptionPane class which gives you dialogboxes which you can use to enter or display data.

(3)This may be an idiotic question, but I'll ask it nonetheless. If I want to print an object and I already have a print() method, I can type

object.print()

to do just that. However, what if I have a method that takes in a certain variable (such as

calculateTransfer(double transfer)

) ? When I call that method, do I write:

transfer.calculateTransfer();

or should it be:

transfer.calculateTransfer(double transfer)

That seems like overkill, but - I'm just not sure. The lecture for this class is all about the history of Java, and all of the homework assignments are kind of a free-for-all, hope-you-find-all-the-information-you-need assignments. So, basically, thank you so much in advance!

it should be neither. you'll need to pass a double variable.
for instance, if you have a print method with the next signature:

public void print(double var){
}

you'll need to do something like this:

double var = ..// put here the code to set a value:
// it could be double var = 3.0;
// or a call for a method that returns a double
transfer.print(var);

Thank you for the answers to 1 and 2 - for the third question, I'm a bit confused. We're not supposed to have a set value for the transfer amount, so where you wrote "double var = ... " - I don't have any value to assign there. In the assignment, the methods were given that we were supposed to use, including

public void print()

Is there any way to make it work with that?

Thank you for the answers to 1 and 2 - for the third question, I'm a bit confused. We're not supposed to have a set value for the transfer amount, so where you wrote "double var = ... " - I don't have any value to assign there. In the assignment, the methods were given that we were supposed to use, including

public void print()

Is there any way to make it work with that?

if you want to print a variable and it cannot be passed to the method the best is to use static variables which are initiated within your main class and can be accessed throught the class

Okay. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.