Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
//Main Class public class Main { public static void main(String[] args) { //object creation and invoking constructor of Class "Book" Book myBook = new Book("The Great Gatsby", "F. Scott Fitzgerald", 2425.00); System.out.println("--- Book Details ---"); myBook.displayDetails(); System.out.println("\n--- Discount Calculation ---"); myBook.applyDiscount(); } } class Book { private String title; private String author; private double price; //Constructor with parameters public Book(String title, String author, double price) { this.title = title; this.author = author; this.price = price; } //method that print author and price public void displayDetails() { System.out.println("Title: " + this.title); System.out.println("Author: " + this.author); System.out.println("Price: P" + String.format("%.2f", this.price)); } public void applyDiscount() { final double DISCOUNT_RATE = 0.10; double discountAmount = this.price * DISCOUNT_RATE; double discountedPrice = this.price - discountAmount; System.out.println("Original Price: P" + String.format("%.2f", this.price)); System.out.println("Discount Rate: " + (DISCOUNT_RATE * 100) + "%"); System.out.println("Discount Amount: P" + String.format("%.2f", discountAmount)); System.out.println("New Discounted Price: P" + String.format("%.2f", discountedPrice)); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)