Skip to content

Commit e207e72

Browse files
author
java-tester-x
committed
Exercise: The Discount System
1 parent cedcbfe commit e207e72

12 files changed

+282
-0
lines changed

src/ex7/DiscountSystem/Customer.class

1.31 KB
Binary file not shown.

src/ex7/DiscountSystem/Customer.ctxt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#BlueJ class context
2+
comment0.params=name
3+
comment0.target=Customer(java.lang.String)
4+
comment1.params=
5+
comment1.target=java.lang.String\ getName()
6+
comment2.params=
7+
comment2.target=boolean\ isMember()
8+
comment3.params=member
9+
comment3.target=void\ setMember(boolean)
10+
comment4.params=
11+
comment4.target=java.lang.String\ getMemberType()
12+
comment5.params=type
13+
comment5.target=void\ setMemberType(java.lang.String)
14+
comment6.params=
15+
comment6.target=java.lang.String\ toString()
16+
numComments=7

src/ex7/DiscountSystem/Customer.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
/**
3+
* The Discount System: Customer.
4+
*/
5+
public class Customer
6+
{
7+
private String name;
8+
private boolean member = false;
9+
private String memberType;
10+
11+
public Customer(String name)
12+
{
13+
this.name = name;
14+
}
15+
16+
public String getName() {
17+
return name;
18+
}
19+
20+
public boolean isMember() {
21+
return member;
22+
}
23+
24+
public void setMember(boolean member) {
25+
this.member= member;
26+
}
27+
28+
public String getMemberType() {
29+
return memberType;
30+
}
31+
32+
public void setMemberType(String type) {
33+
memberType = type;
34+
}
35+
36+
public String toString() {
37+
return String.format("Customer %1$s %2$s member."
38+
, name, (member ? "is the "+memberType : "is not a"));
39+
}
40+
}
491 Bytes
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#BlueJ class context
2+
comment0.params=
3+
comment0.target=CustomerTest()
4+
comment0.text=\r\n\ Default\ constructor\ for\ test\ class\ CustomerTest\r\n
5+
comment1.params=
6+
comment1.target=void\ setUp()
7+
comment1.text=\r\n\ Sets\ up\ the\ test\ fixture.\r\n\r\n\ Called\ before\ every\ test\ case\ method.\r\n
8+
comment2.params=
9+
comment2.target=void\ tearDown()
10+
comment2.text=\r\n\ Tears\ down\ the\ test\ fixture.\r\n\r\n\ Called\ after\ every\ test\ case\ method.\r\n
11+
numComments=3
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
3+
import static org.junit.Assert.*;
4+
import org.junit.After;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
/**
9+
* The test class CustomerTest.
10+
*
11+
* @author (your name)
12+
* @version (a version number or a date)
13+
*/
14+
public class CustomerTest
15+
{
16+
/**
17+
* Default constructor for test class CustomerTest
18+
*/
19+
public CustomerTest()
20+
{
21+
}
22+
23+
/**
24+
* Sets up the test fixture.
25+
*
26+
* Called before every test case method.
27+
*/
28+
@Before
29+
public void setUp()
30+
{
31+
}
32+
33+
/**
34+
* Tears down the test fixture.
35+
*
36+
* Called after every test case method.
37+
*/
38+
@After
39+
public void tearDown()
40+
{
41+
}
42+
}

src/ex7/DiscountSystem/Discount.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
/**
3+
* Write a description of class Discount here.
4+
*
5+
* @author (your name)
6+
* @version (a version number or a date)
7+
*/
8+
public class Discount
9+
{
10+
// instance variables - replace the example below with your own
11+
private int x;
12+
13+
/**
14+
* Constructor for objects of class Discount
15+
*/
16+
public Discount()
17+
{
18+
// initialise instance variables
19+
x = 0;
20+
}
21+
22+
/**
23+
* An example of a method - replace this comment with your own
24+
*
25+
* @param y a sample parameter for a method
26+
* @return the sum of x and y
27+
*/
28+
public int sampleMethod(int y)
29+
{
30+
// put your code here
31+
return x + y;
32+
}
33+
}

