Question

In: Computer Science

Create a class named Purchase. Each Purchase contains an invoice number, amount of sale, and amount...

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.

Here is the provided code:

import java.util.*;
public class CreatePurchase
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Purchase purch = new Purchase();
int num;
double amount;
String entry;
final int LOW = 1000, HIGH = 8000;
System.out.println("Enter invoice number");
entry = input.next();
num = Integer.parseInt(entry);
while(num <= LOW || num >= HIGH)
{
System.out.println("Invoice number must be between " +
LOW + " and " + HIGH + "\nEnter invoice number");
entry = input.next();
num = Integer.parseInt(entry);
}
  
System.out.println("Enter sale amount");
entry = input.next();
amount = Double.parseDouble(entry);
while(amount < 0)
{
System.out.println("Enter sale amount");
entry = input.next();
amount = Double.parseDouble(entry);
}
purch.setInvoiceNumber(num);
purch.setSaleAmount(amount);
purch.display();
}
}

------------------------------------------------------------------------------------------------

Other Class:

_--_____________________________

public class Purchase {
private int invoiceNumber;
private double saleAmount;
private double tax;
private static final double RATE = 0.05;
public void setInvoiceNumber(int num) {
}
public void setSaleAmount(double amt) {
}
public double getSaleAmount() {
}
public int getInvoiceNumber() {
}
public void display() {
System.out.println("Invoice #" + invoiceNumber +
" Amount of sale: $" + saleAmount + " Tax: $" + tax);
}
}

pls help

Solutions

Expert Solution

import java.util.*;
public class CreatePurchase
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int num;
        double amount;
        String entry;
        final int LOW = 1000, HIGH = 8000;
        System.out.println("Enter invoice number");
        entry = input.next();
        num = Integer.parseInt(entry);
        while(num <= LOW || num >= HIGH)
        {
            System.out.println("Invoice number must be between " +
                    LOW + " and " + HIGH + "\nEnter invoice number");
            entry = input.next();
            num = Integer.parseInt(entry);
        }

        System.out.println("Enter sale amount");
        entry = input.next();
        amount = Double.parseDouble(entry);
        while(amount < 0)
        {
            System.out.println("Enter sale amount");
            entry = input.next();
            amount = Double.parseDouble(entry);
        }
        Purchase purch = new Purchase(num, amount);

        purch.setInvoiceNumber(num);
        purch.setSaleAmount(amount);
        purch.display();
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////

public class Purchase {
    private int invoiceNumber;
    private double saleAmount;
    private double tax;
    private static final double RATE = 0.05;

    public Purchase(int invoiceNumber, double saleAmount) {
        this.invoiceNumber = invoiceNumber;
        this.saleAmount = saleAmount;
        tax = saleAmount*0.05;
    }

    public void setInvoiceNumber(int num) {
    }
    public void setSaleAmount(double amt) {
    }
    public double getSaleAmount() {
        return saleAmount;
    }
    public int getInvoiceNumber() {
        return invoiceNumber;
    }
    public void display() {
        System.out.println("Invoice #" + invoiceNumber +
                " Amount of sale: $" + saleAmount + " Tax: $" + tax);
    }
}

Related Solutions

Create a class named Employee and its child class named Salesperson. Save each class in its...
Create a class named Employee and its child class named Salesperson. Save each class in its own file. Name your class and source code file containing the main method homework.java. Make sure each class follows these specifications: 1. An employee has a name (String), employee id number (integer), hourly pay rate (double), a timesheet which holds the hours worked for the current week (double array) and email address (String). A salesperson also has a commission rate, which is a percentage...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
in c#: Create a class named Square that contains fields for area and the length of...
in c#: Create a class named Square that contains fields for area and the length of a side and whose constructor requires a parameter for the length of one side of a Square. The constructor assigns its parameter to the length of the Square’s side field and calls a private method that computes the area field. Also include read-only properties to get a Square’s side and area. Create a class named DemoSquares that instantiates an array of ten Square objects...
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
Invoice Class - Create a class called Invoice that a hardware store might use to represent...
Invoice Class - Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables—a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. If the quantity passed to the constructor is...
3.12 (Invoice Class) Create a class called Invoice that a hardware store might use to represent...
3.12 (Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables-a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for...
Please solve using jupyter notebook . 10.10- (Invoice Class) Create a class called Invoice that a...
Please solve using jupyter notebook . 10.10- (Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as data attributes—a part number (a string), a part description (a string), a quantity of the item being purchased (an int) and a price per item (a Decimal). Your class should have an __init__ method that initializes the four data attributes....
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other...
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT