r/javahelp • u/[deleted] • 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.
1
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
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.
1
u/AutoModerator Aug 30 '18
It seems that you possibly have a screenshot of code in your post Creating class files in /r/javahelp.
Screenshots of code instead of actual code text is against the Code posting rules of /r/javahelp as is also outlined in the sidebar - Code posting.
Never submit screenshots of code instead of code text!
If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.
If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.
For small bits of code (less than 50 lines in total, single classes only),
the default code formatter is fine
(one blank line before the code, then 4 spaces before each line of code).Pastebin for programs that consist of a single class only
Gist for multi-class programs, or programs that require additional files
Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.
Ideone for executable code snippets that use only the console
Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;)
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/AgusHym Aug 30 '18
what dont you understand?
you need in first place draw the uml class. Can you do it?
1
Aug 30 '18
The best advice I can give you is not to be afraid. The only way forward is plunging in. Never mind that you cannot get it to work - that's what forums like these are for. Just get started with something, and it will all follow.
0
u/Wolfhammer69 Nooblet Brewer Aug 30 '18
You need to paste your code here properly formatted, or link to pastebin etc
Explain what exactly you're stuck on
Tell us what you have tried and whats not working
Rule's of this Reddit are on the right hand side, points 2 to 5 seem relevant here.
1
u/androgynyjoe Aug 30 '18
I guess I find it hard to believe that you haven't learned anything about coding. This seems like an assignment for Intro to Computer Science or something like that. I'm a bit curious how many days/weeks into the class you are and what you've done so far.
Nevertheless, it seems like you're being asked to create a class and some static methods. These are meant to be like functions; they input something and output something else. I would start by making a file called Marks.java which looks like this:
For example, the method that I called
maxshould input an array of integers (int[]) which I've calledsomeMarksand return anotherintwhich is the maximum value found insomeMarks.Of course, you say you were given a pre-written class "Marks" so maybe this much has already been done for you.