How to create number limitations with JOptionPane.showInputDialog(null, ""); - java

So I'm making a game as you can see but i need to make it so that the player cannot use more than 28 stat points.
Can anyone help?
Here is my code.
package fallout.pkg4.game;
import javax.swing.JOptionPane;
public class Fallout4Game
{
public static void main(String[] args)
{
int pointsint2;
int pointsint;
String points;
String points2;
int resultint;
String perc;
int resultPerc;
int result3;
String end;
int endParsed;
int result4;
String chari;
int chariParsed;
int result5;
String inte;
int inteParsed;
int result6;
String agi;
int agiParsed;
int result7;
String luck;
int luckParsed;
Boolean error;
points = JOptionPane.showInputDialog(null, "Welcome to Brandons first game. Please enter 28 to start.");
JOptionPane.showMessageDialog(null,"You have " + points + " stats points. Choose wisley.....");
JOptionPane.showMessageDialog(null,"You will be choosing your S.P.E.C.I.A.L. attributes");
points2 = JOptionPane.showInputDialog(null, "STRENGTH You have " + points + " points.");
if(JOptionInput <= then )
pointsint = Integer.parseInt(points);
pointsint2 = Integer.parseInt(points2);
resultint = pointsint - pointsint2;
perc = JOptionPane.showInputDialog(null,"PERCEPTION You have " + resultint + " points left");
resultPerc = Integer.parseInt(perc);
result3 = resultint - resultPerc;
end = JOptionPane.showInputDialog(null,"ENDURENCE You have " + result3 + " points left.");
endParsed = Integer.parseInt(end);
result4 = result3 - endParsed;
chari = JOptionPane.showInputDialog(null,"CHARISMA You have " + result4 + " points left.");
chariParsed = Integer.parseInt(chari);
result5 = result4 - chariParsed;
inte = JOptionPane.showInputDialog(null,"INTELIGENCE You have " + result5 + " points left.");
inteParsed = Integer.parseInt(inte);
result6 = result5 - inteParsed;
agi = JOptionPane.showInputDialog(null,"AGILITY You have " + result6 + " points left");
agiParsed = Integer.parseInt(agi);
result7 = agiParsed - result6;
luck = JOptionPane.showInputDialog(null,"LUCK You have " + result7 + " points left");
luckParsed = Integer.parseInt(luck);
}
}

Related

Binomial in Java saving 2 variables in a variable after getting user input

I try to save both user input after the iteration, but I'm not sure how to do it. I always get
java:19: error: variable x might not have been initialized
long resalt = bio(x, y);
Source code:
import java.util.Scanner;
public class Aufgabe11 {
public static void main (String [] args) {
Scanner pit = new Scanner(System.in);
System.out.println("Enter fac number");
long a = pit.nextLong();
long result = recFac(a);
System.out.println("The factorial of" + " "+ a + " " + "is"+ " " + result);
Scanner pat = new Scanner(System.in);
long[] vars = new long [2];
for(int i = 0; i < vars.length; i++){
System.out.println("Enter bio var:");
vars [i] = pat.nextLong();
}
long x,y = pat.nextLong();
long resalt = bio(x, y);
System.out.println("The bio of" + " " + x + "over" + y + "is" + " " + resalt);
}
public static long recFac (long a) {
if (a <= 1) {
return 1;
}
else {
return a * recFac (a-1);
}
}
public static long bio (long x, long y) {
if ((x == y) || (y == 0))
return 1;
else
return bio (x-1, y) + bio (x-1, y-1);
}
}

JavaFX Loop through array and find a match, otherwise try again

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");
});

Running a Java file from Eclipse on Mac

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.

Netbeans - Trying to get jCombobox selected item into another JFrame TextArea

