Skip to content

Instantly share code, notes, and snippets.

@rishisidhu
Created January 10, 2020 08:39
Show Gist options
  • Save rishisidhu/a7ecda8b4797612395f4262ac1ea6372 to your computer and use it in GitHub Desktop.
Save rishisidhu/a7ecda8b4797612395f4262ac1ea6372 to your computer and use it in GitHub Desktop.
Base class Book. How inheritance works
/**
*Base Class : Book
*Author : Rishi Sidhu
*Organization : AI Graduate
**/
public class Book
{
public String author;
public float costPrice;
public float salePrice;
public String title;
public int pages;
public Book(String au, float cp, float sp, String tl, int pg){
author = au;
costPrice = cp;
salePrice = sp;
title = tl;
pages = pg;
}
//Compute net profit per book
public float netProfit()
{
return (salePrice - costPrice);
}
//Compute tax on net profit per book @ 30%
public float getTax()
{
return (0.3f*this.netProfit());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment