Question: Write a Java Program that following this blueprint ============ CODE =========== import java.text.NumberFormat; // from the power points recording for chapter 8 public class Book
Write a Java Program that following this blueprint ============ CODE ===========
import java.text.NumberFormat;
// from the power points recording for chapter 8 public class Book { private String title; private int numInStock; private double cost; private int stockNum; public Book() { }
public Book(String title, int numInStock, double cost, int stockNum) { this.stockNum=stockNum; this.title = title; this.numInStock = numInStock; this.cost = cost; } public String toString() { NumberFormat nf = NumberFormat.getCurrencyInstance(); return title + " with id number " + stockNum + " has " + numInStock + " books in stock costing " + nf.format(cost)+ " each."; } // other methods go here.... //*** we will often require a equals() method and a compareTo() method at minimum
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public int getNumInStock() { return numInStock; }
public void setNumInStock(int numInStock) { this.numInStock = numInStock; }
public double getCost() { return cost; }
public void setCost(double cost) { this.cost = cost; }
public int getStockNum() { return stockNum; }
public void setStockNum(int stockNum) { this.stockNum = stockNum; }
} ================================= TO-DO
Complete the code for the Book-Driver program by filling the comments BELOW: public class BookDriver {
public static void main(String[] args) { // create a book named "Java is Fun" with 200 in stock costing 55.00 each. The stock number is 1234 //print out the book using the toString() method //create a book calling the empty constructor. //set the title to "Databases R Us" //set the number in stock to 50 // set the cost each to $35.00 // set the stock number to 5555 //print out the book. //change the price to $55.00 //print out the book
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
