Java Inheritance and Understanding Interface Classes -



Java Inheritance and Understanding Interface Classes -

hi, working on short java assignment have been set (i learning basics) struggling create sense of question. question follows:

design , write classes model different types of publications in library. consider different types of publications, e.g. books , magazines. set attributes , methods mutual types of publications in super-class, , extend super-class appropriately create set of sub-classes.

make sure include appropriate constructor, getter, setter , customised methods in classes. utilize method overloading , overriding appropriate.

make maximum utilize of inheritance in design , class code.

implement next interface class in design , coding:

+ getpublisher() : string + getpublicationtitle() : string + getprice : float + setpublication(publisherin: string, titlein:string, pricein:float) : void

so have answered best can, please read , check on right track , understand meant doing, seems fat simple correct? oh , javadocs not finished yet [=

public interface publicationinterface { /** * returns book publisher name (as string) */ public string getpublisher(); /** * returns book publication title (as string) */ public string getpublicationtitle(); /** * returns book cost (as float) */ public float getprice(); /** * sets book publication details. * * @param publisherin book publisher (as string) * @param titlein book title (as string) * @param pricein book cost (as float) */ public void setpublication(string publisherin, string publicationtitlein, float pricein); } abstract public class publications implements publicationinterface { // attributes protected string publisher; protected string publicationtitle; protected float price; public publications(string publisherin, string publicationtitlein, float pricein) { publisher = publisherin; publicationtitle = publicationtitlein; cost = pricein; } public string getpublisher() { homecoming (publisher); } public string getpublicationtitle() { homecoming (publicationtitle); } public float getprice() { homecoming (price); } public void setpublication(string publisherin, string publicationtitlein, float pricein) { publisher = publisherin; publicationtitle = publicationtitlein; cost = pricein; } } public class mag extends publications { string editor; string date; public magazine(string publisherin , string publicationtitlein, float pricein, string editorin, string datein) { super (publisherin , publicationtitlein, pricein); editor = editorin; date = datein; } public void setpublication(string publisherin, string publicationtitlein, float pricein) { publisherin = publisher; publicationtitlein = publicationtitle; pricein = price; } public string geteditor() { system.out.println("the editor of mag " + editor); homecoming (editor); } public string getdate() { system.out.println("the publication date of mag " + date); homecoming (date); } public string getpublisher() { system.out.println("the publisher of mag " + publisher); homecoming (publisher); } public string getpublicationtitle() { system.out.println("the publication title of mag " + publicationtitle); homecoming (publicationtitle); } public float getprice() { system.out.println("the cost of mag £" + price); homecoming (price); } } public class referencematerial extends publications { string genre; string subject; public referencematerial(string publisherin , string publicationtitlein, float pricein, string genrein, string subjectin) { super (publisherin , publicationtitlein, pricein); genre = genrein; subject = subjectin; } public string getgenre() { system.out.println("the genre of material " + genre); homecoming (genre); } public string getsubject() { system.out.println("the subject of material " + subject); homecoming (subject); } public string getpublisher() { system.out.println("the publisher of material " + publisher); homecoming (publisher); } public string getpublicationtitle() { system.out.println("the publication title of material " + publicationtitle); homecoming (publicationtitle); } public float getprice() { system.out.println("the cost of material £" + price); homecoming (price); } } public class book extends publications { int pagenumber; string author; public book(string publisherin , string publicationtitlein, float pricein, int pagenumberin, string authorin) { super (publisherin , publicationtitlein, pricein); pagenumber = pagenumberin; author = authorin; } public int getpagenumber() { system.out.println("the number of pages in book " + pagenumber); homecoming (pagenumber); } public string getauthor() { system.out.println("the author of book " + author); homecoming (author); } public string getpublisher() { system.out.println("the publisher of book " + publisher); homecoming (publisher); } public string getpublicationtitle() { system.out.println("the publication title of book " + publicationtitle); homecoming (publicationtitle); } public float getprice() { system.out.println("the cost of book £" + price); homecoming (price); } } public class testlibrary { public static void main() { mag magazine1 = new mag ("sanyonic publishing", "ayup magazine", 99, "yeshumenku suni", "12/09/2011"); system.out.println(); magazine1.geteditor(); magazine1.getdate(); magazine1.getpublisher(); magazine1.getpublicationtitle(); magazine1.getprice(); system.out.println(); referencematerial referencematerial1 = new referencematerial ("dorling kindesy", "killer sharks in solent", 200, "nature", "sharks"); referencematerial1.getgenre(); referencematerial1.getsubject(); referencematerial1.getpublisher(); referencematerial1.getpublicationtitle(); referencematerial1.getprice(); system.out.println(); book book1 = new book ("hodder & soughton", "one day", 75, 1105, "david nicholls"); book1.getpagenumber(); book1.getauthor(); book1.getpublisher(); book1.getpublicationtitle(); book1.getprice(); system.out.println(); } }

many all

this looks fine save don't need interface @ all. didn't see mentioned in homework, , it's not necessary subclassing.

interfaces mutual methods implemented set of classes otherwise not related (specifically not part of class hierarchy).

since classes descend parent publications class, there not need publicationsinterface in case. super class fills role nicely.

publication p = new book(); p.setpublisher("acme books");

java inheritance interface

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -