6 Replies - 254 Views - Last Post: 25 February 2013 - 05:13 AM Rate Topic: -----

#1 r3tr0k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-February 13

Beginner Programming - Making a clock class - QUESTIONS

Posted 24 February 2013 - 03:26 PM

Hi guys, I'm a first year CS student and we have some extra work set that doesn't need to be completed but I want to get my head round it. i'm not the best at programming and haven't used a forum like this before so i was wondering if someone could explain what these different things do within a class in simpleton speak ;)

Below is the work that we've been set.

Posted Image

Basically what I want to know is, what do I do with the statements in the lowest box starting with Clock() like, where do they go?
Will I be needing 4 seperate classes then? Main, hours, minutes, seconds
What does Get, Set and Add do?
No idea how to set this all out and I feel stupid as hell...
Thanks in advance!

http://tinypic.com/r/sc886u/6

Theres a tinypic link as the above image doesn't want to work

Is This A Good Question/Topic? 0
  • +

Replies To: Beginner Programming - Making a clock class - QUESTIONS

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1292
  • Posts: 2,863
  • Joined: 30-January 11

Re: Beginner Programming - Making a clock class - QUESTIONS

Posted 24 February 2013 - 03:33 PM

I know where you're coming from - you want to get ahead in your knowledge. The problem is you aren't at that stage yet. The questions your asking are on the very basic OOP level. You aren't going to get any better explanation here than you would by your teachers on your course. Besides they are paid to teach you so they should really be better.

If you really want to know then read up on object oriented programming. But my advice is to leave off for a bit. You are only going to confuse yourself more and that leads to bad motivation. Both of which you don't need in exchange for a week ahead of teaching.

But to answer your questions -

1. Nope you only need one class called Clock.

2. Get/Set are used to set and get the values of the fields (hours, minutes etc). You use the set method to give the fields values and get to retrieve the value - for use use when printing out the value etc.

3. Add is a method that performs an action on your fields. In this case Add will simply add on values to the fields. You also add logic into these methods. For example incrementing hours when minutes reaches 60 etc.
Was This Post Helpful? 0
  • +
  • -

#3 r3tr0k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-February 13

Re: Beginner Programming - Making a clock class - QUESTIONS

Posted 24 February 2013 - 03:41 PM

Thanks for such a quick reply! I still can't understand what the "Clock()" is representing? I know where everything else will go but I don't know where that would be haha. It's probably a very simple question I just want to know what I'm doing before I start. Yes we have only just started OOP so it's all very basic, but it seems to twist my mind :(

Or is it literally just the name of the class?
Was This Post Helpful? 0
  • +
  • -

#4 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1292
  • Posts: 2,863
  • Joined: 30-January 11

Re: Beginner Programming - Making a clock class - QUESTIONS

Posted 24 February 2013 - 03:46 PM

Clock() is the constructor. It contains the code that will be executed when a new Clock object is created.

It is normally used to initialize the fields.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: Beginner Programming - Making a clock class - QUESTIONS

Posted 24 February 2013 - 03:49 PM

Yes, Clock is the name of the class and Clock() will be constructors (there are two of them). But as Ryano121 points out, you need to gen up on OOP fundamentals.
Was This Post Helpful? 0
  • +
  • -

#6 r3tr0k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-February 13

Re: Beginner Programming - Making a clock class - QUESTIONS

Posted 24 February 2013 - 03:52 PM

Cool! I think i get it now then. If i have any more problems i'll post back here but it should be good. Thanks guys.
Was This Post Helpful? 0
  • +
  • -

#7 Witchking  Icon User is offline

  • D.I.C Head

Reputation: 68
  • View blog
  • Posts: 186
  • Joined: 17-February 13

Re: Beginner Programming - Making a clock class - QUESTIONS

Posted 25 February 2013 - 05:13 AM

You won't get far without understanding the main concepts of OOP. You should read through these five articles, they might help you better understand.

Part 1 Part 2 Part 3 Part 4 Part 5
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1