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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:38:40+00:00 2026-06-01T00:38:40+00:00

This is a kind of a newb question but I’m really new to programming

  • 0

This is a kind of a newb question but I’m really new to programming and I’m only a little over a week into a programming course in grade 11. We use Java, and work with Netbeans.

What I’m working on right now is this:

During a special sale at a store, a 10% discount is taken off of
purchases over $10.00.

Create an application that prompts the user for the amount of
purchases and then returns the discounted price, as well as the
discount amount itself.

My Code:

 DecimalFormat x = new DecimalFormat ("$###.00");
 double purchases, discount, finalPrice;
 purchases = Double.parseDouble (purchaseInput.getText ());
 if (purchases >= 10) {
     discount = purchases * 0.10;
 }    
 else { 
     discount = 0;
 }
 finalPrice = purchases - discount;
 discountOutput.setText (discount);
 finalPriceOutput.setText (finalPrice);

The problem is the last two lines. I’m trying to set the values to text fields. It says that it is finding double, but needs java.lang.String. I tried changing them to a string with double.toString () but it says the double can’t be dereferenced. I’m pretty confused right now, please help.

I’m sure the fix isn’t very complicated, but I’ve looked every content section we have learned so far twice and still cant find how to fix my problem.

  • 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-01T00:38:41+00:00Added an answer on June 1, 2026 at 12:38 am

    You already have a DecimalFormat to convert doubles to strings. So try this:

     DiscountOutput.setText(x.format(Discount));
     FinalPriceOutput.setText(x.format(FinalPrice));
    

    You can also do it without using DecimalFormat, but the result will be slightly different because the numbers are not formatted as “$###.00”:

     DiscountOutput.setText(Discount.toString());
     FinalPriceOutput.setText(FinalPrice.toString());
    

    Also, as a suggestion, I think money quantities look better when you use “$#,##0.00“. That way you have thousands separator (,) and fractions of a dollar show up like $0.51 instead of $.51, which looks weird. So do:

     DecimalFormat x = new DecimalFormat ("$#,##0.00");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Total newb to .NET programming (and AJAX) but I've been working on this program
I know this kind of question is asked a lot but I have a
This is probably quite a newb question, but I can't seem to figure it
This kind of seems like a noob question, but I could not find an
This kind of code would normally work in PHP, but since the scope is
I have this kind of question. In my form, i got this as a
This kind of goes along with my original question about has_many :through with conditions,
Quick question: is this kind of nesting possible? An if statement first passing a
This kind of builds up on Already asked question ... However here, say, I'm
This question is kind of related to our web application and it is bugging

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.