Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Computer Science Object Oriented Programming Question 3.13 (Invoice Class) Creat

ID: 3879167 • Letter: C

Question

Computer Science Object Oriented Programming Question

3.13 (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 data members-a part num- ber (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type int). [Note: In subsequent chapters, we'll use numbers that contain decimal points (e.g., 2.75)-called floating-point values-to represent dollar amounts.) Your class should have a constructor that initializes the four data members. A constructor that receives multiple arguments is defined with the form: ClassNameC TpeNamel parameterNamel, TpeName2 parameterName2, ) Provide a set and a get function for each data member. In addition, provide a member function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as an int value. If the quantity is not positive, it should boe set to o. If the price per item is not positive, it should be set to o. Write a test program that demon- strates class Invoice's capabilities. 3.14 (Employee Class) Create a class called Employee that includes three pieces of information as data members-a first name (type string), a last name (type string) and a monthly salary (type int). [Note: In subsequent chapters, we'll use numbers that contain decimal points (e.g, 2.75)- called floating-point values-to represent dollar amounts.] Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0·Write a test program that demonstrates class Employee's capabilities. Create two Employee objects and display each object's yearly salary. Then give each Em- ployee a 10 percent raise and display each Employee's yearly salary again. 3.15 (Date Class) Create a class called Date that includes three pieces of information as data members-a month (type int), a day (type int) and a year (type int). Your class should have a con- structor with three parameters that uses the parameters toi purpose of this exercise, assume that the values provided for the year and day are correct, but ensure that the month value is in the range 1-12; if it isn't, set the month to 1. Provide a set and a get func- tion for each data member. Provide a member function displayDate that displays the month, day nitialize the three data members. For the and year separated by forward slashes). Write a test program that demonstrates class Date's capa- ties.

Explanation / Answer

3.13:

SourceCode:

import java.util.Scanner;

class Invoice{

String partNumber;

String partDescription;

int itemPurchased;

double pricePerItem;



Invoice()

partNumber = "";

partDescription = "";

itemPurchased = 0;

pricePerItem = 0.0;

}



String getPartNumber(){
return partNumber;

}

String getPartDescription(){

return partDescription;

}

int getItemPurchased(){

return itemPurchased;

}

double getPricePerItem(){

return pricePerItem;

}

double getInvoiceAmount(){

return (itemPurchased * pricePerItem);

}

void setPartNumber(String pn){

partNumber = pn;

}

void setPartDescription(String pd){

partDescription = pd;

}

void setItemPurchased(int ip){

itemPurchased = ip;

}

void setPricePerItem(double ppi){

pricePerItem = ppi;

}



}

class InvoiceDemo {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

Invoice invoice = new Invoice();

System.out.print(" Enter part number :");

invoice.setPartNumber(sc.nextLine());

System.out.print("Enter part description :");

invoice.setPartDescription(sc.nextLine());

System.out.print("Enter item purchased :");

invoice.setItemPurchased(sc.nextInt());

System.out.print("Enter price per item :");

invoice.setPricePerItem(sc.nextDouble());

System.out.print(" Detail of items purchasing-->");

System.out.print(" Part number :" + invoice.getPartNumber());

System.out.print(" Part description :" + invoice.getPartDescription());

System.out.print(" Total Billing Amount :" + invoice.getInvoiceAmount());

}

}

//Hi, if you have any quiries please comment in here, and do rate the solution if it is helpful to you...Thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote