Created
January 10, 2020 08:39
-
-
Save rishisidhu/a7ecda8b4797612395f4262ac1ea6372 to your computer and use it in GitHub Desktop.
Base class Book. How inheritance works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*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