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

  • Home
  • SEARCH
  • 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 7797509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:42:24+00:00 2026-06-01T23:42:24+00:00

The assignment is: Write a program that provides 20% discount for member who purchase

  • 0

The assignment is:

Write a program that provides 20% discount for member who purchase any two books at XYZ bookstore. (Hint: Use constant variable to the 20% discount.)

I have done the coding, but cannot prompt book name, and then show the discounted price. Please see my coding below and modify it as your needs.

import java.util.Scanner;

public class Book_Discount {
  public static void main(String args[]) {
  public static final double d = 0.8;
  Scanner input = new Scanner(System.in);

  int purchases;
  double discounted_price;
  System.out.print("Enter value of purchases: ");

  purchases = input.nextInt();
  discounted_price = purchases * d; // Here discount calculation takes place

  // Displays discounted price
  System.out.println("Value of discounted price: " + discounted_price); 
  }

}
  • 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-01T23:42:25+00:00Added an answer on June 1, 2026 at 11:42 pm

    For prompting the book name as well, you write something like:

    /* Promt how many books */
    System.out.print("How many books? ");
    int bookCount = scanner.nextInt();
    scanner.nextLine(); // finish the line...
    double totalPrice = 0.0d; // create a counter for the total price
    
    /* Ask for each book the name and price */
    for (int i = 0; i < bookCount; ++i)
    {
        System.out.print("Name of the book? ");
        String name = scanner.nextLine();  // get the name
        System.out.print("Price of the book? ");
        double price = scanner.nextDouble(); // get the price
        scanner.nextLine(); // finish the line
        totalPrice += price; // add the price to the counter
    }
    
    /* If you bought more than 1 book, you get discount */
    if (bookCount >= 2)
    {
        totalPrice *= 0.8d;
    }
    
    /* Print the resulting price */
    System.out.printf("Total price to pay: %.2f%n", totalPrice);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: my assignment was to write a program that uses linked list to keep
A while back we were given an assignment to write a c program that
I have a class assignment where I have to write a program that will
My class assignment is to write a program that has the user input a
*My assignment is to write a program that stores an array of five int
for an assignment I have to write a program that will take in an
I'm working on a homework assignment that requires me to write a program that
For class I have an assignment: Write a C++ program that will output the
I've got an assignment to write a server program that accepts multiple clients. I'm
Here is the assignment verbatim: 1.) Write a Java program that is a TCP

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.