Question

Language: Java / Python Topic: Invoices

Language: Java / Python

Topic: Invoices

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

public class Invoice implements Payable
{
   private String partNumber; 
   private String partDescription;
   private int quantity;
   private double pricePerItem;

   // four-argument constructor
   public Invoice( String part, String description, int count, 
      double price )
   {
      partNumber = part;
      partDescription = description;
      setQuantity( count ); // validate and store quantity
      setPricePerItem( price ); // validate and store price per item
   } // end four-argument Invoice constructor

   // set part number
   public void setPartNumber( String part )
   {
      partNumber = part;  
   } // end method setPartNumber

   // get part number
   public String getPartNumber()
   {
      return partNumber;
   } // end method getPartNumber

   // set description
   public void setPartDescription( String description )
   {
      partDescription = description;
   } // end method setPartDescription

   // get description
   public String getPartDescription()
   {
      return partDescription;
   } // end method getPartDescription

   // set quantity
   public void setQuantity( int count )
   {
      quantity = ( count < 0 ) ? 0 : count; // quantity cannot be negative
   } // end method setQuantity

   // get quantity
   public int getQuantity()
   {
      return quantity;
   } // end method getQuantity

   // set price per item
   public void setPricePerItem( double price )
   {
      pricePerItem = ( price < 0.0 ) ? 0.0 : price; // validate price
   } // end method setPricePerItem

   // get price per item
   public double getPricePerItem()
   {
      return pricePerItem;
   } // end method getPricePerItem

   // return String representation of Invoice object
   public String toString()
   {
      return String.format( "%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f", 
         "invoice", "part number", getPartNumber(), getPartDescription(), 
         "quantity", getQuantity(), "price per item", getPricePerItem() );
   } // end method toString

   // method required to carry out contract with interface Payable
   public double getPaymentAmount() 
   {
      return getQuantity() * getPricePerItem(); // calculate total cost
   } // end method getPaymentAmount
} // end class Invoice

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Language: Java / Python Topic: Invoices
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language: Python Topic: APIs and JSON Function name: can_visit Parameters: country_code (str), langList (list of strings...

    Language: Python Topic: APIs and JSON Function name: can_visit Parameters: country_code (str), langList (list of strings ) Return: boolean Description: You are looking for a country to visit for SB2K19 and want to ensure that you know how to speak at least one of the languages spoken in that country. Given a country_code (str), a three - letter code representing the country you want to visit, and a langList (list), a list of the names of the languages you know...

  • Has to be in Java programming language Java Python mirrorLength We'll say that a "mirror" section...

    Has to be in Java programming language Java Python mirrorLength We'll say that a "mirror" section in an array is a group of contiguous elements such that somewhere in the array, the same group appears in reverse order. For example, the largest mirror section in {1, 2, 3, 8, 9, 3, 2, 1} is length 3 (the {1, 2, 3} part). Return the size of the largest mirror section found in the given array. 3 mirrorLength([1, 2, 3, 8, 9,...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python code that gets a string from the user and counts the number of uppercase letters, the number of lowercase letters, the number of digits, and the sum of the digits. Please see the outcome below: Outcome: Enter the string: okOKE9o7 Uppercase letters: 3 Lowercase letters: 3 Digits: 2 Sum of digits: 8 Must look exactly like outcome for full credit.

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function named capital_letter that accepts a string as an argument and checks if each word in the string begins with a capital letter. If so, the function will return true, otherwise, return false. Please see the outcome below: Outcome number 1: Enter a string: Python Is Really Fun! True Sample run number 2: Enter a string: i Love Python False Note: Try to keep this...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is sued. Write a Python...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is sued. Write a Python code that gets a string containing a person’s first, middle, and last name, and print her/his last name, followed by comma and the first name initial. For example, if the user enters Randy Rick Gomez, the program should display Gomez, R. Please note that in the output, the first character of each name should be capital. Please see the outcomes below: Outcome: Enter your...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python statement that creates a two-dimensional list named values with 3 rows and 2 columns. Then write nested loops that get an integer value from the user for each element in the list. Then display the content of the list. Please see the outcome below: Outcome run: Enter the 1 element in the 1 row :1 Enter the 2 element in the 1 row :2...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python statement that creates a two-dimensional list named values with 3 rows and 2 columns. Then write nested loops that get an integer value from the user for each element in the list. Then display the content of the list. Please see the outcome below: Outcome run: Enter the 1 element in the 1 row :1 Enter the 2 element in the 1 row :2...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT