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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:43:03+00:00 2026-06-18T06:43:03+00:00

I’m trying to make a java application that’s allows the user to make a

  • 0

I’m trying to make a java application that’s allows the user to make a catalog for a supermarket, and then display all the products that the user entered to the catalog. Now I have a problem with filling the array of objects the should be fill in by the user’s input.
The output should be like the following (user input in Bold):

Enter product description (or # to stop): Condensed Powdered water
Enter product code: P3487
Enter product unit price: $2.50
Enter product unit phrase: per packet

Enter product description (or # to stop): Distilled Moonbeams
Enter product code: K3876
Enter product unit price: $3.00
Enter product unit phrase: a dozen

Enter product description (or # to stop): Anti-Gravity Pills
Enter product code: Z9983
Enter product unit price: $12.75
Enter product unit phrase: for 60

Enter product description (or # to stop): #

Your catalog:
P3487, Condensed Powdered water, $2.50 per packet.
K3876, Distilled Moonbeams, $3.00 a dozen.
Z9983, Anti-Gravity Pills, $12.75 for 60.

The code that I wrote : 2 classes
class 1:

public class Catalog {

private String description ; 
private String code ;
private double price ;
private String phrase ;

int counter = 0;

private Catalog [] list = new Catalog [100];

public Catalog (String productDescription , String productCode , double    productPrice , String productPhrase)
{
    description = productDescription;
    code = productCode;
    price = productPrice;
    phrase = productPhrase;
}

public void setDescription (String productDescription)
{
    description = productDescription;
}

public String getDescription ()
{
    return description;
}

public void setCode (String productCode)
{
    code = productCode;
}

public String getCode ()
{
    return code;
}

public void setPrice (double productPrice)
{
    price = productPrice;
}

public double getPrice ()
{
    return price;
}

public void setPhrase (String productPhrase)
{
    phrase = productPhrase;
}

public String getPhrase ()
{
    return phrase;
}

class 2:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class CatalogTest {

/**
 * @param args
 * @throws IOException 
 */

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    String name = null; 
    String code = null;
    double price = 0.0;
    String phrase = null;



    BufferedReader input = new BufferedReader (new InputStreamReader  (System.in));

    Catalog product = new Catalog(name,code,price,phrase);

    Catalog [] productsArray = new Catalog [100];


    for (int i = 0 ; i < productsArray.length ; i ++)
    {


        System.out.println("Enter product description (or # to stop): ");
        name = input.readLine();

        if (!("#".equals(name))) 
        {

            productsArray [i] = product;
            product.setDescription(name);

            System.out.println("Enter product code: ");
            code = input.readLine();
            productsArray [i] = product;
            product.setCode(code);


            System.out.println("Enter product unit price: ");
            price = Double.parseDouble(input.readLine());
            productsArray [i] = product;
            product.setPrice(price);


            System.out.println("Enter product unit phrase: ");
            phrase = input.readLine();
            productsArray [i] = product;
            product.setPhrase(phrase);



            productsArray [i] = new Catalog (name,code,price,phrase);



        }

        else 
        {
            System.out.println("Your Catalog:");

            System.out.printf("%s, %s,$%.2f   %s",product.getCode(),product.getDescription(),product.getPrice(),product
                    .getPhrase());
            break;
        }


    }


}
}

The output I get (user input in Bold) :
Enter product description (or # to stop):
condensed powdered water
Enter product code:
p3487
Enter product unit price:
2.50
Enter product unit phrase:
per packet
Enter product description (or # to stop):
distilled moonbeams
Enter product code:
k3876
Enter product unit price:
3
Enter product unit phrase:
a dozen
Enter product description (or # to stop):
#
Your Catalog:
k3876, distilled moonbeams,$3.00 a dozen

So any help PLEASE ??

  • 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-18T06:43:05+00:00Added an answer on June 18, 2026 at 6:43 am

    Here is the updated code that works…

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    public class CatalogTest
    {
    
        /**
         * @param args
         * @throws IOException
         */
    
        public static void main(String[] args) throws IOException
        {
            // TODO Auto-generated method stub
    
            String name = null;
            String code = null;
            double price = 0.0;
            String phrase = null;
    
            BufferedReader input = new BufferedReader(new InputStreamReader(
                System.in));
    
            Catalog product = new Catalog(name, code, price, phrase);
    
            Catalog[] productsArray = new Catalog[100];
    
            for (int i = 0; i < productsArray.length; i++)
            {
    
                System.out.println("Enter product description (or # to stop): ");
                name = input.readLine();
    
                if (!("#".equals(name)))
                {
    
                    productsArray[i] = product;
                    product.setDescription(name);
    
                    System.out.println("Enter product code: ");
                    code = input.readLine();
                    productsArray[i] = product;
                    product.setCode(code);
    
                    System.out.println("Enter product unit price: ");
                    price = Double.parseDouble(input.readLine());
                    productsArray[i] = product;
                    product.setPrice(price);
    
                    System.out.println("Enter product unit phrase: ");
                    phrase = input.readLine();
                    productsArray[i] = product;
                    product.setPhrase(phrase);
    
                    productsArray[i] = new Catalog(name, code, price, phrase);
    
                }
    
                else
                {
                    System.out.println("Your Catalog:");
                    for (int j = 0; j < productsArray.length; j++)
                    {
                        if(productsArray[j]!=null)
                        {
                            System.out.printf("%s, %s,$%.2f %s,",
                                productsArray[j].getCode(),
                                productsArray[j].getDescription(),
                                productsArray[j].getPrice(),
                                productsArray[j].getPhrase());
                        }
                    }
                    break;
                }
    
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.