NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

abstract class Computer {

private String brand;
private String processor;
private int ram; // in gigabytes
private int hdd; // in gigabytes

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

public String getBrand() {
return brand;
}

public String getProcessor() {
return processor;
}

public int getRam() {
return ram;
}

public int getHdd() {
return hdd;
}

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

class Desktop extends Computer {

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

@Override
public void displayDetails() {
System.out.println("Desktop Details:");
System.out.println("Brand: " + getBrand());
System.out.println("Processor: " + getProcessor());
System.out.println("RAM: " + getRam() + " GB");
System.out.println("HDD: " + getHdd() + " GB");
}
}

class Laptop extends Computer {

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

@Override
public void displayDetails() {
System.out.println("Laptop Details:");
System.out.println("Brand: " + getBrand());
System.out.println("Processor: " + getProcessor());
System.out.println("RAM: " + getRam() + " GB");
System.out.println("HDD: " + getHdd() + " GB");
}
}







public class ComputerTest {

public static void main(String[] args) {
Desktop desktop = new Desktop("Dell", "Intel Core i7", 16, 1000);
Laptop laptop = new Laptop("HP", "Intel Core i5", 8, 512);

System.out.println("Desktop Details:");
displayComputerDetails(desktop);

System.out.println();

System.out.println("Laptop Details:");
displayComputerDetails(laptop);
}

public static void displayComputerDetails(Computer computer) {
computer.displayDetails();
}
}







///////////setmethod
abstract class Computer {
private String brand;
private String processor;
private int ram; // in gigabytes
private int hdd; // in gigabytes



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

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

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

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

class Desktop extends Computer {

}

class Laptop extends Computer {

}


////get

abstract class Computer {
private String brand;
private String processor;
private int ram; // in gigabytes
private int hdd; // in gigabytes

// Constructor and setter methods remain the same

public String getBrand() {
return brand;
}

public String getProcessor() {
return processor;
}

public int getRam() {
return ram;
}

public int getHdd() {
return hdd;
}
}

class Desktop extends Computer {
// Constructor and other methods remain the same
}

class Laptop extends Computer {
// Constructor and other methods remain the same
}




user input uotput/////////////////////////////////////////////////

import java.util.Scanner;

public class ComputerTest2 {

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

System.out.println("Enter details for Desktop:");
System.out.print("Enter brand: ");
String desktopBrand = scanner.nextLine();

System.out.print("Enter processor: ");
String desktopProcessor = scanner.nextLine();

System.out.print("Enter RAM (in GB): ");
int desktopRam = scanner.nextInt();
scanner.nextLine(); // Consume newline character

System.out.print("Enter HDD (in GB): ");
int desktopHdd = scanner.nextInt();
scanner.nextLine(); // Consume newline character

Desktop desktop = new Desktop(desktopBrand, desktopProcessor, desktopRam, desktopHdd);

// Getting user input for Laptop
System.out.println("nEnter details for Laptop:");
System.out.print("Enter brand: ");
String laptopBrand = scanner.nextLine();

System.out.print("Enter processor: ");
String laptopProcessor = scanner.nextLine();

System.out.print("Enter RAM (in GB): ");
int laptopRam = scanner.nextInt();
scanner.nextLine(); // Consume newline character

System.out.print("Enter HDD (in GB): ");
int laptopHdd = scanner.nextInt();
scanner.nextLine(); // Consume newline character

Laptop laptop = new Laptop(laptopBrand, laptopProcessor, laptopRam, laptopHdd);

scanner.close();

// Displaying details
System.out.println("nDesktop Details:");
displayComputerDetails(desktop);

System.out.println("nLaptop Details:");
displayComputerDetails(laptop);
}

public static void displayComputerDetails(Computer computer) {
computer.displayDetails();
}
}











     
 
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.