1. Create a class Invoice that includes four pieces of information as instant va
ID: 3542857 • Letter: 1
Question
1. Create a class Invoice that includes four pieces of information as instant variables
Create a class Invoice that includes four pieces of information as instant variables - partID (type int), partDescription (type string), quantity (type int) and pricePerPiece (type int). Your class should have a constructor that takes 4 parameters and initializes the four instant variables. Provide a set and get functions for each instant variable. Provide a method names getInvouceAmount () that gives the invoice amount (multiplies the quantity by the price per item), then returns the amount as an integer value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should e set to 0. Use the set methods to check for valid values and use your set functions in your constructor. Write a test class InvoiceTest that demonstrates class Invoice's capabilities. please enter part ID:111 Please enter part description: Saw please enter part quantity : 10 please enter part price: 5Explanation / Answer
Full working code tested in eclipse .
have any doubts or need clarifications - post here
liked solution - please rate best
import java.io.InputStreamReader;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class OnlineStore {
int partId ;
String partDescription;
int quantity;
int pricePerPiece;
public OnlineStore(int id,String desc,int quant,int price){
partId = id;
partDescription = desc;
if(quant<0) setquantity(0);
else quantity = quant;
if (price<0) setPPP( 0);else pricePerPiece = price;
}
public void setID(int id){
partId= id;
}
public void setdescription(String id){
partDescription= id;
}public void setquantity(int id){
quantity= id;
}public void setPPP(int id){
pricePerPiece= id;
}
public int getID(){
return partId;
}
public String getdesc(){
return partDescription;
}public int getquantity(){
return quantity;
}public int getPPP(){
return pricePerPiece;
}
public double getinvoiceamount(){
return (double)getquantity()*getPPP();
}
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.print("Please enter part ID: ");
int id=Integer.parseInt(in.nextLine());
System.out.println(id);
System.out.print("Please enter part Description: ");
String des=in.nextLine();
System.out.println(des);
System.out.print("Please enter quantity: ");
int q=in.nextInt();
System.out.println(q);
//if(q<0) q=0;
System.out.print("Please enter price per part: ");
int p=in.nextInt();
System.out.println(p);
//if(p<0) p=0;
OnlineStore o=new OnlineStore(id, des, q, p);
//display result in a JOptionPane message dialog
JOptionPane.showMessageDialog( null, "The total amount for "+o.getquantity()+ "parts of ID"+o.getID()+" , "+ o.getdesc()+" is KD " +o.getinvoiceamount(),"Message", JOptionPane.PLAIN_MESSAGE );
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.