Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

There are 3 tasks to be accomplished  Write Java program and classes according to the…

  1. User

    There are 3 tasks to be accomplished  Write Java program and classes according to the requirement  Let all the classes to be public and each class into a .java file  Write your main program as a main class name them: "TestTask1", "TestTask2" and "TestTask3"

    public class Ram16GB { private double price; public Ram16GB() { price = 40.0; } public double getPrice() { return price; } } Task 1 (1) Define all the classes in the table (2)Write your main program to create an instance and print the price per each class Hard Drive 75.0CompactHardDrive75.0 Compact Hard Drive 64.0 Large Capacity Hard Drive 130.0SSD130.0 SSD 80.0 Large Capacity SSD 120.016GBMemoryModule(Ram16GB)120.0 16GB Memory Module (Ram16GB) 40.0 32GB Memory Module (Ram32GB) 69.0EfficientProcessor69.0 Efficient Processor 306.0 Powerful Processor $589.0

  2. Assistant

    Here is the Java program to accomplish Task 1:

    public class HardDrive {
        private double price;
        
        public HardDrive() {
            price = 75.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class CompactHardDrive {
        private double price;
        
        public CompactHardDrive() {
            price = 64.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class LargeCapacityHardDrive {
        private double price;
        
        public LargeCapacityHardDrive() {
            price = 130.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class SSD {
        private double price;
        
        public SSD() {
            price = 80.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class LargeCapacitySSD {
        private double price;
        
        public LargeCapacitySSD() {
            price = 120.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class Ram16GB {
        private double price;
        
        public Ram16GB() {
            price = 40.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class Ram32GB {
        private double price;
        
        public Ram32GB() {
            price = 69.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class EfficientProcessor {
        private double price;
        
        public EfficientProcessor() {
            price = 306.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class PowerfulProcessor {
        private double price;
        
        public PowerfulProcessor() {
            price = 589.0;
        }
        
        public double getPrice() {
            return price;
        }
    }
    
    public class TestTask1 {
        public static void main(String[] args) {
            HardDrive hardDrive = new HardDrive();
            CompactHardDrive compactHardDrive = new CompactHardDrive();
            LargeCapacityHardDrive largeCapacityHardDrive = new LargeCapacityHardDrive();
            SSD ssd = new SSD();
            LargeCapacitySSD largeCapacitySSD = new LargeCapacitySSD();
            Ram16GB ram16GB = new Ram16GB();
            Ram32GB ram32GB = new Ram32GB();
            EfficientProcessor efficientProcessor = new EfficientProcessor();
            PowerfulProcessor powerfulProcessor = new PowerfulProcessor();
            
            System.out.println("Hard Drive $" + hardDrive.getPrice());
            System.out.println("Compact Hard Drive $" + compactHardDrive.getPrice());
            System.out.println("Large Capacity Hard Drive $" + largeCapacityHardDrive.getPrice());
            System.out.println("SSD $" + ssd.getPrice());
            System.out.println("Large Capacity SSD $" + largeCapacitySSD.getPrice());
            System.out.println("16GB Memory Module (Ram16GB) $" + ram16GB.getPrice());
            System.out.println("32GB Memory Module (Ram32GB) $" + ram32GB.getPrice());
            System.out.println("Efficient Processor $" + efficientProcessor.getPrice());
            System.out.println("Powerful Processor $" + powerfulProcessor.getPrice());
        }
    }
    

    This program defines all the necessary classes and their respective prices. The main program creates instances of each class and prints the price per class.