Results 1 to 2 of 2
- 12-03-2011, 04:48 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 26
- Rep Power
- 0
How validate input against abstract class?
I have 5 pipe types, and want to check user input with each abstract type. The user input will be via a GUI.
My current pipe code:
Java Code:public abstract class Pipe { protected boolean InnerInsulation, OuterReinforcement; protected int Colour; protected int[] Grades; public validateOrder(){ } }Java Code:public class Type1 extends Pipe { public Type1() { this.InnerInsulation = false; this.OuterReinforcement = false; this.Colour = 2; this.Grades = new int[]{1, 2, 3}; } }Java Code:public class Type2 extends Pipe { public Type2() { this.InnerInsulation = false; this.OuterReinforcement = false; this.Colour = 1; this.Grades = new int[]{2, 3, 4}; } }Java Code:public class Type3 extends Pipe { public Type3() { this.InnerInsulation = false; this.OuterReinforcement = false; this.Colour = 2; this.Grades = new int[]{2, 3, 4, 5}; } }Java Code:public class Type4 extends Pipe { public Type4() { this.InnerInsulation = true; this.OuterReinforcement = false; this.Colour = 2; this.Grades = new int[]{2, 3, 4, 5}; } }I want to create a method within the pipe abstract class to compare values with each value and if values match of the types, to return the type and if not, to say order invalid.Java Code:public class Type5 extends Pipe { public Type5() { this.InnerInsulation = true; this.OuterReinforcement = true; this.Colour = 2; this.Grades = new int[]{3, 4, 5}; } }
All help appreciated.
-
Re: How validate input against abstract class?
Consider making validateOrder a true method -- with a valid return type, likely a boolean. Make it abstract and thereby force all subclasses to implement the method. By the way, you only have one abstract type here, so it makes no sense to state that you want to validate input with "each" abstract type.
Similar Threads
-
Compare Abstract Class Values to User input?
By FadedAura in forum New To JavaReplies: 16Last Post: 11-25-2011, 04:49 PM -
Class is not abstract and does not override abstract method run(com.
By rgeurts in forum New To JavaReplies: 4Last Post: 04-14-2011, 11:42 AM -
How do I validate user input from forms with Java?
By rickywh in forum New To JavaReplies: 2Last Post: 01-30-2010, 06:49 AM -
Difference between Abstract class having only abstract method and a Interface class
By Santoshbk in forum New To JavaReplies: 6Last Post: 02-11-2009, 10:51 AM -
validate time input format
By Alairmon in forum New To JavaReplies: 2Last Post: 11-04-2008, 07:39 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks