r/javahelp • • Aug 30 '18

Homework Creating class files

Hey, I'm a first year at uni doing a programming class and I'm having some trouble with some work. I have no idea what to do to be honest, I haven't learnt anything about coding and am just stuck. I understand how class's work as well as attributes and methods, I just don't know how to write the code itself. The work also comes with a prewritten class file and class marks, I don't know what to do with them either. Any help would be appreciated, I have linked below the link to pics of the work.

https://imgur.com/a/HZc7Fqt

0 Upvotes

8 comments sorted by

View all comments

1

u/[deleted] Aug 30 '18

You need to be a bit more specific. What specifically are you struggling with? You say you understand how classes work but do you know what a constructor is, how to write a method, what a getter and setter is and what they do? Is it the syntax you're confused by or do you just not know how to calculate the distance between two points in 3D space? There are so many possible reasons why you find this hard that, short of doing your assignment for you, we can't give you decent help.

My general advice would be to start by identifying the different classes that the assignment requires, then deciding what data each class needs to hold (these will be your data members/data fields). Then figure out what operations each class needs to be able to perform (these will be your methods). And, before you even start to write the code to perform the operations, set out the template of your class. Declare your data members, write your method signatures (scope, return type, name, parameters). Once you have that laid out, start fleshing out the actual steps that have to take place inside each method/constructor. Write these steps as comments first. Then when you're pretty sure that you have the right steps written out, start writing those comments out in correct Java code (you may have to refer to lecture notes and online information to do this).

0

u/[deleted] Aug 30 '18

I don't know what a constructor is, how to write a method, or what a getter and setter are. I'm completely new to this subject, I do have some material that covers arrays and methods but it's not much and it only covers what they do.