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;
}
}
Related
I am making an java program for college and I am stuck at one point, the exam says I need to extract information from an txt file that is already written. I need to get only the information from the end of the lines like password or something.
DISCLAIMER:
I know how to do it by using scanner and file. But it is not really clear how to extract only the information not the whole line.
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
public class Trip {
private String password;
private String placeOfDeparture;
private String destination;
private int durationInDays;
private double wage;
private double rentPrice;
private String firstName;
private String lastName;
private String[] passwords;
public Trip(String placeOfDeparture, String destination, int durationInDays, double wage,
double rentPrice, String firstName, String lastName) {
super();
this.placeOfDeparture = placeOfDeparture;
this.destination = destination;
this.durationInDays = durationInDays;
this.wage = wage;
this.rentPrice = rentPrice;
this.firstName = firstName;
this.lastName = lastName;
generateTripPassword();
}
public void generateTripPassword() {
Random rand = new Random();
int randomNumbers = rand.nextInt(100);
String personInitials = "";
String departureInitials = "";
String destinationInitials = "";
personInitials += firstName.substring(0, 1).toUpperCase();
personInitials += lastName.substring(0, 1).toUpperCase();
departureInitials += placeOfDeparture.substring(0, 2).toUpperCase();
destinationInitials += destination.substring(0, 2).toUpperCase();
for(int i = 0; i < passwords.length; i++) {
if(passwords[i] == null) {
passwords[i] = personInitials + departureInitials + destinationInitials + randomNumbers;
break;
}
}
this.password = personInitials + departureInitials + destinationInitials + randomNumbers;
}
public void getTripInformation() {
System.out.println("Trip details: \n");
System.out.println("Trip password: " + password);
System.out.println("Passenger name: " + firstName + " " + lastName + ".");
System.out.println("Duration in days: " + durationInDays + ".");
System.out.println("Wage: " + wage + ".");
System.out.println("Rent price is: " + rentPrice + ".");
}
public void writeTripInfo(String tripType) {
File file = new File(this.password + ".txt");
try {
FileWriter trip = new FileWriter(file);
trip.write("Trip details: ");
trip.write("Trip password: " + password);
trip.write("Passenger name: " + firstName + " " + lastName + ".");
trip.write("Duration in days: " + durationInDays + ".");
trip.write("Wage: " + wage + ".");
trip.write("Rent price is: " + rentPrice + ".");
trip.write("Type of the trip is: " + tripType);
trip.close();
System.out.println("File writing successfully completed! Name of yje file is: " + this.password + " . Enjoy.");
} catch (IOException e) {
System.out.println("An error occured while writing file.");
System.out.println("Here is the error debug code: ");
e.printStackTrace();
}
}
}
After you have put each part on its own line (and removed the '.' at the end), you can parse each line by splitting on ':'
public void readTripInfo(String path)
{
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
String line;
// Read each line of file
while ((line = br.readLine()) != null) {
// Split on ':'
String [] parts = line.split(":");
if (parts.length == 2) {
// Save
if (parts[0].equals("Trip password")) {
password = parts[1].trim();
}
else if (parts[0].equals("Passenger name")) {
String [] names = parts[1].trim().split(" ");
if (names.length == 2) {
firstName = names[0];
lastName = names[1];
}
}
else if (parts[0].equals("Duration in days")) {
durationInDays = Integer.parseInt(parts[1].trim());
}
// Continue for the rest
}
}
}
catch (Exception e) {
System.out.println(e);
}
}
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 :-)
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");
});
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
I'm currently struggling to make my procedures to work. I'm having to do this all as objects This is what I have in my main file currently:
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Room[] myHotel = new Room[6];
//myHotel[x] = new Room();
myHotel[0] = new Room();
myHotel[1] = new Room();
myHotel[2] = new Room();
myHotel[3] = new Room();
myHotel[4] = new Room();
String roomName = null;
String choice;
int roomNum = 0;
initialise(myHotel);
while ( roomNum < 5 )
{
System.out.println("Hotel Booking Options");
System.out.println("V: To View all rooms");
System.out.println("A: To Add a customer to a room");
choice = input.next();
if (choice.equals("V")) //views all the rooms
{
view(myHotel, roomName);
}
if (choice.equals("A")) //To add a customer to a room
{
System.out.println("Enter room number (0-5) or 6 to stop:" );
roomNum = input.nextInt();
System.out.println("Enter name for room " + roomNum + " : " ) ;
roomName = input.next();
myHotel[roomNum].mainName = roomName ;
//myHotel[roomNum].setName(roomName);
add(myHotel, roomName);
System.out.println(" ");
}
}
}
private static void initialise( Room hotelRef[] ) {
for (int x = 0; x < 5; x++ ) hotelRef[x].mainName = "empty";
System.out.println( "initilise ");
}
public static void view(Room myHotel[], Room roomName){
for (int x = 0; x <5; x++)
{
int z = 0;
Room Roomname = roomName;
myHotel[z]= Roomname;
if (myHotel[x].mainName.equals("empty"))
System.out.println("room " + x + " is empty");
else {
System.out.println("room " + x + " occupied by " + myHotel[x].mainName);
//System.out.println("room " + x + " is occupied by "+ myHotel[x]);
}
}
}
private static void add(Room myHotel[], String roomName){
for (int x = 0; x <5; x++)
{
int z = 0;
String Roomname = roomName;
myHotel[z]= Roomname;
if (myHotel[x].mainName.equals("empty"))
{
System.out.println("room " + x + " is empty");
}
else {
System.out.println("room " + x + " is occupied by "+ myHotel[x]);
}
}
}
}
In my other .java file with the object variables:
public class Room {
String mainName;
//private String mainName;
int guestsInRoom;
public Room() {
mainName = "k";
System.out.println("made a room ");
}
public void setName(String aName) {
System.out.println("add name class method ");
mainName = aName;
}
public String getName() {
return mainName;
}
}
I'm not sure how to fix line 54 - view(myHotel, roomName); Sorry if my variable names are confusing and misleading...