-
Notifications
You must be signed in to change notification settings - Fork 686
Expand file tree
/
Copy pathBaseDisc.java
More file actions
56 lines (44 loc) · 1.6 KB
/
BaseDisc.java
File metadata and controls
56 lines (44 loc) · 1.6 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
package org.launchcode;
public abstract class BaseDisc {
// Fields
//name : Store the name of the disc
private String name;
//Store the storage capacity of the disc
private double storageCapacity;
//Store the data content of the disc
private String contents;
// Constructors
//Initializes the name and storage capacity of the disc and sets the initial contents to an empty string.
//Getters and Setters: Provide access to the fields.
public BaseDisc(String name, double storageCapacity) {
this.name = name;
this.storageCapacity = storageCapacity;
this.contents = "";
}
// Getters and Setters
public String getName() {
return name;
}
public double getStorageCapacity() {
return storageCapacity;
}
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
// Custom Methods
// Represents the common spinning behavior for all optical discs. This method is inherited by both CD and DVD classes but can be overridden.
public void spinDisc() {
// This method can be common for both CD and DVD
System.out.println("A disc spins.");
}
//Represents the common behavior for ejecting a disc
public void ejectDisc() {
// Common method for ejecting a disc
System.out.println("Ejecting the disc.");
}
// An abstract method that forces subclasses (CD and DVD) to provide their own implementation to return information about the disc
public abstract String discInfo();
}