Created
February 23, 2016 07:28
-
-
Save rhexgomez/165dafa3360081e5c32b to your computer and use it in GitHub Desktop.
Wedding Planner Basic App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2016 Elmar Rhex Gomez. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.example; | |
public class InvitationInformation { | |
private int id; | |
private String familyName; | |
private int size; | |
private boolean responded; | |
private int numberOfChickens; | |
private int numberOfVegies; | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getFamilyName() { | |
return familyName; | |
} | |
public void setFamilyName(String familyName) { | |
this.familyName = familyName; | |
} | |
public int getSize() { | |
return size; | |
} | |
public void setSize(int size) { | |
this.size = size; | |
} | |
public boolean isResponded() { | |
return responded; | |
} | |
public void setResponded(boolean responded) { | |
this.responded = responded; | |
} | |
public int getNumberOfChickens() { | |
return numberOfChickens; | |
} | |
public void setNumberOfChickens(int numberOfChickens) { | |
this.numberOfChickens = numberOfChickens; | |
} | |
public int getNumberOfVegies() { | |
return numberOfVegies; | |
} | |
public void setNumberOfVegies(int numberOfVegies) { | |
this.numberOfVegies = numberOfVegies; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2016 Elmar Rhex Gomez. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.example; | |
import javax.swing.JOptionPane; | |
public class Main { | |
public static final String FAMILY_HOST_MESSAGE = "Who host the event?"; | |
public static final String FAMILY_NAME_MESSAGE = "Enter the family name!\n(e.g. Smith,Jones,etc.)"; | |
public static final String FAMILY_SIZE_MESSAGE = "Enter the family size.\nNote: Number only and no letters!!"; | |
public static final String FAMILY_SIZE_ERROR_MESSAGE = "Venue capacity exceeded!"; | |
public static final String ENTER_MENU = "MENU: Select the number that corresponds to your choice" + | |
"\n1 Rescind Invitation" + | |
"\n2 Record Response" + | |
"\n3 Rescind Invitation" + | |
"\n0 Exit"; | |
public static void main(String[] args) { | |
String hostFamily = JOptionPane.showInputDialog(null, FAMILY_HOST_MESSAGE); | |
Wedding wedding = new Wedding(hostFamily); | |
while (true) { | |
String familyName = JOptionPane.showInputDialog(null, FAMILY_NAME_MESSAGE); | |
int familySize = Integer.parseInt(JOptionPane.showInputDialog(null, FAMILY_SIZE_MESSAGE)); | |
if (!wedding.invite(familyName, familySize)) { | |
JOptionPane.showMessageDialog(null, FAMILY_SIZE_ERROR_MESSAGE); | |
break; | |
} | |
} | |
while (true) { | |
String input = JOptionPane.showInputDialog(null, ENTER_MENU); | |
int selected = Integer.parseInt(input != null ? input : "0"); | |
if (selected == 1) { | |
String inp = JOptionPane.showInputDialog(null, "Remove guess using ID:\n" | |
+ wedding.showAllUnresponsiveGuess()); | |
boolean result = wedding.rescindInvitation(inp); | |
if (!result) { | |
JOptionPane.showMessageDialog(null, "An Error occur while removing!"); | |
} | |
} else if (selected == 2) { | |
String inp = JOptionPane.showInputDialog(null, "Indicate meals to guess using ID:\n" | |
+ wedding.showAllUnresponsiveGuessWithFamilyMember()); | |
boolean isValid = wedding.invitationExists(inp); | |
if (!isValid) { | |
JOptionPane.showMessageDialog(null, "Invalid ID!"); | |
} else { | |
int veg = Integer.parseInt(JOptionPane.showInputDialog(null, "Vegies count")); | |
int chick = Integer.parseInt(JOptionPane.showInputDialog(null, "Chicken count")); | |
if (wedding.foodIsEnough(Integer.parseInt(inp), veg, chick)) { | |
wedding.addResponse(Integer.parseInt(inp), veg, chick); | |
} else { | |
JOptionPane.showMessageDialog(null, "Food count did not match!"); | |
} | |
} | |
} else if (selected == 0) { | |
break; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2016 Elmar Rhex Gomez. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.example; | |
import java.util.ArrayList; | |
public class Wedding { | |
private static final int VENUE_MAX_CAPACITY = 250; | |
private static final ArrayList<InvitationInformation> INVITATION = new ArrayList<>(); | |
private int idGenerator; | |
private String host; | |
private int capacity; | |
public Wedding(String host) { | |
this(VENUE_MAX_CAPACITY, host); | |
} | |
public Wedding(int capacity, String host) { | |
this.host = host; | |
this.capacity = capacity; | |
} | |
/** | |
* This is a method for inviting people. | |
* | |
* @param familyName the family name | |
* @param familySize the family size | |
* @return true if the family is successfully invited, | |
* otherwise false means capacity exceeded | |
*/ | |
public boolean invite(String familyName, int familySize) { | |
if ((capacity - familySize) >= 0) { | |
capacity -= familySize; | |
InvitationInformation in = new InvitationInformation(); | |
in.setFamilyName(familyName); | |
in.setSize(familySize); | |
in.setId(idGenerator++); | |
INVITATION.add(in); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
/** | |
* This method will list all the unresponsive guess. | |
* | |
* @return the list string | |
*/ | |
public String showAllUnresponsiveGuess() { | |
StringBuilder builder = new StringBuilder(); | |
for (InvitationInformation invi : INVITATION) { | |
if (!invi.isResponded()) { | |
builder.append(invi.getId()); | |
builder.append(" "); | |
builder.append(invi.getFamilyName()); | |
builder.append("\n"); | |
} | |
} | |
return builder.toString(); | |
} | |
/** | |
* This method will list all the unresponsive guess. | |
* | |
* @return the list string | |
*/ | |
public String showAllUnresponsiveGuessWithFamilyMember() { | |
StringBuilder builder = new StringBuilder(); | |
for (InvitationInformation invi : INVITATION) { | |
if (!invi.isResponded()) { | |
builder.append(invi.getId()); | |
builder.append(" "); | |
builder.append(invi.getFamilyName()); | |
builder.append(" size:"); | |
builder.append(invi.getSize()); | |
builder.append("\n"); | |
} | |
} | |
return builder.toString(); | |
} | |
/** | |
* Remove guess | |
* | |
* @param id | |
* @return true if successfully remove, false if not | |
*/ | |
public boolean rescindInvitation(String id) { | |
if (id != null) { | |
return rescindInvitation(Integer.parseInt(id)); | |
} | |
return false; | |
} | |
// Overloading | |
public boolean rescindInvitation(int id) { | |
for (InvitationInformation in : INVITATION) { | |
if (in.getId() == id && !in.isResponded()) { | |
INVITATION.remove(in); | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* Check if the user exists | |
* | |
* @param id | |
* @return | |
*/ | |
public boolean invitationExists(String id) { | |
if (id != null) { | |
try { | |
int i = Integer.parseInt(id); | |
for (InvitationInformation inv : INVITATION) { | |
if (inv.getId() == i && !inv.isResponded()) { | |
return true; | |
} | |
} | |
} catch (Exception e) { | |
return false; | |
} | |
} | |
return false; | |
} | |
public boolean foodIsEnough(int id, int v, int c) { | |
for (InvitationInformation inv : INVITATION) { | |
if (inv.getId() == id && (v + c) == inv.getSize()) { | |
return true; | |
} | |
} | |
return false; | |
} | |
public void addResponse(int id, int v, int c) { | |
for (InvitationInformation inv : INVITATION) { | |
if (inv.getId() == id) { | |
inv.setNumberOfVegies(v); | |
inv.setNumberOfChickens(c); | |
inv.setResponded(true); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment