JAVA PROGRAMMING-LMS INTEG.MINDTAP
JAVA PROGRAMMING-LMS INTEG.MINDTAP
8th Edition
ISBN: 9781337091503
Author: FARRELL
Publisher: Cengage Learning
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
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)
Design an application that declares an array of 10 StockTransactionobjects. Prompt the user for data for each object, and then display all the values. Design an application that declares an array of 10 StockTransactionobjects. Prompt the user for data for each object, and then pass the array to a method that determines and displays the two stocks with the highest and lowest price per share.
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