java_aat3
java_aat3
COLLEGE OF ENGINEERING
(Autonomous college under VTU)
Bull Temple Rd, Basavanagudi, Bengaluru, Karnataka
560019 2023-2025
Department of Computer Applications
“Java
Programming”
By
FAADIL KHALEEL
class Shape {
protected int x;
protected int y;
@Override
public void showxyvalue() {
super.showxyvalue();
System.out.println("Length: " + length);
System.out.println("Breadth: " + breadth);
}
}
class TV {
protected String companyName;
protected int screenSize;
@Override
public void displayTVDetails() {
super.displayTVDetails();
System.out.println("TV Type: " + TVtype);
}
}
@Override
public void displayTVDetails() {
super.displayTVDetails();
System.out.println("TV Type: " + (TVtype ? "Color" : "Black and White"));
}
}
System.out.println("Color TV Details:");
colorTV.displayTVDetails();
System.out.println("\nBW TV Details:");
bwTV.displayTVDetails();
}
}
OutPut:
3)Imagine a publishing company that markets both book and audiocassette versions of its
works.Create a class publication that stores the title (a string) and price (type fl oat) of publication.
From this class, derive two classes: book, which adds a page count (type int), and tape, which adds
a playing time in minutes (type fl oat). Each of these three classes should have a getdata() function
to get its data from the user as the keyboard, and a putdata() function to display its data.
Write a main() program to test the book and tape classes by creating instance of them, asking
the user to fi ll in data with getdata(), and then displaying data with putdata().
import java.util.Scanner;
class Publication {
protected String title;
protected float price;
@Override
public void getData() {
super.getData();
@Override
public void putData() {
super.putData();
System.out.println("Page Count: " + pageCount);
}
}
@Override
public void getData() {
super.getData();
@Override
public void putData() {
super.putData();
System.out.println("Playing Time: " + playingTime + " minutes");
}
}