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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:05:40+00:00 2026-05-29T16:05:40+00:00

I have been fighting with this for quite some time and have found a

  • 0

I have been fighting with this for quite some time and have found a couple useful resources, yet the problem persists.

Here’s my code:

import java.util.Scanner;

public class Stocks {

public static void main(String [] args){

    // value of stock at beginning of year and end of year.
    final int beginningStock = 10;
    final int endStock = 20;


    // value of stocks by quarter; there are three quarters. 
    int firstQuarter;
    int secondQuarter;
    int thirdQuarter;
    String broker;
    String Buy;

    firstQuarter = 10;
    secondQuarter = 30;
    thirdQuarter = 20;

    //Tell client the maximum value/price of the stock during the year.     
    System.out.println("The maximum price of a stock share in the year is: $" + secondQuarter + ".");

    // Tell client the minimum value/price of the stock during the year.
    System.out.println("The minimum price of a stock share in the year is: $" + firstQuarter + ".");

    //Ask broker if you want to buy or sell
    Scanner input = new Scanner(System.in);

    System.out.println("Would you like to Buy or Sell stocks? Please use Buy or Sell commands.");
    broker = input.next("");

    if (broker == "Buy"){
        //Calculate percentage increase of stock through year if the broker wants the client to buy.
        //The values are relative to the start of the year.
        double percentIncrease;

        percentIncrease = (double)(endStock - beginningStock)/(beginningStock);

        //Convert decimal to percentage and tell client percentage increase relative to beginning of year.
        System.out.println("The percentage increase of the stock through the year, relative to beginning of year, is: %"+ ((int)(percentIncrease*100+.5))+ "." );


    }

    else if (broker == "Sell"){
        //Calculate change relative to end of year
        double endIncrease;

        endIncrease = (double)(endStock - beginningStock)/(endStock);

        //Convert decimal to percentage and tell client percentage increase relative to end of year.
        System.out.println("The percentage increase of the stock through the year, relative to end of year, is: %"+ ((int)(endIncrease*100))+ "." );

    }

    }
}

The issue I am having is around line 29:

//Ask broker if you want to buy or sell
    Scanner input = new Scanner(System.in);

    System.out.println("Would you like to Buy or Sell stocks? Please use Buy or Sell commands.");
    broker = input.next("");

    if (broker == "Buy"){
        //Calculate percentage increase of stock through year if the broker wants the client to buy.
        //The values are relative to the start of the year.
        double percentIncrease;

        percentIncrease = (double)(endStock - beginningStock)/(beginningStock);

        //Convert decimal to percentage and tell client percentage increase relative to beginning of year.
        System.out.println("The percentage increase of the stock through the year, relative to beginning of year, is: %"+ ((int)(percentIncrease*100+.5))+ "." );

It will take the String but will not use it. I don’t know what I am doing wrong. Forgive me this is my first post on here.

  • 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-29T16:05:41+00:00Added an answer on May 29, 2026 at 4:05 pm

    The problem is that == tests for reference-equality rather than value-equality; that is, it checks that the two sides are the same object, rather than equivalent objects. You need to change this:

        if (broker == "Buy"){
    

    to this:

        if (broker.equals("Buy")){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been fighting this issue for some time so today I started a
I have been fighting this problem with the help of a RegEx cheat sheet,
I've been fighting this crazy problem for hours and have gotten nowhere. I have
For the last 2 hours I have been fighting with this problem and trying
I have been fighting with a wiered yet simple problem. I have a Data
Have been working on this question for a couple hours and have come close
I've been fighting this for a while, seems I'm close but not quite there.
I've been fighting with jQuery all night and getting quite frustrated here, so forgive
I've been fighting this all day. Inside my styles.xml file I have color information
I have been fighting with this error for a while. The error is somewhere

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.