All pastes #44387 Raw Edit

Unnamed

public java v1 · immutable
#44387 ·published 2006-03-03 22:04 UTC
rendered paste body
import java.io.FileOutputStream;import java.io.PrintStream;import java.text.DecimalFormat;import java.util.Scanner;public class BookTest {	/**	 * @param args	 */	public static void main(String[] args) {		//Create our Book object, loop control, Input, and temporary value variables.		Book bInfo = new Book();		boolean enterBook = true;		Scanner keyboard = new Scanner(System.in);		int booksToBuy;		double taxRate;		DecimalFormat df1 = new DecimalFormat("##,###.00");				while (enterBook) {			System.out.println("Do you want to enter a book (y/n)?:");			if (keyboard.nextLine().matches("[^Nn]")) {				System.out.println("Enter the title of the book: ");				bInfo.setTitle(keyboard.nextLine());				System.out.println("Enter the price of the book:");				bInfo.setPrice(Double.parseDouble(keyboard.nextLine()));				System.out.println("Enter the quantity of the book:");				bInfo.setQuantity(Integer.parseInt(keyboard.nextLine()));				writeBook(bInfo);				System.out.println("How many books would you like to buy?:");				booksToBuy = Integer.parseInt(keyboard.nextLine());				System.out.println("Enter the tax rate (%):");				taxRate = Double.parseDouble(keyboard.nextLine());				System.out.println("The Total Cost is: "						+ bInfo.getTotalCost(booksToBuy, taxRate));				if (booksToBuy > bInfo.getQuantity()) {					int buyMore = 10 - (bInfo.getQuantity() - booksToBuy);					System.out.println(buyMore							+ "new copies of the book have been ordered.");					bInfo.setQuantity(10);				} else {					bInfo.setQuantity(bInfo.getQuantity() - booksToBuy);				}				System.out.println(bInfo.toString());			} else {				enterBook = false;			}		}		System.out.println("Goodbye!");	}	private static boolean writeBook(Book bookInfo) {		try {			FileOutputStream file = new FileOutputStream("books.txt", true);			PrintStream printer = new PrintStream(file);			printer.println(bookInfo.getTitle() + "#" + bookInfo.getPrice()					+ "#" + bookInfo.getQuantity());			printer.flush();			printer.close();			System.out.println(bookInfo.toString()					+ " has been saved to books.txt");			return true;		} catch (Exception e) {			System.out.println(e.getMessage() + "");			return false;		}	}}