Skip to content

Commit 5879ca8

Browse files
committed
Corrected the invoice files.
1 parent dd95b10 commit 5879ca8

File tree

5 files changed

+113
-59
lines changed

5 files changed

+113
-59
lines changed

Chapter05/src/Invoices/Invoice2.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package Invoices;
2+
/**
3+
* Created by Kimberly Henry <kimberly.henry@outlook.com>
4+
* On: Jul at: 10:06 PM.
5+
* Project: Java Programming
6+
* Package: Invoices
7+
* File: Invoice2
8+
* Modify the constructor in the Invoice class so that the day is not greater
9+
* than 31, 30, or 28, depending on the month. For example, if a user tries
10+
* to create an invoice for April 31, force it to April 30. Also, if the month
11+
* is invalid, and thus forced to 0, also force the day to 0. Save the modified
12+
* Invoice class as Invoice2.java.
13+
*/
14+
public class Invoice2
15+
{
16+
private int invoiceNumber;
17+
private double balanceDue;
18+
private int month;
19+
private int day;
20+
private int year;
21+
public Invoice2(int invoice, double balance, int mth, int d, int yr)
22+
{
23+
invoiceNumber = invoice;
24+
balanceDue = balance;
25+
month = mth;
26+
day = d;
27+
year = yr;
28+
if (invoice < 1000)
29+
{
30+
invoice = 0;
31+
if (invoice == 0)
32+
{
33+
System.out.println("Invoice INVALID: ");
34+
}
35+
}
36+
if ((month == 2 && day > 28) || (month == 1 && day > 31) || (month == 3 && day > 31)
37+
|| (month == 5 && day > 31) || (month == 7 && day > 31) || (month == 8 && day > 31)
38+
|| (month == 10 && day > 31) || (month == 12 && day > 31) || (month == 4 && day > 30)
39+
|| (month == 6 && day > 30) || (month == 9 && day > 30) || (month == 11 && day > 30))
40+
{
41+
switch (month)
42+
{
43+
case 1:
44+
case 3:
45+
case 5:
46+
case 7:
47+
case 8:
48+
case 10:
49+
case 12:
50+
day = 31;
51+
break;
52+
case 2:
53+
day = 28;
54+
break;
55+
case 4:
56+
case 6:
57+
case 9:
58+
case 11:
59+
day = 30;
60+
break;
61+
default:
62+
System.out.println("Month INVALID or Day, Day set to last of the month");
63+
}
64+
}
65+
}
66+
public void displayInvoice()
67+
{
68+
System.out.println("Invoice Number: " + invoiceNumber);
69+
System.out.println("Due Date: " + month + "-" + day + "-" + year);
70+
System.out.println("Balance Due: " + balanceDue);
71+
}
72+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package Invoices;
2+
/**
3+
* Created by Kimberly Henry <kimberly.henry@outlook.com>
4+
* On: Jul at: 9:02 PM.
5+
* Project: Java Programming
6+
* Package: Invoices
7+
* File: TestInvoice2
8+
* Then modify the TestInvoice class to create Invoice2 objects.
9+
* Create enough objects to test every decision in the constructor.
10+
* Save this file as TestInvoice2.java.
11+
*/
12+
public class TestInvoice2
13+
{
14+
public static void main(String[] args)
15+
{
16+
Invoice2 test001 = new Invoice2(999, 56.00, 1, 32, 2014);
17+
Invoice2 test002 = new Invoice2(5423, 56.00, 2, 31, 2014);
18+
Invoice2 test003 = new Invoice2(1235, 56.00, 3, 32, 2014);
19+
Invoice2 test004 = new Invoice2(8563, 56.00, 4, 31, 2014);
20+
Invoice2 test005 = new Invoice2(9999, 56.00, 5, 32, 2014);
21+
Invoice2 test006 = new Invoice2(2222, 56.00, 6, 31, 2014);
22+
Invoice2 test007 = new Invoice2(1111, 56.00, 7, 32, 2014);
23+
Invoice2 test008 = new Invoice2(4444, 56.00, 8, 32, 2014);
24+
Invoice2 test009 = new Invoice2(5555, 56.00, 9, 31, 2014);
25+
Invoice2 test010 = new Invoice2(6666, 56.00, 10, 32, 2014);
26+
Invoice2 test011 = new Invoice2(7777, 56.00, 11, 31, 2014);
27+
Invoice2 test012 = new Invoice2(8888, 56.00, 12, 32, 2014);
28+
test001.displayInvoice();
29+
test002.displayInvoice();
30+
test003.displayInvoice();
31+
test004.displayInvoice();
32+
test005.displayInvoice();
33+
test006.displayInvoice();
34+
test007.displayInvoice();
35+
test008.displayInvoice();
36+
test009.displayInvoice();
37+
test010.displayInvoice();
38+
test011.displayInvoice();
39+
test012.displayInvoice();
40+
}
41+
}

Problems/src/Invoices/Invoice2.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)