Hello wonderful people!
I've relatively new to this java and I'm practicing by creating an online booking system with multiple JFrames (I've heard this could be an issue).
In short, I want to retrieve the value of this jComboBox and display it in a text area on a separate frame. The problem is: How do I undergo this?
private void filmSelecterActionPerformed(java.awt.event.ActionEvent evt) {
if (filmSelecter.getSelectedIndex() == 0)
continueButton.setEnabled(false);
else {
continueButton.setEnabled(true);
}
Second JFrame
private void jQty2ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void reviewButtonActionPerformed(java.awt.event.ActionEvent evt) {
// -------Review Order Button----
double Qty1 = Double.parseDouble(jQty1.getText());
double Qty2 = Double.parseDouble(jQty2.getText());
double Qty3 = Double.parseDouble(jQty3.getText());
double Qty4 = Double.parseDouble(jQty4.getText());
double total, subTotal, ticket1, ticket2, ticket3, ticket4;
String adultPrice = String.format("%.2f", adultprice);
subTotal1.setText(adultPrice);
String studentPrice = String.format("%.2f", studentprice);
subTotal2.setText(studentPrice);
String childPrice = String.format("%.2f", childprice);
subTotal3.setText(childPrice);
String seniorPrice = String.format("%.2f", seniorprice);
subTotal4.setText(seniorPrice);
ticket1 = Qty1 * adultprice;
ticket2 = Qty2 * studentprice;
ticket3 = Qty3 * childprice;
ticket4 = Qty4 * seniorprice;
//subTotal
String sub1 = String.format("£%.2f", ticket1);
subTotal1.setText(sub1);
String sub2 = String.format("£%.2f", ticket2);
subTotal2.setText(sub2);
String sub3 = String.format("£%.2f", ticket3);
subTotal3.setText(sub3);
String sub4 = String.format("£%.2f", ticket4);
subTotal4.setText(sub4);
subTotal = ticket1 + ticket2 + ticket3 + ticket4;
// Total ticket price
String subTotalAll = String.format("£%.2f", subTotal);
jTotalPrice.setText(subTotalAll);
// Receipt
String Title = "\tGreenwich Peninsula Cinema\n\n\n";
String Movie = "Movie Name: " + "\n";
//String MovieDay = "Movie Day" + filmSelecter.getSelectedItem() + "\n";
String MovieTime = "Movie Time: \n";
String Barrier = "=========================================" + "\n";
String Adult = "Adult:" + subTotal1.getText() + "\nNumber of Tickets: " + Qty1 + "\n";
String Student = "Student:" + subTotal2.getText() + "\nNumber of Tickets: " + Qty2 + "\n";
String Child = "Child:" + subTotal3.getText() + "\nNumber of Tickets: " + Qty3 + "\n";
String Senior = "Senior:" + subTotal4.getText() + "\nNumber of Tickets: " + Qty4 + "\n";
String Thanks = "\n\n\tEnjoy the film!";
String ShowReceipt = Barrier + Title + Movie + /*MovieDay +*/ MovieTime + Barrier + Adult + Student + Child + Senior + Thanks + "\n" + Barrier;
filmReceipt.append(ShowReceipt);
}
I hope this helps in anyway.

Connect Login to the Main Class (Object Oriented)

Here's my Login class:
package mangInasal;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MILogin extends JFrame {
private JLabel lblUsername, lblPassword;
private JTextField txtUsername;
private JPasswordField txtPassword;
private JButton btnLogin, btnCancel;
public MILogin() {
super("Login");
setLayout(new FlowLayout());
lblUsername = new JLabel("Username: ");
add(lblUsername);
txtUsername = new JTextField(10);
add(txtUsername);
lblPassword = new JLabel("Password: ");
add(lblPassword);
txtPassword = new JPasswordField(10);
add(txtPassword);
btnLogin = new JButton("Login");
add(btnLogin);
btnCancel = new JButton("Cancel");
add(btnCancel);
ActionListener listener = new ButtonListener();
btnLogin.addActionListener(listener);
btnCancel.addActionListener(listener);
}
private class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JButton source = (JButton) e.getSource();
String username = txtUsername.getText().toUpperCase();
String pass = txtPassword.getText();
if (source == btnLogin) {
if (username.equals("TIPQC") && (pass.equals("ABET"))) {
String okay = "defimages/loginsuccess.gif";
java.net.URL imgURL = getClass().getClassLoader().getResource(okay);
ImageIcon okpic = new ImageIcon(imgURL);
JOptionPane.showMessageDialog(null, "WELCOME", "Correct Input", JOptionPane.PLAIN_MESSAGE, okpic);
dispose();
mangInasaldef manginasaldef = new mangInasaldef();
manginasaldef.run();
} else {
String okay = "defimages/loginfail.gif";
java.net.URL imgURL = getClass().getClassLoader().getResource(okay);
ImageIcon failpic = new ImageIcon(imgURL);
JOptionPane.showMessageDialog(null, "Incorrect Username or Password", "Message Dialog", JOptionPane.PLAIN_MESSAGE, failpic);
}
}
if (source == btnCancel) {
System.exit(1);
}
}
}
public void run() {
setSize(200, 200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setResizable(false);
}
public static void main(String[] args) {
MILogin milogin = new MILogin();
milogin.run();
}
}
And here's my Main class:
package mangInasal;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class mangInasaldef extends JFrame{ //class name
private static String username = "";
private static String customername = "";
private static String dineOut = "";
private String order = "";
private String order1 = "";
private String order2 = "";
private String order3 = "";
private String order4 = "";
private String order5 = "";
private String order6 = "";
private String order7 = "";
private String order8 = "";
private String order9 = "";
private String order10 = "";
private String order11 = "";
private String order12 = "";
private String order13 = "";
private String order14 = "";
private String order15 = "";
private String order16 = "";
private String order17 = "";
private int total = 0;
private int totalSpicy = 0;
private int total1 = 0;
private int total2= 0;
private int total3 = 0;
private int total4 = 0;
private int total5 = 0;
private int total6 = 0;
private int total7 = 0;
private int total8 = 0;
private int total9 = 0;
private int total10 = 0;
private int total11 = 0;
private int total12 = 0;
private int total13 = 0;
private int total14 = 0;
private int total15 = 0;
private int total16 = 0;
private int total17 = 0;
private int totalOrder = total + totalSpicy + total1 + total2 + total3 + total4 + total5 + total6 + total7 + total8 + total9 + total10 + total11 + total12 + total13 + total14 + total15;
private double vatCollected = totalOrder * 0.12;
private boolean exact = true; // a boolean variable that is declared private in order to be accessed by different methods
private double change, cashTendered;
private static int cashAmount;
private static Scanner inp = new Scanner(System.in); // private static declared Scanner which allows the user to input characters or strings by different methods
private JLabel lblUsername, lblPassword;
private JTextField txtUsername;
private JPasswordField txtPassword;
private JButton btnLogin, btnCancel;
public mangInasaldef() {
boolean repeatLoop = true;
System.out.print("\nInput Customer Name: ");
String customerName = inp.nextLine();
customername = customerName;
System.out.print("\nInput Cashier Name: ");
String user = inp.nextLine();
username = user;
do{
System.out.print("\nInput either Dine In or Take Out: ");
String dInDOut = inp.nextLine();
dineOut = dInDOut;
if (dineOut.equals("Dine In") || dineOut.equals("Take Out")){
System.out.print("");
repeatLoop = false;
}
else{
JOptionPane.showMessageDialog(null, "Try again! Please input Dine In or Take Out only!","Error", JOptionPane.ERROR_MESSAGE);
repeatLoop = true;
System.out.print ("\f");
}
}while(repeatLoop);
System.out.print("\n\n\t\tCashier: " +username);
System.out.print(" "+dineOut);
System.out.print("\n\t\tCustomer Name: " +customername);
EventQueue.invokeLater(new Runnable() {
#Override
public void run()
{
new mangInasaldef();
}
});
}
public mangInasaldef() {
JFrame frame = new JFrame("Mang Inasal Ordering System");
JPanel panel = new JPanel();
String choices[] = {"Paborito Meal 1 Paa","Paborito Meal 1.5 (Spicy Paa with Thigh part)","Paborito Meal 2 (Pecho)","Paborito Meal 3 (Pork Barbeque 4 pcs)","Paborito Meal 4 (Bangus Sisig)","Paborito Meal 5 (Pork Sisig)","Paborito Meal 6 (Bangus Inihaw)","Sulit Meal 1 (Paa)","Sulit Meal 2 (Pork Barbeque 2 pcs)","Pancit Bihon","Dinuguan at Puto","Ensaladang Talong","Softdrinks","Iced Tea","HaloHalo","Leche Flan","Turon Split","Print Receipt"};
JComboBox combo = new JComboBox(choices);
combo.setBackground(Color.black);
combo.setForeground(Color.yellow);
panel.add(combo);
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(350,100);
frame.setVisible(true);
combo.addItemListener(new ItemListener () {
#Override
public void itemStateChanged(ItemEvent e)
{
String item = (String)e.getItem();
if (e.getStateChange () == ItemEvent.SELECTED)
{
System.out.print("\nYou chose " +item);
if (item.equals("Paborito Meal 1 Paa"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of PM1");
Integer bilang= Integer.valueOf((String)val);
total = bilang * 99;
order = " " + bilang + " " + " PM1 PAA W/ RICE" +" "+ total + ".00V" + "\n"; //stores the values of the variables bilang and total in the variable order and prints them
}
if (item.equals("Paborito Meal 1.5 (Spicy Paa with Thigh part)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of PM1.5");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
totalSpicy = bilang * 99;
order1 = " " + bilang + " " + " PM1.5 PAA" +" "+ totalSpicy + ".00V" + "\n"; //stores the values of the variables bilang and total in the variable order and prints them
}
if (item.equals("Paborito Meal 2 (Pecho)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of PM2");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total1 = bilang * 99;
order2 = " " + bilang + " " + " PM2 PECHO W/ RICE" +" "+ total1 + ".00V" + "\n";
}
if (item.equals("Paborito Meal 3 (Pork Barbeque 4 pcs)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of PM3");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total2 = bilang * 99;
order3 = " " + bilang + " " + " PM3 PORK BBQ W/ RICE " +" "+ total2 + ".00V" + "\n";
}
if (item.equals("Paborito Meal 4 (Bangus Sisig)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of PM4");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total3 = bilang * 99;
order4 = " " + bilang + " " + " PM4 BANGUS SISIG " +" "+ total3 + ".00V" + "\n";
}
if (item.equals("Paborito Meal 5 (Pork Sisig)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of PM5");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total4 = bilang * 99;
order5 = " " + bilang + " " + " PM5 PORK SISIG " +" "+ total4 + ".00V" + "\n";
}
if (item.equals("Paborito Meal 6 (Bangus Inihaw)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of PM6");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total5 = bilang * 99;
order6 = " " + bilang + " " + " PM6 BANGUS INIHAW " +" "+ total5 + ".00V" + "\n";
}
if (item.equals("Sulit Meal 1 (Paa)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of SM1");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total6 = bilang * 59;
order7 = " " + bilang + " " + " SM1 PAA " +" "+ total6 + ".00V" + "\n";
}
if (item.equals("Sulit Meal 2 (Pork Barbeque 2 pcs)"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of SM2");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total7 = bilang * 59;
order8 = " " + bilang + " " + " SM2 PORK BBQ 2 " +" "+ total7 + ".00V" + "\n";
}
if (item.equals("Pancit Bihon"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of Pancit Bihon");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total8 = bilang * 49;
order9 = " " + bilang + " " + " Pancit Bihon " +" "+ total8 + ".00V" + "\n";
}
if (item.equals("Dinuguan at Puto"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of Dinuguan");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total9 = bilang * 49;
order10 = " " + bilang + " " + " Dinuguan at Puto " +" "+ total9 + ".00V" + "\n";
}
if (item.equals("Ensaladang Talong"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of Ensaladang Talong");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total10 = bilang * 29;
order12 = " " + bilang + " " + " Ensaladang Talong " +" "+ total10 + ".00V" + "\n";
}
if (item.equals("Softdrinks"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of Softdrinks");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total11 = bilang * 25;
order13 = " " + bilang + " " + " Softdrinks " +" "+ total11 + ".00V" + "\n";
}
if (item.equals("Iced Tea"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of Iced Tea");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total12 = bilang * 25;
order14 = " " + bilang + " " + " Iced Tea " +" "+ total12 + ".00V" + "\n";
}
if (item.equals("HaloHalo"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of HaloHalo");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total13 = bilang * 49;
order15 = " " + bilang + " " + " HaloHalo " +" "+ total13 + ".00V" + "\n";
}
if (item.equals("Leche Flan"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of Leche Flan");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total14 = bilang * 29;
order16 = " " + bilang + " " + " Leche Flan " +" "+ total14 + ".00V" + "\n";
}
if (item.equals("Turon Split"))
{
Object val = JOptionPane.showInputDialog("Please input quantity of Turon Split");
System.out.print(val);
Integer bilang= Integer.valueOf((String)val);
total15 = bilang * 39;
order17 = " " + bilang + " " + " Turon Split " +" "+ total15 + ".00V";
}
if (item.equals("Print Receipt")) // if Print Receipt was selected it will go to the method computeReceipt
{
System.out.print("\f"); // clears the screen
computeReceipt();
}
}
}
});
}
public void computeReceipt() {
totalOrder = total + totalSpicy + total1 + total2 + total3 + total4 + total5 + total6 + total7 + total8 + total9 + total10 + total11 + total12 + total13 + total14 + total15;
vatCollected = totalOrder * 0.12;
exact = true;
do{
System.out.print("\n\n\tYour total bill is: "+totalOrder);
exact = false;
Object cashMo = JOptionPane.showInputDialog("Please input here your cash");
System.out.println(cashMo);
cashAmount = Integer.valueOf((String)cashMo);
exact = false;
change = cashAmount - totalOrder;
if (cashAmount < totalOrder) {
JOptionPane.showMessageDialog(null, "Try again. Please enter sufficient money to proceed.","Invalid Input", JOptionPane.ERROR_MESSAGE);
exact = true;
}
}while(exact);
System.out.print("\f");
etoPoeReceipt();
}
public void etoPoeReceipt() {
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
Date date = new Date();
System.out.print("\n MANG INASAL");
System.out.print("\n BLUMENTRITT BRANCH");
System.out.print("\n #1631-1633 BLUMENTRITT ST.,");
System.out.print("\n STA CRUZ. MANILA 0000");
System.out.print("\n (932) 885-5844");
System.out.print("\n Operated by: R L YU");
System.out.print("\n TIN 202-161-017-000 VAT");
System.out.print("\n ACC. NO.: 050-204079836-000019");
System.out.print("\n Tel. #: (02)493-6801");
System.out.print("\n\n Cashier: " +username);
System.out.print(" STATION: 2");
System.out.print("\n ---------------------------------------------");
System.out.print("\n O.R #: 84486");
System.out.print(" "+dineOut);
System.out.print("\n Customer Name: " +customername);
System.out.print(" 24");
System.out.print("\n ---------------------------------------------");
System.out.print("\n >>SETTLED<<\n");
System.out.print(""+order );
System.out.print(""+order1 );
System.out.print(""+order2 );
System.out.print(""+order3 );
System.out.print(""+order4 );
System.out.print(""+order5 );
System.out.print(""+order6 );
System.out.print(""+order7 );
System.out.print(""+order8 );
System.out.print(""+order9 );
System.out.print(""+order10 );
System.out.print(""+order11 );
System.out.print(""+order12 );
System.out.print(""+order13 );
System.out.print(""+order14 );
System.out.print(""+order15 );
System.out.print(""+order16 );
System.out.print(""+order17 );
System.out.print("\n\n SUB TOTAL: "+totalOrder+ ".00");
System.out.print("\n DELIVERY VAT: 0.00");
System.out.print("\n ======");
System.out.print("\n AMOUNT DUE: "+totalOrder+ ".00\n\n");
System.out.printf(" VAT COLLECTED %.2f",vatCollected); // declares that the variable should be in two decimal places. % is called format specifier and f is the converter
System.out.println("");
System.out.print(" CASH Tendered: "+cashAmount+ ".00");
System.out.print("\n ======");
System.out.printf("\n CHANGE: %.2f",change);
System.out.print("\n >>Ticket #: 62<<");
System.out.print("\n Created: ");
System.out.print(dateFormat.format(date));
System.out.print("\n SETTLED: ");
System.out.print(dateFormat.format(date));
System.out.print("\n\n *********************************************");
System.out.print("\n THIS SERVES AS AN OFFICIAL RECEIPT.");
System.out.print("\n\n For Feedback: TEXT MIO467(Comments/ Suggest");
System.out.print("\n ions) and SEND to 0917-5941111 or CALL US");
System.out.print("\n at 0917-5596258");
System.out.print("\n Email: feedback#manginasal.com");
System.out.print("\n\n THANK YOU FOR DINING WITH US!");
System.out.print("\n\n *********************************************");
System.out.print("\n S/N: 120416ASL03/1105-6105-9230");
System.out.print("\n DT S/N: 41-L6971 (P0S1)");
System.out.print("\n PERMIT NO: 0412-031-125295-000");
System.out.print("\n MIN: 120276752");
}
}
After the login class was successfully accessed, it does not continue to the main method. I don't know what codes are needed to manipulate to connect the login class to the main class. Thanks for those who will help! :)
Remove the main method from you login class:
public static void main(String[] args) {
MILogin milogin = new MILogin();
milogin.run();
}
Then instance the MILogin class from your Main Class:
MILogin milogin = new MILogin();
milogin.run();

Categories