Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Write an app. that has a class named Laptop w/ attributes named laptopMake (e

ID: 3773925 • Letter: 4

Question


4. Write an app. that has a class named Laptop w/ attributes named laptopMake (e.g. Dell, HP), laptopRAM, and serialNumber, and also getters and setters for each of these fields (see. text p. 353-5 for an example class). Create a LaptopArrayDemo class that asks the user to create 3 Laptop instances and use an array to store pointers to each, and then prints them all out (see p. 448-9 for an example of this type of logic note we'll need to pass the array as an arg to a create Laptops (Laptop[ array) method similar to the code at the bottom of 448.

Explanation / Answer

import java.util.*;

public class LaptopArrayDemo {
private static String laptopMake;
private static String laptopRAM;
private static String Serialnum;

public LaptopArrayDemo() {
   // TODO Auto-generated constructor stub
}

public String getLaptopMake() {
   return laptopMake;
}

public void setLaptopMake(String laptopMake) {
   this.laptopMake = laptopMake;
}


public String getLaptopRAM() {
   return laptopRAM;
}

public void setLaptopRAM(String laptopRAM) {
   this.laptopRAM = laptopRAM;
}

public String getSerialnum() {
   return Serialnum;
}

public void setSerialnum(String serialnum) {
   Serialnum = serialnum;
}

public static void main(String rags[]){
  
   LaptopArrayDemo ld1 = new LaptopArrayDemo();
    Scanner sr = new Scanner(System.in);
    laptopMake= sr.nextLine();
    laptopRAM =sr.nextLine();
    Serialnum = sr.nextLine();
  
    ArrayList al = new ArrayList();
    al.add(ld1.setLaptopMake(laptopMake));
    al.add(ld1.setLaptopRAM(laptopRAM));
    al.add(ld1.setSerialnum(Serialnum));
  
    System.out.println("first instance values "+ld1);
  
  
    LaptopArrayDemo ld2 = new LaptopArrayDemo();
    Scanner sr2 = new Scanner(System.in);
    laptopMake= sr2.nextLine();
    laptopRAM =sr2.nextLine();
    Serialnum = sr2.nextLine();
    ArrayList al2 = new ArrayList();
    al2.add(ld2.setLaptopMake(laptopMake));
    al2.add(ld2.setLaptopRAM(laptopRAM));
    al2.add(ld2.setSerialnum(Serialnum));
  
    System.out.println("secodn instance values"+ld2);
  
    LaptopArrayDemo ld3 = new LaptopArrayDemo();
    Scanner sr3 = new Scanner(System.in);
    laptopMake= sr3.nextLine();
    laptopRAM =sr3.nextLine();
    Serialnum = sr3.nextLine();
    ArrayList al3 = new ArrayList();
    al3.add(ld3.setLaptopMake(laptopMake));
    al3.add(ld3.setLaptopRAM(laptopRAM));
    al3.add(ld3.setSerialnum(Serialnum));
    System.out.println("thord instance values "+ld3);
  
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote