EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
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
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…
Use Java programming language Write a program that asks the user to enter 5 test grades (use an array to store them). Output the grades entered, the lowest and highest grade, the average grade, how many grades are above the average and how many are below and the letter grade for the average grade. Create a method that returns the lowest grade. Create a method that returns the highest grade. Create a method that returns the average grade. Create a method that returns how many grades were above the average. Create a method that returns how many grades were below the average. Create a method that returns the letter grade of the average (90-100 - A, 80-89 - B, 70-79 - C, < 70 - F)
Use Java programming language Write a program that asks the user to enter 5 test grades (use an array to store them). Output the grades entered, the lowest and highest grade, the average grade, how many grades are above the average and how many are below and the letter grade for the average grade. Create a method that returns the lowest grade. Create a method that returns the highest grade. Create a method that returns the average grade. Create a method that returns how many grades were above the average. Create a method that returns how many grades were below the average. Create a method that returns the letter grade of the average (90-100 – A, 80-89 – B, 70-79 – C, < 70 – F)
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
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