Question

When answering this question, can you please specify what you name your files? Thank you! Write a...

When answering this question, can you please specify what you name your files? Thank you!

Write a Java application, and an additional class to represent some real-world entity.

Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods).

The class will:

a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to represent a lamp might include color, price, height, numBulbs, batteryOperated. Each of these 5 variables need a data type.

b. Include at least three different constructor methods, in addition to the default constructor (0 argument constructor). The constructor is a function (method) which allocates memory and initialized the member variables specified in (a.).

c. Include getters/setters for to serve as as mutators and accessors for each variable. Name these appropriately such as setColor & getColor, setPrice & getPrice, setHeight & getHeight, setNumBulbs and getNumBulbs, and setBatteryOperated & getBatteryOperated.

d. Create a member function showValues() to display the values of an object in a formatted manner.

e. Create at least 2 other member functions (methods) for the class that will perform some operation on the data (i.e. calculations or additional report/display of output). For example, turnLampOn, changeBulb, etc.

The Java application class (with a main method) will:

a. Instantiate at least three objects (using each of the constructors at least once) with your program. Note: Set the remaining data with the mutator methods.

b. Store the data from the individual objects into an ArrayList (or some other dynamic data structure of objects.

c. Utilize the showValues() method and each of the two methods on each of your objects to demonstrate their use. Required Output: Generate output samples demonstrating all of your member functions, adequately testing them and showing their functionality (i.e. inputting values, outputting values (displaying them), performing calculations, etc.).

Required Output: Generate output samples demonstrating all of your member functions, adequately testing them and showing their functionality (i.e. inputting values, outputting values (displaying them), performing calculations, etc.).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// PC.java

public class PC {
   // Declaring instance variables
   private String make;
   private String operatingSystem;
   private String Processor;
   private int RAM;
   private boolean isHDMISupport;

   public PC() {
       this.make = "Dell";
       this.operatingSystem = "Windows 10";
       Processor = "Intel";
       RAM = 4;
       this.isHDMISupport = false;
   }

   // Parameterized constructor
   public PC(String make, String operatingSystem, String processor) {
       this.make = make;
       this.operatingSystem = operatingSystem;
       Processor = processor;
       RAM = 2;
       this.isHDMISupport = true;
   }

   // Parameterized constructor
   public PC(String make, String operatingSystem, String processor, int rAM,
           boolean isHDMISupport) {
       this.make = make;
       this.operatingSystem = operatingSystem;
       Processor = processor;
       RAM = rAM;
       this.isHDMISupport = isHDMISupport;
   }

   public String getMake() {
       return make;
   }

   public void setMake(String make) {
       this.make = make;
   }

   public String getOperatingSystem() {
       return operatingSystem;
   }

   public void setOperatingSystem(String operatingSystem) {
       this.operatingSystem = operatingSystem;
   }

   public String getProcessor() {
       return Processor;
   }

   public void setProcessor(String processor) {
       Processor = processor;
   }

   public int getRAM() {
       return RAM;
   }

   public void setRAM(int rAM) {
       RAM = rAM;
   }

   public boolean isHDMISupport() {
       return isHDMISupport;
   }

   public void setHDMISupport(boolean isHDMISupport) {
       this.isHDMISupport = isHDMISupport;
   }

   public void makeHDMISupport() {
       this.isHDMISupport = true;
   }

   public void increaseRamBy1() {
       RAM++;
   }

   // toString method is used to display the contents of an object inside it
   @Override
   public String toString() {
       return "Make=" + make + " Operating System=" + operatingSystem
               + ", Processor=" + Processor + ", RAM=" + RAM
               + ", isHDMISupport=" + isHDMISupport;
   }

   public void showValues() {
       System.out.println("Make=" + make);
       System.out.println("Operating System=" + operatingSystem);
       System.out.println("Processor=" + Processor);
       System.out.println("RAM=" + RAM);
       System.out.println("isHDMISupport=" + isHDMISupport);
   }

}

____________________

// Test.java

import java.util.ArrayList;

public class Test {

   public static void main(String[] args) {
       ArrayList<PC> arl = new ArrayList<PC>();
       PC pc1 = new PC();
       PC pc2 = new PC("Lenovo", "Windows 7", "AMD", 2, true);
       PC pc3 = new PC("Hp", "Windows 7", "Windows 10");

       arl.add(pc1);
       arl.add(pc2);
       arl.add(pc3);
       for(int i=0;i<arl.size();i++)
       {
           System.out.println(arl.get(i));
       }
       pc1.increaseRamBy1();
       pc2.increaseRamBy1();
       pc3.increaseRamBy1();
      
       pc1.makeHDMISupport();
      
       System.out.println("\n\n______After Calling methods______");
       for(int i=0;i<arl.size();i++)
       {
           System.out.println(arl.get(i));
       }
   }

}

________________________

Output:

Make=Dell Operating System=Windows 10, Processor=Intel, RAM=4, isHDMISupport=false
Make=Lenovo Operating System=Windows 7, Processor=AMD, RAM=2, isHDMISupport=true
Make=Hp Operating System=Windows 7, Processor=Windows 10, RAM=2, isHDMISupport=true


______After Calling methods______
Make=Dell Operating System=Windows 10, Processor=Intel, RAM=5, isHDMISupport=true
Make=Lenovo Operating System=Windows 7, Processor=AMD, RAM=3, isHDMISupport=true
Make=Hp Operating System=Windows 7, Processor=Windows 10, RAM=3, isHDMISupport=true


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
When answering this question, can you please specify what you name your files? Thank you! Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please do this in C++. Thank you in advance. Note that you have to carefully create...

    Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...

  • Using C++, Write a class named Employee that has the following member variables: name. A string...

    Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Construct a class named Room that declares two double-precision data members named length and width (2...

    Construct a class named Room that declares two double-precision data members named length and width (2 points). Include a constructor that initializes each data member to 1.0 when a Room object is created (1 point). Add two accessor functions for displaying the length and width values of a Room object and two mutator functions that allow changing these data member values. (2 points) Write a program that tests all functionality of this class. (3 points) Extra Credit: Create this class...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Can you please help me with with problem. please follow all the specific insturctions, and try...

    Can you please help me with with problem. please follow all the specific insturctions, and try to make simple for a beginner in java. Write a class called Shape that contains instance data that represents the name and number of sides of the shape. Define a constructor to initialize these values. Include mutator(setter) methods – with the this reference – for the instance data, and a toString method that returns a the shape data. Create a static variable to keep...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points...

    Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points Design a class named Employee that has the following attributes: * Name ID Number- (Employee's] Identification Number " Department-the name of the department where the employee works " Position-the employee's job title The class should have the following constructors: A constructor that accepts values for all the member data as arguments A constructor that accepts the following values as arguments and assigns them to...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT