-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay20.java
More file actions
101 lines (82 loc) · 2.3 KB
/
Day20.java
File metadata and controls
101 lines (82 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// ---------------------------------------------------
// Author : Benjamin Kataliko Viranga
// Community : Stunt Business
// Community website : www.stuntbusiness.com
//
// 30 Days - Q&A Java basic
// Day 20 : Mini Store : Employees, Items and the Store | item.
// Day 20 | IG : https://www.instagram.com/benjivrik/
// ----------------------------------------------------
// what would be the output of this program ?
/**
*
* Create an Item for your store.
* Give a name, a category, a price
* For the category : let's say we mean vegetables, fruits,etc.
*
*/
class Item
{
public String name;
public String category;
public double price;
public Item(String name, String category, double price)
{
this.name = name;
this.category = category;
this.price = price;
}
// getters
public String getItemName()
{
return this.name;
}
public String getItemCategory()
{
return this.category;
}
public double getPrice()
{
return this.price;
}
// setters
public void setItemName(String name)
{
this.name = name;
}
public void setItemCategory(String category)
{
this.category = category;
}
public void setItemPrice(double price)
{
this.price = price;
}
// for displaying your object
public String toString()
{
System.out.println("\n************** DISPLAYING ITEM INFO **************\n");
String employee = String.format(
"\nItem name : %s\nItem category : %s\nItem price : %s CAD \n",this.name,this.category,this.price
);
return employee;
}
}
public class Day20
{
public static void main(String[] args)
{
Item banana = new Item("Banana","Fruits", 12.5);
Item carrot = new Item("Carrot","Vegetables", 10);
// display your items in your terminal
System.out.println(banana);
System.out.println(carrot);
System.out.println("Changing the price of the items.");
// change the price of your first item to 15 and the second item to 13
banana.setItemPrice(15);
carrot.setItemPrice(13);
// display your items in your terminal
System.out.println(banana);
System.out.println(carrot);
}
}