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 8975229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:49:30+00:00 2026-06-15T18:49:30+00:00

Sorry, this might be duplicated, I’m not sure if my previous attempt to post

  • 0

Sorry, this might be duplicated, I’m not sure if my previous attempt to post this went through.

Started to learn Java several weeks ago, working on one of my first assignments. 🙂

My question is somewhat basic, but I couldn’t find its exact equivalent after looking through previously resolved topics. This isn’t a real life problem, so I guess it’s expected from me to tackle it in a very specific way.

So the task consisted of several steps – I had to create a superclass with a number of custom objects, add new subclasses, implement new methods to count the value of certain variables, write test classes and sort my output.

It’s all been done apart from this last step. Not sure if I’m allowed to just post my problems like that on the web, but here is where I am right now:

I have something like:

public class Pants
{
public enum SizeType {SMALL, MEDIUM, LARGE, EXTRA_LARGE}
private SizeType size; 
private String brand;
private String countryOfOrigin;
private String color;
private double price;

//Other variables and methods

}

public class Jeans extends Pants  
{ 
//new variables and methods 
}


public class Shorts extends Pants 
{
//some more new variables and methods
}

And other similar subclasses.

import java.util.ArrayList;
public class Selection
{
public static void main(String[] args){

    Jeans ex1 = new Jeans("John Lewis");
    ex1.countryOfOrigin("US");
    ex1.color("Navy");
    ex1.setSize(Pants.SizeType.LARGE);
    ex1.setprice(40);
    ex1.machineWashable(true);
    System.out.println(ex1);

    Shorts ex2 = new Shorts("Ted Baker");
    ex2.countryOfOrigin("United Kingdom");
    ex2.color("White");
    ex2.setSize(Pants.SizeType.MEDIUM);
    ex2.setprice(30);
    ex2.machineWashable(true);
    System.out.println(ex2);
//..etc

ArrayList<Pants> selection = new ArrayList<Pants>();
    selection.add(ex1);
    selection.add(ex2);
    selection.add(ex3);
    selection.add(ex4);
    selection.add(ex5);

    System.out.println( "Size - LARGE: " );
    System.out.println();
    Pants.SizeType size;
    size = Pants.SizeType.LARGE;
    ListPants(selection,size);

I need to write a ListPants method to list objects depending on SizeType – starting with large in this case. I don’t think I can implement any additional interfaces (which is what was mostly recommended in other threads).

Please see my attempt below (didn’t work). Am I thinking in the right direction here, or?

public static void ListPants(ArrayList<Pants> selection, Pants.SizeType size)
{
for (Pants.SizeType sizeType : Pants.SizeType.values()) {
    for (Pants pants : selection) {
        if (pants.getSize().equals(sizeType)) {
System.out.println(selection.toString());    
  • 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-06-15T18:49:31+00:00Added an answer on June 15, 2026 at 6:49 pm

    I think it’s just a minor problem you’re facing. You already defined the signature of the method which should print out all pants of a specific size:

    ListPants(ArrayList<Pants> selection, Pants.SizeType size)
    

    That is correct. Now, your code is looping over all pants and over all possible sizes:

    public static void ListPants(ArrayList<Pants> selection, Pants.SizeType size)
    {
    for (Pants.SizeType sizeType : Pants.SizeType.values()) {
        for (Pants pants : selection) {
            if (pants.getSize().equals(sizeType)) {
               System.out.println(selection.toString()); 
    

    Since this looks like a homework assignment, i’ll phrase my answer as a question:

    Where are you using the size parameter in the method body of ListPants?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry this might be a simple question, but I could not figure it out.
Sorry, this might be a basic/stupid/noob question - I am just trying to tweak
Sorry this is not a very well defined question, I am thinking about an
Sorry this is probably super basic. But in all my javabean examples, I've not
Sorry this might be a very stupid question. But I did have bug with
Ok sorry this might seem like a dumb question but I cannot figure this
I'm sorry, my SQL is a bit rusty so this might be trivial, but
This might have been answered somewhere else if so sorry. I have an dynamic
Sorry this is my first time trying to create a plugin, so I might
This might seem daft for which I'm sorry, I've been writing a bit some

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.