-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCitrus.java
More file actions
51 lines (39 loc) · 1.26 KB
/
Copy pathCitrus.java
File metadata and controls
51 lines (39 loc) · 1.26 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
package Demo2_Fruit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
public class Citrus extends Fruit implements Serializable {
private double VitaminC;
public Citrus() {
}
public Citrus(String name, String color, double vitaminC) {
super(name, color);
VitaminC = vitaminC;
}
public double getVitaminC() {
return VitaminC;
}
public void setVitaminC(double vitaminC) {
VitaminC = vitaminC;
}
@Override
public void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter citrus name: ");
setName(br.readLine());
System.out.println("Enter citrus color: ");
setColor(br.readLine());
System.out.println("Enter vitamin C for citrus: ");
setVitaminC(Integer.parseInt((br.readLine())));
System.out.println("new fruit add");
}
@Override
public String output(Fruit citrus) {
return citrus.toString();
}
@Override
public String toString() {
return "\nFruit name: " + getName() + "\tfruit color: " + getColor() + "\tvitamin C: " + getVitaminC() + "Gr\n";
}
}