Concept explainers
a.
Explanation of Solution
Program:
File name: “Purchase.java”
//Define a class named Purchase
public class Purchase
{
//Declare the private variables
private int invoiceNumber;
private double saleAmount;
private double tax;
private static final double RATE = 0.05;
//Define a set method for the invoice number
public void setInvoiceNumber(int num)
{
invoiceNumber = num;
}
//Define a set method for the sale amount
public void setSaleAmount(double amt)
{
//Calculate the sales tax as 5% of the sale amount
saleAmount = amt;
tax = saleAmount * RATE;
}
�...
b.
Explanation of Solution
Program:
File name: “CreatePurchase.java”
//Import necessary header files
import javax.swing.*;
//Define a class named CreatePurchase
public class CreatePurchase
{
//Define a main method
public static void main(String[] args)
{
//Declare Purchase object
Purchase purch = new Purchase();
//Declare the variables
int num;
double amount;
String entry;
final int LOW = 1000, HIGH = 8000;
//Prompt the user to enter the invoice number
entry = JOptionPane.showInputDialog(null, "Enter invoice number");
num = Integer.parseInt(entry);
/*While the user does not enter a number between 1,000 and 8,000*/
while(num <= LOW || num >= HIGH)
{
//Print the message
entry = JOptionPane.showInputDialog(null, "Invoice number must be between " +
LOW + " and " + HIGH + "\nEnter invoice number");
num = Integer...
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
- I CANT GET IT RIGHT Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method for the sale amount, calculate the sales tax as 5% of the sale amount. Also include a display method that displays a purchase’s details. CODE import java.util.Scanner; class CreatePurchase { publicstaticvoidmain(Stringargs[]) { Purchase purchase=newPurchase(); Scanner s=newScanner(System.in); System.out.println("Enter the details: "); while(true) { System.out.print("Enter invoice number[between 1000 and 8000]: "); int i=s.nextInt(); if(i>=1000&& i<=8000){purchase.setInvoiceNumber(i);break;} else System.out.println("Wrong entry,enter again"); } while(true) { System.out.print("Enter amount of purchase[should be non-negative]: "); int i=s.nextInt(); if(i>=0){purchase.setAmountOfSales(i);break;} else System.out.println("Wrong entry,enter again"); }…arrow_forwardFor each of the following exercises, you may choose to write a console-based or GUI application, or both. Write a program for The Carefree Resort named ResortPrices that prompts the user to enter the number of days for a resort stay. Then display the price per night and the total price. Nightly rates are $200 for one or two nights; $180 for three or four nights; $160 for five, six, or seven nights; and $145 for eight nights or more.arrow_forwardIn this exercise, you modify the Grade Calculator application from this chapter’s Apply lesson. Use Windows to make a copy of the Grade Solution folder. Rename the copy Grade Solution-Intermediate. Open the Grade Solution.sln file contained in the Grade Solution-Intermediate folder. Open the CourseGrade.vb file. The DetermineGrade method should accept an integer that represents the total number of points that can be earned in the course. (Currently, the total number of points is 200: 100 points per test.) For an A grade, the student must earn at least 90% of the total points. For a B, C, and D grade, the student must earn at least 80%, 70%, and 60%, respectively. If the student earns less than 60% of the total points, the grade is F. Make the appropriate modifications to the DetermineGrade method and then save the solution. Unlock the controls on the form. Add a label control and a text box to the form. Change the label control’s Text property to “&Maximum points:” (without the quotation marks). Change the text box’s name to txtMax. Lock the controls and then reset the tab order. Open the form’s Code Editor window. The txtMax control should accept only numbers and the Backspace key. Code the appropriate procedure. The grade should be cleared when the user makes a change to the contents of the txtMax control. Code the appropriate procedure. Modify the frmMain_Load procedure so that each list box displays numbers from 0 through 200. Locate the btnDisplay_Click procedure. If the txtMax control does not contain a value, display an appropriate message. The maximum number allowed in the txtMax control should be 400; if the control contains a number that is more than 400, display an appropriate message. The statement that calculates the grade should pass the maximum number of points to the studentGrade object’s DetermineGrade method. Make the necessary modifications to the procedure. Save the solution and then start and test the application.arrow_forward
- For each of the following exercises, you may choose to write a console-based or GUI application, or both. Write a program named TestScoreList that accepts eight int values representing student test scores. Display each of the values along with a message that indicates how far it is from the average.arrow_forwardAccount numbers sometimes contain a check digit that is the result of a mathematical calculation. The inclusion of the digit in an account number helps ascertain whether the number is a valid one. Write an application named CheckDigit that asks a user to enter a four-digit account number and determines whether it is a valid number. The number is valid if the fourth digit is the remainder when the number represented by the first three digits of the four-digit number is divided by 7. For example, 7770 is valid, because 0 is the remainder when 777 is divided by 7. The next problems rely on the generation of a random number. You can create a random number that is at least mi n but less than max using the following statements: Random ranNumberCenerator = new Random(); int randomNumber; randomNumber = ranNumberGenerator .Next(min, max);arrow_forwardDanielle, Edward, and Francis are three salespeople at Holiday Homes. Write an application named HomeSales that prompts the user for a salesperson initial (D, E, or F). Either uppercase or lowercase initials are valid. While the user does not type Z, continue by prompting for the amount of a sale. Issue an error message for any invalid initials entered. Keep a running total of the amounts sold by each salesperson. After the user types Z or z for an initial, display each salespersons total, a grand total for all sales, and the name of the salesperson with the highest total.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage