• Tidak ada hasil yang ditemukan

lab10solution.docx

N/A
N/A
Protected

Academic year: 2025

Membagikan "lab10solution.docx"

Copied!
5
0
0

Teks penuh

(1)

Exercise 1.

package Lab10;

public class Invoice { private String PartNo;

private String Partdesc;

private int Qty_Item;

private double Price;

public Invoice() {

PartNo = null;

Partdesc = null;

Qty_Item = 0;

Price = 0.0;

}

public Invoice(String pn,String pd,int qi,double pr) {

setpn(pn);

setpd(pd);

setq(qi);

setpr(pr);

}

public void setpn(String pn) {

PartNo = pn;

}

public void setpd(String pd) {

Partdesc = pd;

}

public void setq(int q) {

Qty_Item =((q>0)?q:0);

}

public void setpr(double pr) {

Price = ((pr>0)?pr:0);

}

public String getpn() {

return PartNo;

}

public String getpd() {

return Partdesc;

}

public int getq() {

(2)

return Qty_Item;

}

public double getpr() {

return Price;

}

public double getInvoiceAmount() {

double totamt = 0.0;

totamt = (double)Qty_Item*Price;

return totamt;

}

public void Display() {

System.out.println("Part No. in Invoice "+PartNo);

System.out.println("Part Description in Invoice "+Partdesc);

System.out.println("Item Quantity in Invoice "+Qty_Item);

System.out.println("Unit price of Single Item "+Price);

System.out.println("Accumulate amount of all Item "+getInvoiceAmount());

} }

package Lab10;

public class InvoiceP { /**

* @param args */

public static void main(String[] args) { // use for loop or while //for (int I = 1; i<=3; i++){

Invoice In = new Invoice("Ab123","Gear box",23,56.78);

In.Display();

In.setq(70);

In.Display();

// create new object

// use set method for all attributes // call display

//}

} }

Exercise 2 package lab11;

public class Date { private int d,m,y;

(3)

public Date() {

d = 1;

m = 1;

y = 1;

}

public Date(int day, int month, int year) {

d = day;

m = month;

y = year;

}

public void setday(int day) {

d = day;

}

public void setmonth(int month) {

m= month;

}

public void setyear(int year) {

y = year;

}

public int getday() {

return d;

}

public int getmonth() {

return m;

}

public int getyear() {

return y;

}

public void increment() {

d++;

if(d>30) {

d-=30;

m++;

if(m>12) {

m-=12;

y++;

}

(4)

} }

public void decrement() {

if(d!=1) d--;

else{

d = 30;

if(m!=1) m--;

else{

m = 12;

y--;

if(y==0){

increment();

System.out.println("Error!!!");

} }

} }

public void display(){

System.out.println("Date:"+d+"/"+m+"/"+y);

//System.out.println("Date increment:");

} }

package lab11;

public class DateTest {

public static void main(String[] args) { Date d1 = new Date();

Date d2 = new Date(1,1,2001);

Date d3 = new Date(30,12,2001);

d1.increment();

d2.increment();

d3.increment();

d1.display();

d2.display();

d3.display();

d1.decrement();

d3.decrement();

//d1.decrement();

d1.display();

d3.display();

}

(5)

}

Referensi

Dokumen terkait

Item and Description Country of origin Qty Unit Unit price EXW per item Transportation and Insurance and all other costs incidental to delivery, per item Sales and other taxes

Item and Description Country of origin Qty Unit Unit price EXW per item Transportation and Insurance and all other costs incidental to delivery, per item Sales and other taxes

Item and Description Country of origin Qty Unit Unit price EXW per item Transportation and Insurance and all other costs incidental to delivery, per item Sales and other

Item and Description Country of origin Qty Unit Unit price EXW per item Transportation and Insurance and all other costs incidental to delivery, per item Sales and other taxes

Item and Description Country of origin Qty Unit Unit price EXW per item Transportation and Insurance and all other costs incidental to delivery, per item Sales and other taxes

Qty./ Unit Item Description Specifications Function Unit Price Php Total Price Php 1 1 unit Laboratory Roaster  2 horizontal drum design  80-100 grams capacity per drum  Heat

Qty./ Unit Item Description Particulars Specifications Unit Price Php Total Price Php 1 1 Brand New Van 18- seater Engine Type 4 Cylinder ₱1,500,000.00 ₱1,500,000.00 Engine

Qty./ Unit Item Description Specifications Unit Price Php Total Price Php 1 1 Adult Patient Simulator  Full body simulator  Capable of speech recognition  Oral, nasal and