Results 1 to 2 of 2
  1. #1
    FadedAura is offline Member
    Join Date
    Nov 2011
    Posts
    26
    Rep Power
    0

    Default 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};
        }
    }
    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};
        }
    }
    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.

    All help appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default 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

  1. Compare Abstract Class Values to User input?
    By FadedAura in forum New To Java
    Replies: 16
    Last Post: 11-25-2011, 04:49 PM
  2. Replies: 4
    Last Post: 04-14-2011, 11:42 AM
  3. How do I validate user input from forms with Java?
    By rickywh in forum New To Java
    Replies: 2
    Last Post: 01-30-2010, 06:49 AM
  4. Replies: 6
    Last Post: 02-11-2009, 10:51 AM
  5. validate time input format
    By Alairmon in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 07:39 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •