Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Device class:
- public class Device {
- protected String brand;
- protected String model;
- protected double price;
- public Device(){
- }
- public Device(String brand, String model, double price) {
- this.brand = brand;
- this.model = model;
- this.price = price;
- }
- public String getBrand() {
- return brand;
- }
- public void setBrand(String brand) {
- this.brand = brand;
- }
- public String getModel() {
- return model;
- }
- public void setModel(String model) {
- this.model = model;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- @Override
- public String toString() {
- return "Brand: " + brand + ", " + "Model: " + model + ", " + "Price: " + price;
- }
- }
- BrokenDevice class:
- public class BrokenDevice extends Device{
- private String symptoms;
- private int repairDays;
- public BrokenDevice(String brand, String model, double price, String symptoms, int repairDays) {
- super(brand, model, price);
- this.symptoms = symptoms;
- this.repairDays = repairDays;
- }
- public String getSymptoms() {
- return symptoms;
- }
- public void setSymptoms(String symptoms) {
- this.symptoms = symptoms;
- }
- public int getRepairDays() {
- return repairDays;
- }
- public void setRepairDays(int repairDays) {
- this.repairDays = repairDays;
- }
- @Override
- public String toString() {
- return super.toString() + ", " + "Symptoms: " + symptoms + ", " + "Days needed for repair: " + repairDays;
- }
- }
- Service class:
- import java.util.ArrayList;
- public class Service {
- ArrayList<Device> goodCondDevices;
- ArrayList<BrokenDevice> badCondDevices;
- public Service(ArrayList<Device> goodCondDevices, ArrayList<BrokenDevice> badCondDevices) {
- this.goodCondDevices = goodCondDevices;
- this.badCondDevices = badCondDevices;
- }
- public void addDevice(Device deviceToAdd){
- this.goodCondDevices.add(deviceToAdd);
- }
- public void addBrokenDevice(BrokenDevice brokenDeviceToAdd){
- this.badCondDevices.add(brokenDeviceToAdd);
- }
- public void brokenToGood(BrokenDevice brokenDeviceRepaired){
- this.goodCondDevices.add(brokenDeviceRepaired);
- this.badCondDevices.remove(brokenDeviceRepaired);
- }
- public void printBySymptom(String symptom){
- for(BrokenDevice device: this.badCondDevices){
- if(device.getSymptoms().equals(symptom)){
- System.out.println(device);
- }
- }
- }
- public double wholePrice(){
- double sum = 0;
- for(Device device: this.goodCondDevices){
- sum+= device.getPrice();
- }
- for(BrokenDevice device: this.badCondDevices){
- sum+= device.getPrice();
- }
- return sum;
- }
- @Override
- public String toString() {
- StringBuilder str = new StringBuilder();
- str.append("All Devices in good quality:" + '\n') ;
- for (Device device: goodCondDevices){
- str.append(device.toString() + '\n');
- }
- str.append("All Devices in bad quality:" + '\n') ;
- for (BrokenDevice device: badCondDevices){
- str.append(device.toString() + '\n');
- }
- return str.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement