Java Programming
Java Programming
8th Edition
ISBN: 9781305981829
Author: Joyce Farrell
Publisher: Cengage Limited
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 9, Problem 7PE

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 that takes the invoice number

    public void setInvoiceNumber(int num)

    {

        //Assign the value

        invoiceNumber = num;

    }

    //Define a set method that takes the amount of sale

    public void setSaleAmount(double amt)

    {

        //Assign the value

        saleAmount = amt;

        //Compute the sales tax

        tax = saleAmount * RATE;

    }

    //Define a get method that returns the amount of sale

    public double getSaleAmount()

    {

        //Return the value

        return saleAmount;

    }

    //Define a get method that returns the invoice number

    public int getInvoiceNumber()

    {

        //Return the value

        return invoiceNumber;

    }

    /*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: “SortPurchasesArray.java

//Import necessary header files

import java.util.Scanner;

//Define a class named SortPurchasesArray

public class SortPurchasesArray

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare an array of five Purchase objects

        Purchase[] purchases = new Purchase[5];

        //Declare the variables

        int i;

        String message;

        char choice;

        final char QUIT = 'Z';

        int number;

        double price;

        //Create an object for Scanner class

        Scanner keyboard = new Scanner(System.in);

        //For loop to be executed until i exceeds 5

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

        {

            //Prompt the user to enter the invoice number

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

            number = keyboard.nextInt();

            //Prompt the user to enter the amount of sale

            System.out.print("Enter sale amount >> ");

            price = keyboard.nextDouble();

            purchases[i] = new Purchase();

            //Function call

            purchases[i].setInvoiceNumber(number);

            purchases[i].setSaleAmount(price);

        }

        keyboard.nextLine();

        /*Prompt the user to enter whether the Purchase objects

        should be sorted and displayed in invoice number

        order or sale amount order*/

System.out.print("\nSort Purchases by (I)nvoice number, or (S)ale amount? ");

        choice = keyboard.nextLine()...

Blurred answer
Students have asked these similar questions
Q.1. Architecture performance [10 marks] Answer A certain microprocessor requires either 2, 4, or 6 machine cycles to perform various operations. ⚫ (40+g+f)% require 2 machine cycles, ⚫ (30-g) % require 4 machine cycles, and ⚫ (30-f)% require 6 machine cycles. (a) What is the average number of machine cycles per instruction for this microprocessor? Answer (b) What is the clock rate (machine cycles per second) required for this microprocessor to be a "1000 MIPS" processor? Answer (c) Suppose that 35% of the instructions require retrieving an operand from memory which needs an extra 8 machine cycles. What is the average number of machine cycles per instruction, including the instructions that fetch operands from memory?
Q.2. Architecture performance [25 marks] Consider two different implementations, M1 and M2, of the same instruction set. M1 has a clock rate of 2 GHz and M2 has a clock rate of 3.3 GHz. There are two classes of instructions with the following CPIs: Class A CPI for M1 CPI for M2 2.f 1.g B 5 3 C 6 4 Note that the dots in 2 fand 1.g indicate decimal points and not multiplication. a) What are the peak MIPS performances for both machines? b) Which implementation is faster, if half the instructions executed in a certain program are from class A, while the rest are divided equally among classes B and C. c) What speedup factor for the execution of class-A instructions would lead to 20% overall speedup? d) What is the maximum possible speedup that can be achieved by only improving the execution of class-A instructions? Explain why. e) What is the clock rate required for microprocessor M1 to be a "1000 MIPS" (not peak MIPS) processor?
PLEASE SOLVE STEP BY STEP WITHOUT ARTIFICIAL INTELLIGENCE OR CHATGPT I don't understand why you use chatgpt, if I wanted to I would do it myself, I need to learn from you, not from being a d amn robot. SOLVE  STEP BY STEP I WANT THE DIAGRAM PERFECTLY IN SIMULINK
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
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,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License