src/ex7/DiscountSystem/README.TXT

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
------------------------------------------------------------------------
2+
This is the project README file. Here, you should describe your project.
3+
Tell the reader (someone who does not know anything about this project)
4+
all he/she needs to know. The comments should usually include at least:
5+
------------------------------------------------------------------------
6+
7+
PROJECT TITLE:
8+
PURPOSE OF PROJECT:
9+
VERSION or DATE:
10+
HOW TO START THIS PROJECT:
11+
AUTHORS:
12+
USER INSTRUCTIONS:

src/ex7/DiscountSystem/Visit.class

1.37 KB
Binary file not shown.

src/ex7/DiscountSystem/Visit.ctxt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#BlueJ class context
2+
comment0.params=name\ date
3+
comment0.target=Visit(java.lang.String,\ java.util.Date)
4+
comment1.params=
5+
comment1.target=java.lang.String\ getName()
6+
comment2.params=
7+
comment2.target=double\ getServiceExpense()
8+
comment3.params=ex
9+
comment3.target=void\ setServiceExpense(double)
10+
comment4.params=
11+
comment4.target=double\ getProductExpense()
12+
comment5.params=ex
13+
comment5.target=void\ setProductExpense(double)
14+
comment6.params=
15+
comment6.target=double\ getTotalExpense()
16+
comment7.params=
17+
comment7.target=java.lang.String\ toString()
18+
numComments=8

src/ex7/DiscountSystem/Visit.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
import java.util.Date;
3+
4+
/**
5+
* The Discount System: Visit.
6+
*/
7+
public class Visit
8+
{
9+
private Customer customer;
10+
private Date date;
11+
private double serviceExpense;
12+
private double productExpense;
13+
14+
public Visit(String name, Date date)
15+
{
16+
this.customer = new Customer(name);
17+
this.date = date;
18+
}
19+
20+
public String getName() {
21+
return customer.getName();
22+
}
23+
24+
public double getServiceExpense() {
25+
return serviceExpense;
26+
}
27+
28+
public void setServiceExpense(double ex) {
29+
serviceExpense = ex;
30+
}
31+
32+
public double getProductExpense() {
33+
return productExpense;
34+
}
35+
36+
public void setProductExpense(double ex) {
37+
productExpense = ex;
38+
}
39+
40+
public double getTotalExpense() {
41+
return serviceExpense + productExpense;
42+
}
43+
44+
public String toString() {
45+
return String.format("Visit of customer %1$s at date %2$s"
46+
, customer.toString(), date.toString());
47+
}
48+
}

src/ex7/DiscountSystem/package.bluej

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#BlueJ package file
2+
dependency1.from=Visit
3+
dependency1.to=Customer
4+
dependency1.type=UsesDependency
5+
objectbench.height=76
6+
objectbench.width=616
7+
package.editor.height=683
8+
package.editor.width=516
9+
package.editor.x=3
10+
package.editor.y=27
11+
package.numDependencies=1
12+
package.numTargets=4
13+
package.showExtends=true
14+
package.showUses=true
15+
project.charset=UTF-8
16+
target1.association=CustomerTest
17+
target1.editor.height=850
18+
target1.editor.width=790
19+
target1.editor.x=648
20+
target1.editor.y=21
21+
target1.height=50
22+
target1.name=Customer
23+
target1.naviview.expanded=true
24+
target1.showInterface=false
25+
target1.type=ClassTarget
26+
target1.typeParameters=
27+
target1.width=80
28+
target1.x=90
29+
target1.y=100
30+
target2.editor.height=700
31+
target2.editor.width=900
32+
target2.editor.x=43
33+
target2.editor.y=47
34+
target2.height=50
35+
target2.name=CustomerTest
36+
target2.naviview.expanded=true
37+
target2.showInterface=false
38+
target2.type=UnitTestTargetJunit4
39+
target2.typeParameters=
40+
target2.width=110
41+
target2.x=120
42+
target2.y=70
43+
target3.height=50
44+
target3.name=Discount
45+
target3.showInterface=false
46+
target3.type=ClassTarget
47+
target3.typeParameters=
48+
target3.width=80
49+
target3.x=220
50+
target3.y=230
51+
target4.editor.height=844
52+
target4.editor.width=733
53+
target4.editor.x=5
54+
target4.editor.y=28
55+
target4.height=50
56+
target4.name=Visit
57+
target4.showInterface=false
58+
target4.type=ClassTarget
59+
target4.typeParameters=
60+
target4.width=80
61+
target4.x=350
62+
target4.y=100

0 commit comments

Comments
 (0)