Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:30:44+00:00 2026-05-27T04:30:44+00:00

Basically I have been tasked with tackling the following scenario: When you are designing

  • 0

Basically I have been tasked with tackling the following scenario:

When you are designing your class/es, you have to decide what attributes and methods you will include in. For example, if you decide to work in millimeters, your size variable (length) could be of type integer (but later, when calculating the cost, you will have to convert the volume into square inches, because the cost is given per cubic inch of plastic (Table 2 and Table 3 of the coursework)). The volume of plastic material used will be the difference between the outer and inner volume of a pipe. If you decided to prompt the length in meters, then the type should be double, or float, etc.
Once you have validated the user order, your program should determine, based on Table 1, what is the type of the ordered pipe.
Table 1. Types of plastic pipes available.

Type Plastic’s grade    Colour print    Inner insulation    Outer reinforcement Chemical resistance
        0     1 2           
I   1 – 3   YES NO  NO  NO  NO  YES/NO
II  2 – 4   NO  YES NO  NO  NO  YES/NO
III 2 – 5   NO  NO  YES NO  NO  YES/NO
IV  2 – 5   NO  NO  YES YES NO  YES/NO
V   3 – 5   NO  NO  YES YES YES YES/NO

That’s all fine but the part that is getting me is this bit here:

Say in your main class you have determined that client’s order is a pipe of type I, then you can create an object of TypeI and for this object you can call the cost() method to calculate the cost and to show it to the user.

It is basically asking to not instantiate any objects before figuring out which one you need to instantiate, which is hard when it classes a big if statement in the verification as a ‘Brute force method’.

Here is what I have so far.

Main

public class Cw1 {
/**
 * @param args the command line arguments
 */
 public static void main(String[] args) {
    ArrayList<Pipe> pipeList = new ArrayList<Pipe>();
    // TODO code application logic here
    Grade g1 = new Grade(1,3,true,false,false,false,false);
    Grade g2 = new Grade(2,4,false,true,false,false,false);
    Grade g3 = new Grade(2,5,false,false,true,false,false);
    Grade g4 = new Grade(2,5,false,false,true,true,false);
    Grade g5 = new Grade(3,5,false,false,true,true,true);
    pipeList.add(g1);
    pipeList.add(g2);
    pipeList.add(g3);
    pipeList.add(g4);
    pipeList.add(g5);

    for (Pipe p: pipeList)
    {
        p.setGrade(1);
        p.setColour0(false);
        p.setColour1(false);
        p.setColour2(true);
        p.setIns(true);
        p.setReinf(true);
        p.validate();
    }
}
}

Grade (It must have abstracting in the solution)

public class Grade extends Pipe {

public Grade(int minGrade, int maxGrade, boolean hasColour0, boolean hasColour1, boolean hasColour2, boolean hasIns, boolean hasReinf) {
    super(minGrade, maxGrade, hasColour0, hasColour1, hasColour2, hasIns, hasReinf);
}    


}

And pipe

public abstract class Pipe {

public boolean isChemRes() {
    return chemRes;
}

public void setChemRes(boolean chemRes) {
    this.chemRes = chemRes;
}

public boolean isColour0() {
    return colour0;
}

public void setColour0(boolean colour0) {
    this.colour0 = colour0;
}

public boolean isColour1() {
    return colour1;
}

public void setColour1(boolean colour1) {
    this.colour1 = colour1;
}

public boolean isColour2() {
    return colour2;
}

public void setColour2(boolean colour2) {
    this.colour2 = colour2;
}

public double getDiameter() {
    return diameter;
}

public void setDiameter(double diameter) {
    this.diameter = diameter;
}

public boolean isIns() {
    return ins;
}

public void setIns(boolean ins) {
    this.ins = ins;
}

public double getLength() {
    return length;
}

public void setLength(double length) {
    this.length = length;
}

public boolean isReinf() {
    return reinf;
}

public void setReinf(boolean reinf) {
    this.reinf = reinf;
}

public Pipe(int minGrade, int maxGrade, boolean hasColour0, boolean hasColour1, boolean hasColour2, boolean hasIns, boolean hasReinf) {
    this.minGrade = minGrade;
    this.maxGrade = maxGrade;
    this.hasColour0 = hasColour0;
    this.hasColour1 = hasColour1;
    this.hasColour2 = hasColour2;
    this.hasIns = hasIns;
    this.hasReinf = hasReinf;
}



public Pipe() {
}
//<editor-fold desc="Class variables">
private int grade;
private double length, diameter;
private boolean colour0, colour1, colour2, ins, reinf, chemRes;
private int minGrade, maxGrade;
private boolean hasColour0, hasColour1, hasColour2, hasIns, hasReinf; 
// </editor-fold>
public int getGrade() {
    return grade;
}

public void setGrade(int grade) {
    this.grade = grade;
}    
//<editor-fold desc="Public Methods">

public double calcVol()
{
    return 0;
}

public double calcCost()
{
    return 0;
}
public void validate()
{
    if ((grade >= minGrade && grade <= maxGrade) & (colour0 == true && hasColour0 || colour1 == true && hasColour1 || colour2 == true && hasColour2) && (ins == hasIns) && (reinf == hasReinf))
    {
        System.out.print("True");
    }
    else
    {
        System.out.print("False");
    }
}
// </editor-fold>

}

So basically, I don’t understand how I could achieve the same result without instantiating the objects before hand and validating them?

The class isn’t high level, we have only just learned polymorphism.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:30:45+00:00Added an answer on May 27, 2026 at 4:30 am

    Usually, the data which tells you which objects to create comes from an external source: a file, a socket, another object etc. In your case, you could use a text file. Create the Grade instances passing the values you read to the constructor and then call validate and cost on each.

    public class PipeFactory(){
        public Pipe CreatePipe( int minGrade, int maxGrade, boolean hasColour0, boolean hasColour1, boolean hasColour2, boolean hasIns, boolean hasReinf ){
           if( (minGrade == 1 || maxGrade == 3) /* ... Complete this condition yourself */ )
               return new TypeIPipe();
           if( (minGrade == 2 || maxGrade == 4 /* ... Complete this condition yourself */ )
               return new TypeIIPipe();
           //If for other types...
           //If no pipe was created, parameters are invalid, so we throw an exception
           throw new InvalidArgumentException( "Can't create a pipe with these parameters" );
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been battling to get this right...basically I have the following HTML setup: <div
Recently I have been tasked with creating an application for a business that basically
I have been tasked to write a function which is basically same as findIndices
I have been tasked to do a scheduling program in my company. Basically given
I've been tasked with an interesting problem. Basically, I have to compute 3 different
I have been using LINQ with compiled queries, basically passing into the compiled query
I have been playing with the Ruby library shoes. Basically you can write a
I basically have a page which shows a processing screen which has been flushed
Basically, I have been using both Integer.Parse and CInt in most of my daily
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.