Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Practice Access the following Java source file: DiscountCost.java using this link. Debug the program and get it running in its current form (using Scanner

Programming Practice

Access the following Java source file: DiscountCost.java using this link.

Debug the program and get it running in its current form (using Scanner input/output)

Once the program is debugged, change the input/output strategy to use dialog boxes instead of the Scanner console.

Instead of hard-coding the 0.2 in the code for a 20% discount, declare a final constant identifier to replace the value in the existing calculation.

/ This program calculates the sale price of an / item that is regularly priced at $59, with / a 20 percent discount subtracted. import java.util.Scanner; // Needed for the Scanner class public class Discount { public void main(String() args) { Variables to hold the regular price, the amount of a discount, and the sale price. double regularPrice = 59.0; double salePrice; // Create a Scanner object to read input scanner keyboard = new Scanner(System.input) // Get the regular price System.out.print('Enter regular price: '); regularPrice = key.next(); // Calculate the amount of a 20% discount. discount = regularPrice * 0.20; // Calculate the sale price by subtracting // the discount from the regular price. salePrice - regularPrice - discount; // Display the results. system.println("Regular price: $ + regularprice); system.println(Discount amount $" + discount); system.println("Sale price: $" + total); }1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions