EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
8th Edition
ISBN: 9781305480537
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
Expert Solution & Answer
Book Icon
Chapter 8, Problem 11PE

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 method to set the invoice number

    public void setInvoiceNumber(int num)

    {

        invoiceNumber = num;

    }

    //Define a method to set the amount of sale

    public void setSaleAmount(double amt)

    {

        saleAmount = amt;

        //Calculate the amount of sales tax

        tax = saleAmount * RATE;

    }

    /*Define a method to display the invoice number,

    amount of sale, and amount of sales tax*/

    public void display()

    {

        //Print the result

        System.out.println("Invoice #" + invoiceNumber +

         "  Amount of sale: $" + saleAmount + "  Tax: $" + tax);

    }

}

File name: “PurchaseArray.java

//Import necessary header files

import java.util.*;

//Define a class named PurchaseArray

public class PurchaseArray

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare a purchases object

        Purchase[] purchases = new Purchase[5];

        //Declare the variables

        int num;

        double amount;

        String entry;

        //Create an object for Scanner class

        Scanner input = new Scanner(System.in);

        //Declare the variables and initialize the values

        int x;

        final int LOW = 1000, HIGH = 8000;

       //For loop to be executed until x exceeds 5

        for(x = 0; x < purchases.length; ++x)

        {

            purchases[x] = new Purchase();

            //Prompt the user to enter an invoice number

            System.out.print("Enter invoice number >> ");

            num = input...

Blurred answer
Students have asked these similar questions
This is the question I am stuck on - In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Now, write a program that declares an array of five Purchase objects and prompt a user for their values. As each Purchase object is created, continuously prompt until the user enters an invoice number between 1000 and 8000 inclusive and a non-negative sale amount. Prompt the user for values for each object and then display all the values. This is the code that I am unsure where to fully start -  public class Purchase {    private int invoiceNumber;    private double saleAmount;    private double tax;    private static final double RATE = 0.05;    public void setInvoiceNumber(int num)    {       invoiceNumber = num;    }    public void setSaleAmount(double amt)    {       saleAmount = amt;       tax = saleAmount * RATE;    }    public double getSaleAmount()    {       return…
I got part of this code right but the other part I dont this is the question - In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Now, write a program that declares an array of five Purchase objects and prompt a user for their values. As each Purchase object is created, continuously prompt until the user enters an invoice number between 1000 and 8000 inclusive and a non-negative sale amount. Prompt the user for values for each object and then display all the values. This is the code I have -  public class Purchase {    private int invoiceNumber;    private double saleAmount;    private double tax;    private static final double RATE = 0.05;    public void setInvoiceNumber(int num)    {       invoiceNumber = num;    }    public void setSaleAmount(double amt)    {       saleAmount = amt;       tax = saleAmount * RATE;    }    public double getSaleAmount()    {       return…
This is the question I am stuck on - In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Add get methods for the invoice number and sale amount fields so their values can be used in comparisons. Next, write a program that declares an array of five Purchase objects and prompt a user for their values. Then, in a loop that continues until a user inputs a sentinel value of Z, ask the user whether the Purchase objects should be sorted and displayed in invoice number order or sale amount order. This is the code I have -  public class Purchase {    private int invoiceNumber;    private double saleAmount;    private double tax;    private static final double RATE = 0.05;    public void setInvoiceNumber(int num)    {       invoiceNumber = num;    }    public void setSaleAmount(double amt)    {       saleAmount = amt;       tax = saleAmount * RATE;    }    public double…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,