Question

Write a class encapsulating the concept of a telev
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Television.java:

public class Television {

   private String brand;
   private double price;
   public Television() {

   }
  
   public Television(String brand, double price) {
this.brand = brand;
       this.price = price;
   }

   public String getBrand() {
       return brand;
   }
   public double getPrice() {
       return price;
   }
   public void setBrand(String brand) {
       this.brand = brand;
   }
   public void setPrice(double price) {
       this.price = price;
   }

   public String toString() {
       return "Brand Name: "+getBrand()+" Price: "+getPrice();
   }
  
   public boolean equals(Television television2) {

          
       if(getBrand().equals(television2.getBrand()) &&
               getPrice()==television2.getPrice()) {
           return true;
       } else{
           return false;
       }
   }  
}

TelevisionTest.java:

import java.util.Scanner;

public class TelevisionTest {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);
       String brand;
       double price;
       System.out.println("Enter Television1 Name:");
       brand = sc.next();
       System.out.println("Enter Television1 Price:");
       price = sc.nextDouble();
       Television television1 = new Television(brand, price);
       System.out.println("Enter Television2 Name:");
       brand = sc.next();
      
       System.out.println("Enter Television2 Price:");
       price = sc.nextDouble();

      System.out.println("--------------------------");
       System.out.println("Television1 Details are:");
       System.out.println("getBrand(): "+television1.getBrand());
       System.out.println("getPrice(): "+television1.getPrice());

       System.out.println("toString() method result: "+television1);
       System.out.println("--------------------------");
       System.out.println("Television2 Details are:");
       System.out.println("getBrand(): "+television2.getBrand());
       System.out.println("getPrice(): "+television2.getPrice());

       System.out.println("toString() method result: "+television2);

       System.out.println("--------------------------");
       System.out.println("Checking equals method");
       if(television1.equals(television2)) {
           System.out.println("Both televisions are equals");
       } else {
           System.out.println("Both televisions are not equals");
       }

   }

}

OUTPUT:

Markers E Properties | Servers膼Data Source Explorer lb Snippets Console <terminated> TelevisionTest [Java Application] C:APro

Add a comment
Know the answer?
Add Answer to:
Write a class encapsulating the concept of a television set, assuming a television set has the...
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
  • write a class encapsulating the concept of a student assuming that the student has the following...

    write a class encapsulating the concept of a student assuming that the student has the following attributes the name of student the average of the student the rite a class encapsulating the concept of a Student, assuming that the Student has the following attributes: the name of the student, the average of the student, and the student's GPA. Include a default constructor, an overloaded constructor, the accessors and mutators, and methods, toString() and equals(). Also include a method returning the...

  • Write a class Store which includes the attributes: store name, city. Write another class encapsulating an...

    Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method returning the...

  • [CODE] Write a class encapsulating the concept of a house, assuming a house has the following...

    [CODE] Write a class encapsulating the concept of a house, assuming a house has the following attributes: value (in dollars), a city location, and number of bedrooms. Your class name should be “House” and your code should be in a file called “House.java”. You will need to create this file. In this class, include: Private instance variables for the previously-mentioned attributes A default constructor An overloaded constructor Accessor and mutator methods (i.e., get and set methods) The toString method The...

  • IN JAVA Write a class Store which includes the attributes: store name, city. Write another class...

    IN JAVA Write a class Store which includes the attributes: store name, city. Write another class encapsulating an Art Gallery, which inherits from Store. An Art Gallery has the following additional attributes: how many paintings are sold every year and the number of artists submitting artwork. Code the constructor, accessors, mutators, toString and equals method of the super class Store. Code the constructor, accessors and mutators for the subclass Art Gallery. In the Art Gallery class, also code a method...

  • In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following...

    In Java, Write a class encapsulating a restaurant,which inherits from Store. A restaurant has the following additional attributes: how many people are served every year and the average price per person. code the constructor, accessors, mutators, toString and equals method of the new subclass; also code a method returning the average taxes per year. You also need to include a client class to test your code for both the parent class and the subclass. Code for Store below(Super class aka...

  • 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...

  • Write a class encapsulating the concept of daily temperatures for a week with a single dimensiona...

    Write a class encapsulating the concept of daily temperatures for a week with a single dimensional array of temperatures. Write the following methods: • A constructor accepting an array of seven temperatures as a parameter. • Accessor, mutator, toString() and equals() methods • A method returning how many temperatures were below freezing. • A method returning an array of temperatures above 100 degrees. • A method returning the largest change in temperature between any two consecutive days. • A method...

  • Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number...

    Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number of quarters, number of dimes, number of nickels, and number of pennies. Include two constructors (non-argument constructor that assigns 1 to each coin, and another constructor that takes necessary arguments to create an object), needed getter and setter methods, method toString (to print coins objects in a meaningful way), and method equals (to compare two coins objects based on number of coins). Also include...

  • Write a class encapsulating a music store, which inherits from Store. A music store has the...

    Write a class encapsulating a music store, which inherits from Store. A music store has the following additional attributes: the number of titles it offers and its address. Code the constructor and the toString method of the new class. You also need to include a client class (with the main method) to test your code.

  • Write a class encapsulation the concept of coins (Coins java), assuming that coins have the following...

    Write a class encapsulation the concept of coins (Coins java), assuming that coins have the following attributes: a number of quarters, a number of dims, a number of nickels, and a number of pennies. Include a constructor (accept 4 numbers that represent the number of coins for each coin type), mutator and accessot methods, and method tostring. The tostring method should return a string in the following format: Total Value: $5.50 10 quarters, 20 dimes, 19 nickels, and 5 pennies...

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