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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:05:33+00:00 2026-05-24T22:05:33+00:00

First of All here’s the Codes: Product Information: public class ProductInformation { public String

  • 0

First of All here’s the Codes:

Product Information:

public class ProductInformation
{
    public String code;
    public String itemName;
    public double price;
    //Constructor
    public ProductInformation()
    { itemName="-";
      code="-";
      price=0;}
    //Setter
    public void setItemName(String itemName)
    { this.itemName=itemName;}
    public void setCode(String code)
    { this.code=code;}
    public void setPrice(double price)
    { this.price=price;}
    //Getter
    public String getItemName()
    { return itemName;}
    public double getPrice()
    { return price;}
    public String getCode()
    { return code;}

    //Products
    public void getProduct(String code)
    {   if(code == "A001"){
            setCode("A001");
            setItemName("Mouse  ");
            setPrice(100);}
        else if(code == "A002"){
            setCode("A002");
            setItemName("Monitor    ");
            setPrice(2500);}
        else if(code == "A003"){
            setCode("A003");
            setItemName("Keyboard");
            setPrice(200);}
        else if(code == "A004"){
            setCode("A004");
            setItemName("Flash Disk");
            setPrice(300);}
        else if(code == "A005"){
            setCode("A005");
            setItemName("Hard Disk");
            setPrice(1500);}
            }
}

import java.util.*;

Product Display:

public class ProductDisplay
{   public ProductInformation product;
    public ProductDisplay()
    {
        System.out.println("\t\t\t\t  RG COMPUTER SHOP");
        System.out.println("\t\t\t\t    Makati City");
        System.out.println("\t\tP R O D U C T\tI N F O R M A T I O N");
        System.out.println("-------------------------------------------------------");
        System.out.println("\t\tCode\t\tDescription\t\tUnit Price");
        System.out.println("-------------------------------------------------------");
        product = new ProductInformation();
        product.getProduct("A001");
        display();
        product = new ProductInformation();
        product.getProduct("A002");
        display();
        product = new ProductInformation();
        product.getProduct("A003");
        display();
        product = new ProductInformation();
        product.getProduct("A004");
        display();
        product = new ProductInformation();
        product.getProduct("A005");
        display();
    }
    // Display Method
    public void display()
    {  System.out.println("\t\t" + product.getCode()
                        + "\t\t" + product.getItemName()
                        + "\t\t" + product.getPrice()); }
}

My Problem is here in PointOfSale
I tried to let the buyer decide by entering a Product Code
after entering the getProduct I get is always “A005” Even if I enter “A001” or something else. I think the product.getProduct(code) is not working out. Can someone help me fix this problem so i can continue scripting this

import java.util.*;
public class PointOfSale extends ProductDisplay
{   
    public PointOfSale()
    {   System.out.print("\nPurchase Item(y/n)?");
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        if("y".equalsIgnoreCase(line)){
        OpenOrder();
            }
    }
    //=============================================
    public void OpenOrder() // New Order
    {   ArrayList<String> ProductList = new ArrayList<String>();
        ProductList.add("A001");    ProductList.add("A002");
        ProductList.add("A003");    ProductList.add("A004");
        ProductList.add("A005");
        System.out.print("Select Product Code:");
        Scanner sc = new Scanner(System.in);
        String code = sc.next();
        if(ProductList.contains(code))
        { product.getProduct(code);
          display(); EnterQuantity();       }
        else System.out.print("Product Code is Invalid\n"); System.exit(0);}
    //==============================================
    public void EnterQuantity()  //Entering Quantity
    {
        try{
            System.out.print("Enter Quantity:");
            Scanner sc = new Scanner(System.in);
            int quantity = sc.nextInt();
            double amount = quantity * product.getPrice();
            System.out.print("Amount: " + amount);}
        catch (InputMismatchException nfe)
            {System.out.print("\nInvalid Entry: Input must be a Number.\n"); System.exit(0);}
    }
    // Main Method
    public static void main(String[] args)
    {   new PointOfSale(); }
}
  • 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-24T22:05:34+00:00Added an answer on May 24, 2026 at 10:05 pm

    You are comparing strings for equality in your getProduct() method. Strings are objects, so you probably want to use the equals() method:

    public void getProduct(String code)
    {   if(code.equals("A001")){
            setCode("A001");
            setItemName("Mouse  ");
            setPrice(100);}
        else if(code.equals("A002")){
            setCode("A002");
            setItemName("Monitor    ");
            setPrice(2500);}
        else if(code.equals("A003")){
            setCode("A003");
            setItemName("Keyboard");
            setPrice(200);}
        else if(code.equals("A004")){
            setCode("A004");
            setItemName("Flash Disk");
            setPrice(300);}
        else if(code.equals("A005")){
            setCode("A005");
            setItemName("Hard Disk");
            setPrice(1500);}
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all here are some code snippets: public void startThread() { this.animationThread =
first at all, here is my code: string pdfTemplate = Application.StartupPath + \\Templates\\Template Medico.pdf;
First of all here what i'm trying to accomplish: Get the sum of etp_product.price
First of all, here's my code: var users = {}; //User Connect io.sockets.on('connection', function
First of all, here is my code snippet: var str = '<!--:de-->some german text<!--:--><!--:en-->some
first of all here is my code: @protocol SearchTableViewControllerDelegate @required - (void)didSelectFileCardsContent:(FileCardsContent*)content; @end @interface
Hi all first post here :) Let's start with a snippet of the code
First of all here is my code so that you can test it to
First of all i'm new in here and new with csharp. just exhausted while
First of all I've gone through dozens of posting here on SO and google

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.