i new java programming, , taking course through edx uses bluej ide. i'm trying duplicate in eclipse, since understand commonly-used ide professional programmers. have question functionality use in bluej haven't figured out yet in eclipse.
is there way create test instances of objects in eclipse can in bluej?
screenshot 1 shows 2 constructors available class. chose highlighted one.
screenshot 2 dialogue naming instance.
screenshot 3 dialogue menu various methods available object.
so there way in eclipse? have read bit junit, , intend learn use it, wondering if there similar function simple bluej testing in eclipse.
here code car class:
import comp102x.io; //external library available in many of later demo programs https://courses.edx.org/courses/course-v1:hkustx+comp102.1x+2t2015/f792f3a2057040aa959e606d687e9bc4/ /** * class of car objects can move forward, backward , turn */ public class car { private int odometer = 0; // odometer reading initialized 0 private string owner = "noname"; // name of owner /** * default constructor car object */ public car () {} /** * constructor car object new owner’s name * @param name name of owner */ public car(string name) { // constructor takes name argument owner = name; } /** * movecar moves car forward or backward dist units * @param dist moving distance */ public void movecar(int dist) { odometer = odometer + math.abs(dist); io.outputln(owner + "'s car has moved " + dist + " units."); } /** * turncar turns car given degree * @param angle turn angle in degrees */ public void turncar(double angle) { io.outputln(owner + "'s car has turned " + angle + " degrees."); } /** * getodometer gets odometer reading of car * @return value of odometer */ public int getodometer() { return odometer; } }
from experience in working bluej, can tell it's simplified beginners. there's lot of conveniences allowed end user stuff quick instantiation , quick testing.
however, you're not afforded such conveniences (graphically) in ide eclipse, netbeans, or intellij. these ides make easier develop enterprise level code, , such, graphical interface serve in way more help.
depending on context of "test", have several options.
if want instantiate instance , play around it, create new class
main
method. there, instantiate instance ofcar
hand:public static void main(string[] args) { car car = new car(); car altcar = new car("the ride"); // code calls methods on each instance follow }
if want unit tests, junit choice. you'll have put junit somewhere on classpath (documentation eclipse exists).
public class cartest { @test public void testcar() { car car = new car(); // put state car // assert expectations } }