Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.launchcode;
import java.util.ArrayList;

public abstract class BaseDisc {
private String name;
private int storageCapacity;
private int remainingCapacity;
private int capacityUsed;
private String diskType;
private ArrayList<String> contents;

public BaseDisc(String aName, int maxCapacity, String aType, int someUsedCapacity) {
name = aName;
storageCapacity = maxCapacity;
diskType = aType;
capacityUsed = checkCapacity(someUsedCapacity);
remainingCapacity = spaceLeft();
}

private int checkCapacity(int dataWritten) {
if (storageCapacity < dataWritten){
return storageCapacity;
}
return dataWritten;
}

private int spaceLeft(){
return storageCapacity - capacityUsed;
}

public String diskInfo(){
String output = String.format("\nDisk Name: %s\nMax capacity: %d" +
"\nSpace used: %d" +
"\nAvailable space: %d\n", name, storageCapacity, capacityUsed, remainingCapacity);
return output;
}

public String writeData(int dataSize){
if (dataSize > remainingCapacity){
return "Not enough disc space!";
}
capacityUsed += dataSize;
remainingCapacity -= dataSize;

return "Data written to disc. Remaining space = " + remainingCapacity;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package org.launchcode;

public class CD {
// TODO: Implement your custom interface.
public class CD extends BaseDisc implements OpticalDisc{

// TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones
// need to be declared separately.
public CD(String aName, int maxCapacity, String aType, int someUsedCapacity){
super(aName, maxCapacity, aType, someUsedCapacity);
}

@Override
public void spinDisc() {
System.out.println("A CD spins at a rate of 200 - 500 rpm.");
}

@Override
public void readData() {
System.out.println("Would you like to play a game?");
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
package org.launchcode;

public class DVD {
// TODO: Implement your custom interface.
public class DVD extends BaseDisc implements OpticalDisc {

public DVD(String aName, int maxCapacity, String aType, int someUsedCapacity) {
super(aName, maxCapacity, aType, someUsedCapacity);
}

@Override
public void spinDisc() {
System.out.println("A DVD spins at a rate of 570 - 1600 rpm.");
}

@Override
public void readData() {
System.out.println("I'm sorry, Dave. I'm afraid I can't do that.");
}


// TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones
// need to be declared separately.
}


Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package org.launchcode;

public class Main {
public static void main(String[] args) {

// TODO: Declare and initialize a CD and a DVD object.
public static void main(String[] args){

// TODO: Call each CD and DVD method to verify that they work as expected.
CD cd = new CD("CD Example", 700, "CD-R", 350);
DVD dvd = new DVD("DVD Example", 4700, "DVD-R", 1450);

cd.spinDisc();
dvd.spinDisc();

cd.readData();
dvd.readData();

System.out.println(cd.writeData(275));
System.out.println(dvd.writeData(8000));

System.out.println(cd.diskInfo());
System.out.println(dvd.diskInfo());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.launchcode;

public interface OpticalDisc {
void spinDisc();
void readData();
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.