I am being tasked with adding 2 more classes to a prewritten program, one that does all calculations and one that prints the total bill. I understand how to add other classes but im a bit confused since the program already looks like it does the calculations inside of the main class.
Ive tried just adding in the classes but it throws errors because its missing information obviously.
public static void main(String[] args)
{
String squantity, snumber, output, line_output = "";
String [] item = new String [5];
double [] cost = new double [5];
double [] quantity = new double [5];
double [] amount = new double [5];
int number, i;
double grandtotal = 0;
String costout, amountout, grandtotalout;
DecimalFormat df2 = new DecimalFormat("$##,###.00");
for(i=0;i<=4;++i)
{
output = " Acme Grocery Store" + "\n" +
"1-Green Beans $0.35 per pound" + "\n" +
"2-Yellow Beans $0.40 per pound" + "\n" +
"3-Head Lettuce $0.79 per pound" + "\n" +
"4-Leaf Lettuce $1.98 per pound" + "\n" +
"5-Hot House Tomatoes $0.99 per pound" + "\n" +
"6-Hydro Tomatoes $3.98 per pound" + "\n" + "\n" +
"Please make your selection ";
snumber = JOptionPane.showInputDialog(null,
output, "Input Data", JOptionPane.QUESTION_MESSAGE);
number = Integer.parseInt(snumber);
squantity = JOptionPane.showInputDialog(null,
"Enter Quantity", "Input Data", JOptionPane.QUESTION_MESSAGE);
quantity[i] = Double.parseDouble(squantity);
//code for the calculation
if(number == 1)
{
cost[i] = 0.35;
item[i]="Green Beans";
}
else if(number == 2)
{
cost[i] = 0.4;
item[i]="Yellow Beans";
}
else if(number == 3)
{
cost[i] = 0.79;
item[i]="Head Lettuce";
}
else if(number ==4)
{
cost[i] = 1.98;
item[i]="Leaf Lettuce";
}
else if (number==5)
{
cost[i] = 0.99;
item[i]="Hot House Tomatoes";
}
else
{
cost[i] = 3.98;
item[i]="Hydro Tomatoes";
}
amount[i]=cost[i]*quantity[i];
costout=df2.format(cost[i]);
amountout=df2.format(amount[i]);
line_output=line_output+item[i]+" "+costout+" "+amountout+"\n";
grandtotal=grandtotal + amount[i];
}//for loop
grandtotalout=df2.format(grandtotal);
output=line_output+"\n"+ "The total grocery bill = "+grandtotalout;
JOptionPane.showMessageDialog(null, output, " ", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}//main
We are expected to add the classes
class grocery {
}
class printbill{
}
I tried messing with the extends function but I dont think that is correct either
As a starter, your grocery class would look something like this:
final class Grocery
{
Grocery(String InputItem, double InputCost, double InputQuantity)
{
Item = InputItem;
Cost = InputCost;
Quantity = InputQuantity;
}
public final String GetItem()
{
return Item;
}
public final double GetCost()
{
return (double)InputQuantity * Cost;
}
private final String Item;
private final double Cost;
private final int Quantity;
}
The PrintBill class may go like this:
final class PrintBill
{
PrintBill(Grocery [] InputGroceries)
{
Groceries = InputGroceries;
}
public final void Print()
{
double Cost, TotalCost = 0.0;
String Line = "";
String Item;
for (int i = 0; i < Groceries.length; i++)
{
Cost = Groceries[i].GetCost();
Item = Groceries[i].GetItem();
TotalCost += Cost;
// I'll leave it up to you to print this info out.
Line = Item + " " + Cost +" "+ TotalCost +"\n";
}
JOptionPane.showMessageDialog(null, output, " ",
JOptionPane.INFORMATION_MESSAGE);
}
private final Grocery [] Groceries;
}
Your main() would then be:
public static void main(String[] args)
{
String squantity, snumber, output, line_output = "";
Grocery [] Groceries = new Grocery [4];
PrintBill TheBill;
int number;
for (int i = 0; i < Groceries.length; i++)
{
output = " Acme Grocery Store" + "\n" +
"1-Green Beans $0.35 per pound" + "\n" +
"2-Yellow Beans $0.40 per pound" + "\n" +
"3-Head Lettuce $0.79 per pound" + "\n" +
"4-Leaf Lettuce $1.98 per pound" + "\n" +
"5-Hot House Tomatoes $0.99 per pound" + "\n" +
"6-Hydro Tomatoes $3.98 per pound" + "\n" + "\n" +
"Please make your selection ";
snumber = JOptionPane.showInputDialog(null,
output, "Input Data", JOptionPane.QUESTION_MESSAGE);
number = Integer.parseInt(snumber);
squantity = JOptionPane.showInputDialog(null,
"Enter Quantity", "Input Data", JOptionPane.QUESTION_MESSAGE);
quantity = Double.parseDouble(squantity);
if(number == 1)
{
Groceries[i] = new Grocery("Green Beans", 0.35, quantity);
}
else if(number == 2)
{
Groceries[i] = new Grocery("Yellow Beans", 0.4, quantity);
}
// etc...
}
TheBill = new PrintBill(Groceries);
TheBill.Print();
}
More work is required to actually complete this but it should give you a starting point anyway.
Happy Days :-)
Related
I'm writing a party planner program for a question for class.
I can't initialize my three choices of entertainment, decorations, and food.
Eclipse tells me that I should set all these values to 0. I have to stick to these if else statements because that's what we have learned so far.
Here is my code:
import java.util.Scanner;
public class PartyPlanner {
public static void main(String[] args) {
// TODO Auto-generated method stub
int entertainment;
int decorations;
int food;
int budget = entertainment + decorations + food;
Scanner keyboard = new Scanner(System.in);
System.out.println("For your choices, please type"
+ " in what is contained in the brackets."
+ " We will do the calculations for you.");
System.out.println("Choose entertainment:"
+ " [band] for $400 or " + "[DJ] for $150");
String choice1 = keyboard.nextLine();
if (choice1 == "DJ")
{
entertainment = 400;
}
else if (choice1 == "band")
{
entertainment = 150;
}
System.out.println("Where would you like to buy "
+ "decorations? [school] for $100 or [your own] for $250 ?");
String choice2 = keyboard.nextLine();
if (choice2 == "school")
{
decorations = 100;
}
else if (choice2 == "your own")
{
decorations = 250;
}
System.out.println("Would you like to purchase"
+ " [pizza] for $200 or [sub sandwiches]"
+ " for $250 or [appetizers] for $150?");
String choice3 = keyboard.nextLine();
if (choice3 == "pizza")
{
food = 200;
}
else if (choice3 == "sub sandwiches")
{
food = 250;
}
else if (choice3 == "appetizers")
{
food = 150;
}
System.out.println("You have chosen: " + choice1 +
" and " + choice2 + " and " + choice3);
System.out.println("The total cost of this party"
+ " comes out to:" + budget);
}
}
The problem is
The local variable entertainment, decorations, and food may have not been initalized.
First , you have to make the sum at the end of the code because at first the variables are not initialized yet , and secondly you can assign a value of zero if no choice have been made , like this :
public class PartyPlanner {
public static void main(String[] args) {
// TODO Auto-generated method stub
int entertainment;
int decorations;
int food;
Scanner keyboard = new Scanner(System.in);
System.out.println("For your choices, please type"
+ " in what is contained in the brackets."
+ " We will do the calculations for you.");
System.out.println("Choose entertainment:"
+ " [band] for $400 or " + "[DJ] for $150");
String choice1 = keyboard.nextLine();
if (choice1 == "DJ")
{
entertainment = 400;
}
else if (choice1 == "band")
{
entertainment = 150;
}
else { entertainment = 0; }
System.out.println("Where would you like to buy "
+ "decorations? [school] for $100 or [your own] for $250 ?");
String choice2 = keyboard.nextLine();
if (choice2 == "school")
{
decorations = 100;
}
else if (choice2 == "your own")
{
decorations = 250;
}
else { decorations = 0; }
System.out.println("Would you like to purchase"
+ " [pizza] for $200 or [sub sandwiches]"
+ " for $250 or [appetizers] for $150?");
String choice3 = keyboard.nextLine();
if (choice3 == "pizza")
{
food = 200;
}
else if (choice3 == "sub sandwiches")
{
food = 250;
}
else if (choice3 == "appetizers")
{
food = 150;
}
else { food = 0 ; }
int budget = entertainment + decorations + food;
System.out.println("You have chosen: " + choice1 +
" and " + choice2 + " and " + choice3);
System.out.println("The total cost of this party"
+ " comes out to:" + budget);
}
}
I have a GUI based e-store project. I read in a file and parse through it and saved it into an array.
The file format is like so: 11111, "title", 9.90
11111 is the book id, "title" is title, and 9.90 is the price.
I currently have 3 classes in my project. 1 class for Input/Output, 1 class for the Book store GUI code, and another for pop-up boxes when specific buttons are clicked.
In the GUI code, I check read the file into String[] fileArray and then loop through it until there is a match (with TextField input String bookIds = bookIdinput.getText())
I'm able to successfully get a match and go on with the rest of the code, but when there isn't a match, I get an error: Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at windowDisplay.lambda$start$3(windowDisplay.java:###)
which is this line of code for(int i=0; i<fileArray.length; i++)
If there isn't a match, then it should show a pop-up box saying that bookID isn't found.
Below is some of the GUI code
public class windowDisplay extends Application
{
// Variable declarations
private String[] fileArray = null;
private String holdStr = "";
private Stage mainWindow;
private boolean matchFound = false;
private int count = 1;
private int lineItems = 1;
private double totalAmount = 0.0;
private double subTotal = 0.0;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception
{
// OMITTED CODE
// These TextFields show the output depending on the input TextField's.
itemInfoOutput.setDisable(true);
orderSubtotalOutput.setDisable(true);
// Process item button.
processItem.setText("Process Item #" + count);
processItem.setMinWidth(106);
processItem.setOnAction(e ->
{
int numItems = Integer.parseInt(numItemInput.getText());
lineItems = numItems;
String bookIDs = bookIdInput.getText();
int qtyItems = Integer.parseInt(qtyItemInput.getText());
// Read file and check for Book ID
fileArray = bookStoreIO.readFile(bookIDs);
// Loop through array to find match or no matches
for(int i=0; i<fileArray.length; i++)
{
// If there is a match in book ID
if (fileArray[i].equals(bookIDs))
{
double price = Double.parseDouble(fileArray[i + 2]); // Price is in the i+2 position
double discount = calculateDiscount(qtyItems);
totalAmount = calculatePrice(qtyItems, price);
itemInfoOutput.setText(fileArray[i] + " " + fileArray[i + 1] + " " + "$" + price + " " +
qtyItems + " " + discount + "%" + " " + "$" + df.format(totalAmount));
// Disable processItem Button if there is a match and enable confirmItem Button
processItem.setDisable(true);
confirmItem.setDisable(false);
matchFound = true;
}
}
if(matchFound == false)
System.out.println("No match found!");
});
}
// OMITTED CODE
// This method calculates the discount depending on the quantity of items
public static double calculateDiscount(int inputQty){return null;}
// This methdod calculates the price with the discount
public static double calculatePrice(int inputQty, double price){return null;}
}
This class reads the file and returns an array with the contents of that file (once split by the ", " delimitter).
public class bookStoreIO
{
// This method reads the input file "inventory.txt" and saves it into an array.
public static String[] readFile(String stringIn)
{
try
{
String nextLine;
String[] fIn;
// Read file
BufferedReader br = new BufferedReader(new FileReader("inventory.txt"));
while((nextLine = br.readLine()) != null)
{
fIn = nextLine.split(", "); // Split when ", " is seen
if(stringIn.equalsIgnoreCase(fIn[0]))
{
br.close(); // Close file
return fIn; // Return array
}
}
}
// Just in case file isn't found
catch(IOException e)
{
System.out.println("File not found.");
}
return null;
}
I apologize if this seems messy, I'm still new to JavaFX and Java programming.
If you think more code is needed, please let me know!
EDIT: I improved some variable naming and removed the for loop. I'm still having trouble checking when there isn't a match.
public class windowDisplay extends Application
{
// Variable declarations
private String[] fileArray = null;
private Stage mainWindow;
private boolean matchFound = false;
private int count = 1;
private int lineItems = 1;
private double totalAmount = 0.0;
private double subTotal = 0.0;
private int itemQty = 0;
private int idBook = 0;
private String bookTitle = "";
private double bookPrice = 0.0;
private double discountAmount = 0.0;
private String resultOrder = "";
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception
{
// OMITTED CODE
// These TextFields show the output depending on the input TextField's.
itemInfoOutput.setDisable(true);
orderSubtotalOutput.setDisable(true);
// Process item button.
processItem.setText("Process Item #" + count);
processItem.setMinWidth(106);
processItem.setOnAction(e ->
{
int numItems = Integer.parseInt(numItemInput.getText());
lineItems = numItems;
String bookIDs = bookIdInput.getText();
itemQty = Integer.parseInt(qtyItemInput.getText());
// Read file and check for Book ID
fileArray = bookStoreIO.readFile(bookIDs);
idBook = Integer.parseInt(fileArray[0]);
bookTitle = fileArray[1];
bookPrice = Double.parseDouble(fileArray[2]);
discountAmount = calculateDiscount(itemQty);
totalAmount = calculatePrice(itemQty, bookPrice);
itemInfoOutput.setText(idBook + " " + bookTitle + " $" + bookPrice + " " + itemQty + " " + discountAmount
+ "% $" + df.format(totalAmount));
itemInfo.setText("Item #" + count + " info:");
processItem.setDisable(true);
confirmItem.setDisable(false);
matchFound = true;
if(matchFound == false)
System.out.println("not found");
});
// OMITTED CODE
// This method calculates the discount depending on the quantity of items
public static double calculateDiscount(int inputQty){return null;}
// This method calculates the price with the discount
public static double calculatePrice(int inputQty, double price){return null;}
}
I'm also having trouble saving
itemInfoOutput.setText(idBook + " " + bookTitle + " $" + bookPrice + " " + itemQty + " " + discountAmount
+ "% $" + df.format(totalAmount));
into an String or String array to print out a list of all the corresponding matches (along with their book ID, book Title, book Price, quantity, discount , and total price).
An example is shown below:
enter image description here
EDIT 2: The right box is the main GUI. The bottom left box is what shows up when a wrong book is entered (on the 2nd order). The top left is the length of the array.
// Process item button.
processItem.setText("Process Item #" + count);
processItem.setMinWidth(106);
processItem.setOnAction(e ->
{
int numItems = Integer.parseInt(numItemInput.getText());
lineItems = numItems;
String bookIDs = bookIdInput.getText();
itemQty = Integer.parseInt(qtyItemInput.getText());
// Read file and check for Book ID
fileArray = bookStoreIO.readFile(bookIDs);
for(int i=0; i<fileArray.length; i++)
System.out.println(fileArray[i]);
if(fileArray.length >= 3)
{
idBook = Integer.parseInt(fileArray[0]);
bookTitle = fileArray[1];
bookPrice = Double.parseDouble(fileArray[2]);
discountAmount = calculateDiscount(itemQty);
totalAmount = calculatePrice(itemQty, bookPrice);
resultOrder = itemInfoOutput.getText();
itemInfoOutput.setText(idBook + " " + bookTitle + " $" + bookPrice + " " + itemQty + " " + discountAmount
+ "% $" + df.format(totalAmount));
resultOrder = idBook + " " + bookTitle + " $" + bookPrice + " " + itemQty + " " + discountAmount
+ "% $" + df.format(totalAmount);
itemInfo.setText("Item #" + count + " info:");
processItem.setDisable(true);
confirmItem.setDisable(false);
}
else
alertBox.confirmDisplay("Book ID " + idBook + " not in file");
});
I'm writing a simple Java program for my history final project and am having trouble exporting it out of eclipse so it can be run on my teacher's computer (a Mac).
Here is the code:
package project;
import java.util.Scanner;
public class Denim {
public static void main(String []args) {
Scanner scan = new Scanner(System.in);
System.out.println("What item of denim is in question?");
String str = scan.nextLine();
String str1 = str.toUpperCase();
String jeans = "JEANS";
String jeansp = "JEAN PANTS";
String tux = "CANADIAN TUXEDO";
String tux1 = "CANADIEN TUXEDO";
String tux2 = "CANADIAN TUX";
String tux3 = "CANADIEN TUX";
String jacket = "JACKET";
String jjacket = "JEAN JACKET";
String hat = "HAT";
String dhat = "DENIM BASEBALL HAT";
String bhat = "BASEBALL HAT";
String c = "C";
int jeanFactor = 9982;
double jacketFactor = 10466.25178;
double bottleFactor = 128/16.9;
double hatFactor = 314.1415;
if (str1.equals(jeans) || str1.equals(jeansp)){
System.out.println("How many pairs of jeans?");
int numj = scan.nextInt();
int gallonj = numj*jeanFactor;
System.out.println("Producing " + numj + " pairs of jeans would use: ");
System.out.println(gallonj + " gallons of water");
double bottlesj = gallonj*bottleFactor;
System.out.println(bottlesj + " bottles of water");}
else if ((str1.equals(tux)) || (str1.equals(tux1)) || (str1.equals(tux2)) ||(str.equals(tux3))){
System.out.println("How many tuxedos?");
int numt = scan.nextInt();
int gallontp = numt * jeanFactor;
double gallontj = numt * jacketFactor;
double gallont = gallontp + gallontj;
double bottlest = gallont*bottleFactor;
System.out.println("Producing " + numt +" " + c + str.substring(1,8) + " tuexedos would use: ");
System.out.println(gallont +" gallons of water.");
System.out.println(bottlest + " bottles of water");}
else if (str1.equals(jacket) || str.equals(jjacket)){
System.out.println("How many jackets?");
int numjj = scan.nextInt();
double gallonjj = numjj*jacketFactor;
double bottlesjj = numjj*bottleFactor;
System.out.println("Producing " + numjj + " jackets would use: ");
System.out.println(gallonjj + " gallons of water");
System.out.println(bottlesjj + " bottles of water");}
else if (str1.equals(hat) || str.equals(dhat) || str.equals(bhat)){
System.out.println("How many hats?");
int numh = scan.nextInt();
double gallonh = numh*hatFactor;
double bottlesh = numh*bottleFactor;
System.out.println("Producing " + numh + " jackets would use: ");
System.out.println(gallonh + " gallons of water");
System.out.println(bottlesh + " bottles of water");
}
}
}
I click file-export and export it as a .jar file, but every time I try and open it to run it, a message pops up saying "The Java JAR file could not be launched. Does anyone know how to fix this or what I'm doing wrong? Both my computer and my teacher's are Macbooks.
In my code below, I am having an issue where I add the customer name to one room, but instead it adds the customer to every room. I can't figure out what in my code the issue is. I have tried removing the procedure but that still produced the same problem.
package test;
import java.util.*;
public class test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String choice, custName = "";
int roomNum = 1;
String[] hotel = new String[12];
String[] customer = new String[12];
hotelInitialise(hotel);
custInitialise(customer);
while ( roomNum < hotel.length-1 ) {
for (int i = 0; i < hotel.length-1; i++) {
System.out.println("This is the Hotel Menu. Please choose from the following options:\n");
System.out.println("A: " + "This will add a new entry\n");
System.out.println("V: " + "View all rooms\n");
choice = input.next().toUpperCase();
if (choice.equals("A")) {
System.out.println("Enter room number(1-10)");
roomNum =input.nextInt();
System.out.println("Enter name for room " + roomNum + " : " ) ;
custName = input.next();
addNewBooking(hotel, custName);
System.out.println(" ");
}
if (choice.equals("V")) {
seeAllRooms(hotel, custName);
}
}
}
}
// When the program loads it will assign all the values of the array as being empty
private static void hotelInitialise( String hotelRef[] ) {
for (int x = 0; x < 11; x++){
hotelRef[x] = "Room " + x + " is empty.";
}
System.out.println( "Welcome to the Summer Tropic Hotel.\n");
}
private static void custInitialise (String custRef[]) {
for (int i = 0; i < 11; i++) {
custRef[i] = ", no customer has occupied this room";
}
}
private static void addNewBooking(String hotel[], String customer) {
for (int x =1; x <11; x++) {
if (hotel[x].equals("Room " + hotel[x] + " is empty."))
System.out.println("Room " + x + " is empty.");
else {
System.out.println("Room " + x + " is occupied by "+ customer);
}
}
}
private static void seeAllRooms(String hotel[], String customer) {
for (int i = 0; i < hotel.length-1; i++) {
int j=0;
String custName = customer;
hotel[j]= custName;
if (hotel[i].equals("Room " + i + " is empty."))
System.out.println("Room " + i + " is empty.");
else {
System.out.println("Room " + i + " is occupied by "+ hotel[j] + ".");
}
}
}
}
In addNewBooking method you have this line:
if (hotel[x].equals("Room " + hotel[x] + " is empty."))
However hotel[x] has a value of "Room x is empty" e.g. hotel[1] is "Room 1 is empty" So the final check is becoming "hotel[x].equals(Room Room x is empty is empty.)" which is never equals to your hotel[x]
You have to change your code to
if (hotel[x].equals("Room " + x + " is empty."))
//do something there like add the booking
My Setup class:
import static java.lang.System.*;
import java.util.Scanner;
import java.io.*;
public class Setup
{
private String[] roomtype, custAddress, custName;
private int[] cPhone;
private double[] roomPrice;
private int[] roomNumber;
Scanner kb = new Scanner(in);
public Setup()
{
roomtype = new String[6];
custName = new String[6];
custAddress = new String[6];
roomPrice = new double[6];
cPhone = new int[6];
roomNumber = new int[6];
}
public void unoccupied()
{
String answer;
for (int c = 1; c<6; c++)
{
if(custName[c] == null)
{
out.println("Room" + roomtype[c] + " is not occupied.");
out.print("Would you like to assign a customer to this room?");
answer = kb.nextLine();
if (answer.contains("y"))
{
out.print("Which customer would you like to put in this room?");
answer = kb.nextLine();
roomtype[c] = answer;
}
}
}
}
public void addName(String[] custName)
{
for (int c = 1; c<6; c++)
{
if(custName[c] == null)
{
out.print("Add a name to customer " + c + ": ");
custName[c] = kb.nextLine();
}
}
}
public void addcPhone(int[] cPhone)
{
for (int p = 1; p<6; p++)
{
if(cPhone[p] == 0)
{
out.print("Add a cell phone number to customer " + p + ": ");
cPhone[p] = kb.nextInt();
}
}
}
public void addAddress(String[] custAddress)
{
for (int a = 1; a<6; a++)
if(custAddress[a] == null)
{
if(custName[a] == null)
{
out.print("Add an address to customer " + a + ": ");
custAddress[a] = kb.nextLine();
}
else
out.print("Add an address to " + custName + ": ");
custAddress[a] = kb.nextLine();
}
}
public String toString()
{
String receipt = "";
receipt += "Customer Name: " + custName ;
receipt += "Address: " + custAddress ;
receipt += "Phone number: " + cPhone ;
receipt += "Thanks for making your room reservation for Geek Speak with the Orozco Hotel!" ;
receipt += "We have you booked in room number " + roomNumber + ", which is a " + roomtype + "." ;
receipt += "Your charges for the convention will be $" + roomPrice + "." ;
receipt += "We hope you enjoy your stay with us and the convention.";
receipt += "The Orozco Hotel Staff";
return receipt;
}
}
And my driver class:
import java.util.Scanner;
import static java.lang.System.*;
public class Driver
{
public static void main(String[] args)
{
Scanner kb = new Scanner(in);
Setup[] customer = new Setup[5];
for(int i = 0; i<6; i++)
customer[i] = new Setup(custName, cPhone, custAddress);
Setup[] room = new Setup[5];
for(int i = 0; i<6; i++)
room[i] = new Setup(roomtype, roomPrice, roomNumber);
room[1].unoccupied();
}
}
Im trying to make 5 customer objects with custName, custAddress, and cPhone as parameters, and 5 room objects with roomPrice, roomtype, and roomNumber as parameters. I tried creating the objects with arrays, but I have no idea what I'm doing, as my teacher hasn't helped me at all this year. My driver class keeps returning the error "cannot find symbol" for the parameters in the customer and room objects. Any help to fix this code so that the objects hold the parameters is appreciated.
I think you need to reconsider your abstraction. These was a quick revamp to use a more OO approach. You can extend this idea by separating rooms from customer. You should have a hotel object be a collection of Rooms and customers.
import java.util.LinkedList;
public class Hotel{
LinkedList<Customer> customers;
public void addCustomer(Customer c){
customers.add(c);
}
public void removeCustomer(int roomNumber){
boolean flag = true;
for(int i = 0; i < customers.size() && flag; ++i){
if(customers.get(i).getRoomNumber() == roomNumber)
customers.remove(i);
flag = false;
}
}
public String toString(){
String s = "";
for(Customer c : customers)
s += c.toString() + "\n";
return s;
}
}
class Customer {
private String roomType;
private String address;
private String name;
private String phone;
private String price;
private int roomNumber;
public Customer(String rmTp, String addrss, String nm, String phn, String prc, int rmNm){
roomType = rmTp;
address = addrss;
name = nm;
phone = phn;
price = prc;
roomNumber = rmNm;
}
public int getRoomNumber(){ return roomNumber; }
public String toString(){
String receipt = "";
receipt += "Customer Name: " + name ;
receipt += "Address: " + address ;
receipt += "Phone number: " + phone ;
receipt += "Thanks for making your room reservation for Geek Speak with the Orozco Hotel!" ;
receipt += "We have you booked in room number " + roomNumber + ", which is a " + roomType + "." ;
receipt += "Your charges for the convention will be $" + price + "." ;
receipt += "We hope you enjoy your stay with us and the convention.";
receipt += "The Orozco Hotel Staff";
return receipt;
}
}