0

I am working with (put in the simplest way I can think of) a three layer java file using jGRASP, for anybody else who happens to use that, and cares to think about that fact. I am sure that most other java editors work pretty much the same.

I am trying to simulate a computerized cash register. I have my three files that I am working with: CashRegister.java, TestInventory.java, and InventoryItem.java.

I am not going to go into what each file does. I have that part down fairly well, and I am just confused on how the files interact with each other. CashRegister.java call and works off of TestInventory.java, which is based from and works off of InventoryItem.java.

I have looked around for, but I cannot really find anything that makes sense for me on how to call a class into another class.

In short, FileC needs to call FileB in order to do it's work, and FileB needs to do FileA in order to do it's job correctly.

Any recommendations or quick help? I don't need anything complicated, and I am sure it is something simple that I'm just not seeing.

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
Jon Akers
  • 71
  • 9
  • Sorry, but this is way too broad and "basic". You use other classes by either calling static methods on them or by instantiating them with "new" to then invoke non static methods on these objects. That is explained in any good book or tutorial. Don't expect us to help with problems that mainly require you sitting down to learn the things that learning to program is about. "please help me" is not a question within the scope of this community. – GhostCat Mar 10 '18 at 05:36
  • @GhostCat, would you please elaborate what you mean by that? I tried to put what I needed help on without going into too much detail, but somehow I don't think that is quite what you mean with your comment. – Jon Akers Mar 10 '18 at 05:39
  • You don't need "help". You need to accept that you have to sit down and spend hours and hours reading books. I already told you how one class can make use of methods in another class. Again: this community is not a replacement for you studying books or tutorials. – GhostCat Mar 10 '18 at 05:50
  • @GhostCat, there is one thing I would like to let you know: I use this site as a last resort. I have a book that I use, then a tutorial website related to the book, then I Google it and look for videos, and from there, I go to the main page, and this site is usually the first thing on the list, going down the list as I am drawing blanks.. As for time I am looking for how to do this stuff, I spend more time looking for how to do it than I do with my own freaking family. I'll admit it: I struggle a lot. But I do what I need to do in order for a chance to get my work done. – Jon Akers Mar 10 '18 at 05:57
  • By the time I use this site, I have run out of other options. I probably spend more hours trying to learn this stuff than most people work in a week. Just want you to think about that. – Jon Akers Mar 10 '18 at 06:00
  • And I gave you in my first comment the concepts that answer your question. Beyond that : as said we are talking about super basic stuff. The answer that you accepted only linked to existing material. In that sense it is exactly what I predicted to happen - somebody gave you a link to existing material. That is not what this site should be about. Seriously: if learning these basics costs you so much time and energy then you probably should look into your learning strategies. – GhostCat Mar 10 '18 at 06:17
  • As I said before my question was edited: I tried to look for articles WITHIN THIS SITE, but the ones that I could find were either not relevant or confused me even more. I tried to look, and the person who answered obviously knows more articles on this site than I do. I tried, but I can only do so much with what I know. – Jon Akers Mar 10 '18 at 06:22
  • What I mean is : you probably learn better when you have a human around that explains things. Like a peer or tutor. But that is something that this site is not (really) about. I suggest you rather follow step by step tutoriald. And you don't move on to the next step until you really got all of the current session. – GhostCat Mar 10 '18 at 06:44
  • Just search for "oracle Java tutorial" and start top to bottom. – GhostCat Mar 10 '18 at 06:45

1 Answers1

0

Java codes are executed using the Java Virtual Machine(JVM), and it doesn't matter either you have 3 classes or 1000 classes, JVM can handle it. First have a basic knowledge about java.

Read these articles,

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
  • Well, the second article I have already seen and tried to read, but that just confused me even more. However, I hadn't found the first article you posted, and I think I get it now: So I basically call it like calling another method, but I need to add mutators in order to allow the final class to work with the other classes, correct? Or am I reading completely wrong? – Jon Akers Mar 10 '18 at 05:46
  • Correct. Code inside `static` methods. call them anywhere using `className.methodName()`. That's the easiest way. – Roshana Pitigala Mar 10 '18 at 05:48
  • Thank you. Of course, after going through all of this, I was able to find a video that I have seen at some point in the past that explains it a bit. After looking at your first article, it all started to come back to me. I just wish I could have seen that one when I was looking, but all of the so-called "related article" that this site put up when I was typing my question were completely useless, and I don't think that was one of them. – Jon Akers Mar 10 '18 at 05:51
  • Right... Sorry about that. It is easy for me to overlook that simple little thing. By the way, you seem to be great at not-so-subtle clues (Just going for a bit of humor there, not trying to be a jerk) (; – Jon Akers Mar 10 '18 at 05:59
  • Sorry to bug you with something like this, but I have just one last quick question, since it seems like you know your way around java (I am taking a college course, and it is a pest...) and I really have no clue: Do you think java will have a problem if the method that I am calling has the same name as the file itself? – Jon Akers Mar 10 '18 at 06:08
  • 1
    @JonAkers no it won't be a problem. And there's a regulation that all developers tend to use when naming methods. _Method names should start with lowercase letter and be a verb e.g. actionPerformed(), main(), print(), println() etc._ – Roshana Pitigala Mar 10 '18 at 06:12
  • OK. Thanks. I knew about that little rule of thumb, but I have a habit of naming methods by how I will remember then, and not usually through that little trick. People tend to be a bit annoyed at me when I am sharing a semi-complete code, often renaming my methods... But thanks for all of your help. – Jon Akers Mar 10 '18 at 06:16