Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

java_aat3

Uploaded by

faadilkhaleel360
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

java_aat3

Uploaded by

faadilkhaleel360
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

B.M.S.

COLLEGE OF ENGINEERING
(Autonomous college under VTU)
Bull Temple Rd, Basavanagudi, Bengaluru, Karnataka
560019 2023-2025
Department of Computer Applications

Report is submitted for fulfillment of AAT work in the subject

“Java
Programming”
By

FAADIL KHALEEL

Under the Guidance

Prof. R.V. Raghavendra Rao


(Associate Professor)
1.Create a base class called Shape, it contain two methods getxyvalue() and showxyvalue()
for accepting co-ordinates and to displaying the same. Create a subclass called Rectangle. It also
contains a method to display the length and breadth of the rectangle called showxyvalue(). Use
the overriding concept.

class Shape {
protected int x;
protected int y;

public void getxyvalue(int x, int y) {


this.x = x;
this.y = y;
}

public void showxyvalue() {


System.out.println("Coordinates: (" + x + ", " + y + ")");
}
}

class Rectangle extends Shape {


private int length;
private int breadth;

public Rectangle(int length, int breadth) {


this.length = length;
this.breadth = breadth;
}

@Override
public void showxyvalue() {
super.showxyvalue();
System.out.println("Length: " + length);
System.out.println("Breadth: " + breadth);
}
}

public class shape {


public static void main(String[] args) {
Rectangle rect = new Rectangle(10, 20);
rect.getxyvalue(5, 15);
rect.showxyvalue();
}
}
OutPut:
2.)Write a class called TV with the following attribute. Name of the company and Screen size using
super keyword and Inheritance to create a color TV class, it has a attribute TVtype also a BW TV
class it is also have TVtype attribute in Boolean data type.

class TV {
protected String companyName;
protected int screenSize;

public TV(String companyName, int screenSize) {


this.companyName = companyName;
this.screenSize = screenSize;
}

public void displayTVDetails() {


System.out.println("Company Name: " + companyName);
System.out.println("Screen Size: " + screenSize + " inches");
}
}

class ColorTV extends TV {


private String TVtype;

public ColorTV(String companyName, int screenSize, String TVtype) {


super(companyName, screenSize);
this.TVtype = TVtype;
}

@Override
public void displayTVDetails() {
super.displayTVDetails();
System.out.println("TV Type: " + TVtype);
}
}

class BWTV extends TV {


private boolean TVtype;

public BWTV(String companyName, int screenSize, boolean TVtype) {


super(companyName, screenSize);
this.TVtype = TVtype;
}

@Override
public void displayTVDetails() {
super.displayTVDetails();
System.out.println("TV Type: " + (TVtype ? "Color" : "Black and White"));
}
}

public class teevee {


public static void main(String[] args) {

ColorTV colorTV = new ColorTV("Samsung", 55, "LED");

BWTV bwTV = new BWTV("Sony", 21, false);

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;

public void getData() {


Scanner scanner = new Scanner(System.in);

System.out.print("Enter title: ");


title = scanner.nextLine();

System.out.print("Enter price: ");


price = scanner.nextFloat();
}

public void putData() {


System.out.println("Title: " + title);
System.out.println("Price: Rs" + price);
}
}

class Book extends Publication {


private int pageCount;

@Override
public void getData() {
super.getData();

Scanner scanner = new Scanner(System.in);

System.out.print("Enter page count: ");


pageCount = scanner.nextInt();
}

@Override
public void putData() {
super.putData();
System.out.println("Page Count: " + pageCount);
}
}

class Tape extends Publication {


private float playingTime;

@Override
public void getData() {
super.getData();

Scanner scanner = new Scanner(System.in);

System.out.print("Enter playing time in minutes: ");


playingTime = scanner.nextFloat();
}

@Override
public void putData() {
super.putData();
System.out.println("Playing Time: " + playingTime + " minutes");
}
}

public class bookmain {


public static void main(String[] args) {

Book book = new Book();


System.out.println("Enter details for the book:");
book.getData();
System.out.println("\nBook details:");
book.putData();

Tape tape = new Tape();


System.out.println("\nEnter details for the tape:");
tape.getData();
System.out.println("\nTape details:");
tape.putData();
}
}

You might also like