-
April 9th, 2013, 09:17 AM
#1
Help with java class, subclass
Hello,
I need help with my work. I'm no good at programming and we started learning java last week, yet we got a hard task to do and i have no idea how to do it. If you could help me with it I would be very grateful.
The task:
Requirements
- implement a class 'motor' with fields 'currentSpeed', 'currentDirection', 'id' and methods 'turnLeft()', 'turnRight()'
- implement basic user interface for controlling the engine
- implement at least two subclasses for different/various electric motors (i.e. a stepperMotor, DCMotor, etc.)
- implement subclass-specific (hardware-dependant) methods
- implement output to see how it works
- implement input for choosing,initializing,operating the motors
Inputs (user can
- coosing a motor subclass
- initializing a motor
- determining state of a motor
- using the motor (left/right)
Outputs (we will see
- all public variables/fields that change value
- internal behaviour of hardware-dependant methods (i.e. logic value of the pins connected to motors)
-
April 17th, 2013, 01:53 PM
#2
Re: Help with java class, subclass
Pretty enough to complete the task: http://lmgtfy.com/?q=java+interface+explained
Recommended structure:
- interface Engine (here go the methods declarations)
- class (can be abstract) Motor as Engine implementation (here go the motor methods implementation or their redeclaration)
- class Motor1 extending class Motor (here go the motor specific methods overrides)
- class Motor2 extending class Motor (here go the motor specific methods overrides)
- for test and runs you could use a separate class with the main function
Last edited by Xeel; April 17th, 2013 at 02:04 PM.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|