NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package classWork;

public abstract class Computer {

private String brand;
private String processor;
private int ram;
private int hdd;

// Constructors
public Computer() {
}

public Computer(String brand, String processor, int ram, int hdd) {
this.brand = brand;
this.processor = processor;
this.ram = ram;
this.hdd = hdd;
}

// Setters and getters
public String getBrand() {
return brand;
}

public void setBrand(String brand) {
this.brand = brand;
}

public String getProcessor() {
return processor;
}

public void setProcessor(String processor) {
this.processor = processor;
}

public int getRam() {
return ram;
}

public void setRam(int ram) {
this.ram = ram;
}

public int getHdd() {
return hdd;
}

public void setHdd(int hdd) {
this.hdd = hdd;
}

// Abstract method to be implemented by subclasses
public abstract void display();
}

package classWork;

public class Desktop extends Computer {
// Constructors

public Desktop() {
super();
}

public Desktop(String brand, String processor, int ram, int hdd) {
super(brand, processor, ram, hdd);
}

// Implementation of the abstract method
@Override
public void display() {
System.out.println("Desktop Configuration: ");
System.out.println("Brand: " + getBrand());
System.out.println("Processor: " + getProcessor());
System.out.println("RAM: " + getRam() + "GB");
System.out.println("HDD: " + getHdd() + "GB");
}
}

package classWork;

public class Laptop extends Computer {
// Constructors

public Laptop() {
super();
}

public Laptop(String brand, String processor, int ram, int hdd) {
super(brand, processor, ram, hdd);
}

// Implementation of the abstract method
@Override
public void display() {
System.out.println("Laptop Configuration: ");
System.out.println("Brand: " + getBrand());
System.out.println("Processor: " + getProcessor());
System.out.println("RAM: " + getRam() + "GB");
System.out.println("HDD: " + getHdd() + "GB");
}
}

package classWork;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Create Desktop object
Desktop desktop = new Desktop();
System.out.println("Enter Desktop details:");
System.out.print("Brand: ");
desktop.setBrand(scanner.nextLine());
System.out.print("Processor: ");
desktop.setProcessor(scanner.nextLine());
System.out.print("RAM (GB): ");
desktop.setRam(scanner.nextInt());
System.out.print("HDD (GB): ");
desktop.setHdd(scanner.nextInt());
scanner.nextLine(); // Consume newline

// Create Laptop object using constructor overloading
System.out.println("nEnter Laptop details:");
System.out.print("Brand: ");
String brand = scanner.nextLine();
System.out.print("Processor: ");
String processor = scanner.nextLine();
System.out.print("RAM (GB): ");
int ram = scanner.nextInt();
System.out.print("HDD (GB): ");
int hdd = scanner.nextInt();

Laptop laptop = new Laptop(brand, processor, ram, hdd);

// Demonstrate polymorphism
System.out.println("nDisplaying configurations:");
Computer[] computers = {desktop, laptop};
for (Computer computer : computers) {
computer.display();
System.out.println();
}

scanner.close();
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.