EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 6, Problem 15PE

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...

Blurred answer
Students have asked these similar questions
a. 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. Save the file as Purchase.java. b. Create an application that declares a Purchase object and prompts the user for purchase details. When you prompt for an invoice number, do not let the user proceed until a number between 1,000 and 8,000 has been entered. When you prompt for a sale amount, do not proceed until the user has entered a nonnegative value. After a valid Purchase object has been created, dispO the object's invoice number, sale amount, and sales tax. Save the file as CreatePurchase.java.
Kinetic Energy In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object’s kinetic energy: KE =1/2mv2 In the formula KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second. Create an application that allows the user to enter an object’s mass and velocity and then displays the object’s kinetic energy. The application should have a method named KineticEnergy that accepts an object’s mass (in kilograms) and velocity (in meters per second) as arguments. The method should return the amount of kinetic energy that the object has.
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"); }…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY