Java UML correction -
i solved uml diagram in java not sure totally correct. , want know should add or remove program.
interface playaudio { // playaudio interface void playa(int id); } interface playvideo { // playvideo interface void playv(int id); } class electronicdevice { // electronicdevice class boolean started; public void start() { if (!started) { started = true; system.out.println("the device started playing."); } } public void stop() { if (started) { started = false; system.out.println("the device stopped playing."); } } } class dvdplayer extends electronicdevice implements playvideo, playaudio { // dvdplayer // class public string devicetype; dvdplayer(string devicetype) { // constructor this.devicetype = devicetype; } public void start() { system.out.println("the " + devicetype + " started playing."); } public void stop() { system.out.println("the " + devicetype + " stopped playing."); } public void playv(int id) { system.out.println("the " + devicetype + " playing video stream no. " + id + "."); } public void playa(int id) { system.out.println("the " + devicetype + " playing audio track no. " + id + "."); } } class mp3player extends electronicdevice implements playaudio { // mp3player // class public string devicetype; mp3player(string devicetype) { // constructor this.devicetype = devicetype; } public void start() { system.out.println("the " + devicetype + " started playing."); } public void stop() { system.out.println("the " + devicetype + " stopped playing."); } public void playa(int id) { system.out.println("the " + devicetype + " playing audio track no. " + id + "."); } } public class testbench { public static void testaudio(playaudio a) { a.playa(0); // have put 0 id because testing audio // device, see if works } public static void testvideo(playvideo v) { v.playv(0); } public static void teststart(electronicdevice e) { e.start(); } public static void teststop(electronicdevice e) { e.stop(); } public static void main(string[] args) { // main method mp3player m = new mp3player("ipod"); m.start(); m.playa(5); playaudio = new mp3player("walkman"); testaudio(a); electronicdevice ed = new dvdplayer("dolby digital"); teststart(ed); ((playvideo) ed).playv(6); } } ps : okay how started exercise ? or should start in way coding uml?

Comments
Post a Comment