Question

(Please use java to write these questions) Q1. Create a class on an object Computer with...

(Please use java to write these questions)

Q1. Create a class on an object Computer with two fields and two methods as follows: (5 points)

field: cpu and memory, method: compile( ) and execute( )

Q2. Write a source code to activate a class created in Q1. (5 points)

Homework Answers

Answer #1
// Q1
class Computer {
    private String cpu;
    private String memory;

    public Computer() {
    }

    public Computer(String cpu, String memory) {
        this.cpu = cpu;
        this.memory = memory;
    }

    public void compile() {
        System.out.println("Program is compiled...");
    }

    public void execute() {
        System.out.println("Program is executed...");
    }
}

// Q2
class ComputerTest {

    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.compile();
        computer.execute();
    }
}

Know the answer?
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
Similar Questions
Coding in Java Create an Airplane class (not abstract) that uses the Vehicle interface in Q1....
Coding in Java Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for all methods should print simple messages to the screen using System.out.println(). Add an integer speed variable that is changed using ChangeSpeed method. ChangeSpeed adds 5 to the speed each time it is called. Create a default constructor that sets the initial speed to 0. Don't create other constructors or any setter/getter methods. // code from Q1: interface Vehicle { void Start();...
write some lines of Java code that create a Screen object. Then call its clear method...
write some lines of Java code that create a Screen object. Then call its clear method if (and only if) its number of pixels is greater than two million. (Don’t worry about things being logical here; the goal is only to write something that is syntactically correct—i.e., that would compile if we typed it in.)
(JAVA) Create a class that represents a Customer. Use good OO programming technique. A Customer has...
(JAVA) Create a class that represents a Customer. Use good OO programming technique. A Customer has a firstName, lastName, customerNumber, emailAddress. You can add some more fields if you want to, but those 4 are a minimum. Override the equals method, and the toString method from the Object class. Implement the Comparable interface. In the main method, create some instances of the Customer class, and demonstrate the use of the accessor and mutator methods, as well as the compareTo method.
Q1: Use the setCharAt() method in StringBuilder class to edit a String "java". After editing it,...
Q1: Use the setCharAt() method in StringBuilder class to edit a String "java". After editing it, the String will be "Java". Q2: Write a Java program to define the ListNode in the LinkedList:
Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for...
Create an Airplane class (not abstract) that uses the Vehicle interface in Q1. The code for all methods should print simple messages to the screen using System.out.println(). Add an integer speed variable that is changed using the ChangeSpeed method. ChangeSpeed adds 5 to the speed each time it is called. Create a default constructor that sets the initial speed to 0. Don't create other constructors or any setter/getter methods. PLEASE CODE THIS IN JAVA
(Use JAVA) For this program, you need to create three classes, one of which is a...
(Use JAVA) For this program, you need to create three classes, one of which is a main class that includes aggregation from the other two classes. Each of the classes must include at least two fields, multiple constructors, accessor and mutator methods, and toString. Methods in your main class must include: 1. .equals 2. .copy 3. One that passes an object other than the .copy method 4. One that returns an object 5. toString that calls the toStrings from the...
C++ Design a class named Computer that holds the make, model, and amount of memory of...
C++ Design a class named Computer that holds the make, model, and amount of memory of a computer. Include methods to set the values for each data field, and include a method that displays all the values for each field. Create the class diagram and write the pseudocode that defines the class. Pseudocode help please
Write the program in java Implement a class Product. Create instance variables to store product name...
Write the program in java Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.
in JAVA Write a class Store which includes the attributes: store name and sales tax rate....
in JAVA Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Yarn Store, which inherits from Store. A Yarn Store has the following additional attributes: how many skeins of yarn are sold every year and the average price per skein. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Yarn Store; In the Yarn Store class, also code a method returning the...
1.Write a program that instantiates an object from the computer class and writes data into the...
1.Write a program that instantiates an object from the computer class and writes data into the object. you can set the data internally in the program. You do not need to ask for keyboard input. 2. Create a method that displays the data inside the computer object.