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

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...
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...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String Bread - of type String Price - of type Double Include get and set methods for these fields. The methods should be prefixed with 'get' or 'set' respectively, followed by the field name using camel case. For example, setMainIngredient. Use the application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods to test your class. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student 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. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT