package EmployeePayAppMRM;
import javax.swing.JOptionPane;
public class java
{
public static void main(String[] args)
{
String firstName;
String lastName;
String fullName;
String itemsSold;
String valueItems;
double basePay;
double totalPay;
double valueSold;
int numberSold;
final double ITEM_MIN = 10;
final int VALUE_MIN = 2500;
final int BONUS = 500;
firstName = JOptionPane.showInputDialog(" Enter employee's first name:");
lastName = JOptionPane.showInputDialog(" Enter employee's last name:");
fullName = JOptionPane.showInputDialog(" Enter base pay for " + firstName + " " + lastName + ":");
basePay = Double.parseDouble(fullName);
itemsSold = JOptionPane.showInputDialog(" Enter number of items sold for " + firstName + " " + lastName + ":");
totalPay = Double.parseDouble(fullName);
fullName = JOptionPane.showInputDialog(" Enter value of items sold for " + firstName + " " + lastName + ":");
valueSold = Double.parseDouble(fullName);
basePay = 1000;
if ( itemsSold > ITEM_MIN) //ERROR HERE (bad operand)
totalPay = (basePay + BONUS);
else if (valueSold >= VALUE_MIN)
totalPay = (basePay + BONUS);
else
totalPay = basePay;
System.out.println("this" + firstName + " " + lastName + " " + "will be paid" + totalPay "for selling" + itemsSold "items valued at $" + valueSold); //ERROR HERE
System.exit(0);
}
}
The first problem is about types, for the second you just miss some +
itemsSold is a String
ITEM_MIN is a double
Do like this, of parse it before
if(Double.parseDouble(itemsSold) > ITEM_MIN)
totalPay = (basePay + BONUS);
Finally, you don't need to define the variable and do the assignement later, just do it at the same time, once reoganisating all :
final double ITEM_MIN = 10;
final int VALUE_MIN = 2500;
final int BONUS = 500;
String firstName = JOptionPane.showInputDialog(" Enter employee's first name:");
String lastName = JOptionPane.showInputDialog(" Enter employee's last name:");
String fullName = JOptionPane.showInputDialog(" Enter base pay for " + firstName + " " + lastName + ":");
double itemsSold = Double.parseDouble(JOptionPane.showInputDialog(" Enter number of items sold for " + firstName + " " + lastName + ":"));
double valueSold = Double.parseDouble(JOptionPane.showInputDialog(" Enter value of items sold for " + firstName + " " + lastName + ":"));
double totalPay = 0;
double basePay = 1000;
if (itemsSold > ITEM_MIN) {
totalPay = (basePay + BONUS);
} else if (valueSold >= VALUE_MIN) {
totalPay = (basePay + BONUS);
} else {
totalPay = basePay;
}
System.out.println("this" + firstName + " " + lastName + " " + "will be paid" + totalPay + "for selling" + itemsSold + "items valued at $" + valueSold);
Related
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.
So I can't get the variables to be divisible, I need to be able to do this, otherwise I don't know of a way to finish building the lock that I want to build.
It uses 20 inputted numbers, and then arranges them into a Algebra2/calculus system of equations, and then solves for the "s", "a", "f", and "e" it starts by removing "e" from the equation by substituting.
I would greatly appreciate help, I'm open to ideas as well, because sofar I have 25 of these to build, and this is only 1/3 of the first one.
In short, how do I divide variables?
import java.util.Scanner;
public class Lock
{
public static void main(String[] args) {
Scanner user_input = new Scanner (System.in);
String num_a;
System.out.print("Enter the first number: ");
num_a = user_input.next();
String num_b;
System.out.print("Enter the second number: ");
num_b = user_input.next();
String num_c;
System.out.print("Enter the third number: ");
num_c = user_input.next();
String num_d;
System.out.print("Enter the fourth number: ");
num_d = user_input.next();
String num_e;
System.out.print("Enter the fifth number: ");
num_e = user_input.next();
String num_f;
System.out.print("Enter the sixth number: ");
num_f = user_input.next();
String num_g;
System.out.print("Enter the seventh number: ");
num_g = user_input.next();
String num_h;
System.out.print("Enter the eigth number: ");
num_h = user_input.next();
String num_i;
System.out.print("Enter the ninth number: ");
num_i = user_input.next();
String num_j;
System.out.print("Enter the tenth number: ");
num_j = user_input.next();
String num_k;
System.out.print("Enter the eleventh number: ");
num_k = user_input.next();
String num_l;
System.out.print("Enter the twetlth number: ");
num_l = user_input.next();
String num_m;
System.out.print("Enter the thirteenth number: ");
num_m = user_input.next();
String num_n;
System.out.print("Enter the fourteenth number: ");
num_n = user_input.next();
String num_o;
System.out.print("Enter the fifteenth number: ");
num_o = user_input.next();
String num_p;
System.out.print("Enter the sixteenth number: ");
num_p = user_input.next();
String num_q;
System.out.print("Enter the seventeenth number: ");
num_q = user_input.next();
String num_r;
System.out.print("Enter the eighteenth number: ");
num_r = user_input.next();
String num_s;
System.out.print("Enter the nineteenth number: ");
num_s = user_input.next();
String num_t;
System.out.print("Enter the twentieth number: ");
num_t = user_input.next();
System.out.println(num_a + "s + " + num_b + "a + " + num_c + "f + " + num_d + "e = " + num_e);
System.out.println(num_f + "s + " + num_g + "a + " + num_h + "f + " + num_i + "e = " + num_j);
System.out.println(num_k + "s + " + num_l + "a + " + num_m + "f + " + num_n + "e = " + num_o);
System.out.println(num_p + "s + " + num_q + "a + " + num_r + "f + " + num_s + "e = " + num_t);
System.out.println(num_a + "s + " + num_b + "a + " + num_c + "f + " + num_d + "[(" + num_t + " " + num_p + "s + " + num_q + "a " + num_r + "f) / " + num_s + "] =" + num_e);
System.out.println(num_f + "s + " + num_g + "a + " + num_h + "f + " + num_i + "[(" + num_t + " " + num_p + "s + " + num_q + "a " + num_r + "f) / " + num_s + "] =" + num_j);
System.out.println(num_k + "s + " + num_l + "a + " + num_m + "f + " + num_n + "[(" + num_t + " " + num_p + "s + " + num_q + "a " + num_r + "f) / " + num_s + "] =" + num_o);
// THIS creates the fourth equation items/order to be substituted into the other first three equations.
int t = num_t;
int s = num_s;
int num_ts = (t / s);
num_ts =
num_ps = (num_p / num_s);
num_qs = (num_q / num_s);
num_rs = (num_r / num_s);
// THIS is the Fourth equation being substituted into the First Equation
num_dts = (num_d * num_ts);
num_dps = (num_d * num_ps);
num_dqs = (num_d * num_qs);
num_drs = (num_d * num_rs);
// THIS is the Fourth equation being substituted into the Second Equation
num_its = (num_i * num_ts);
num_ips = (num_i * num_ps);
num_iqs = (num_i * num_qs);
num_irs = (num_i * num_rs);
// THIS is the fourth equation being substituted into the Third Equation
num_nts = (num_n * num_ts);
num_nps = (num_n * num_ps);
num_nqs = (num_n * num_qs);
num_nrs = (num_n * num_rs);
System.out.println(num_a + "s + " + num_b + "a + " + num_c + "f + " + num_dts + " " + num_dps + "s + " + num_dqs + "a " + num_drs + "f = " + num_e);
System.out.println(num_f + "s + " + num_g + "a + " + num_h + "f + " + num_its + " " + num_ips + "s + " + num_iqs + "a " + num_irs + "f = " + num_j);
System.out.println(num_k + "s + " + num_l + "a + " + num_m + "f + " + num_nts + " " + num_nps + "s + " + num_nqs + "a " + num_nrs + "f = " + num_o);
}
}
You can't add, subtract, divide, or multiply String variables. You have to make your variables into ints in order to do that. Also, you can use an array to hold your variables, since there is so many of them.
String, Integer, Float, are not the same types. you can't apply operators like / or * on String for instance. + is special because it has a definition for String, which means concatenate.
Since you need to do some operations on the user inputs, you can read them directly as int:
System.out.print("Enter the first number: ");
int num_a = user_input.nextInt();
System.out.print("Enter the second number: ");
int num_b = user_input.nextInt();
Then you can do
int num_ab = a / b;
Note that if a < b, then num_ab will be 0, since this is an integer. You may want to do something like
float num_ab = (float)a / b;
Now, this code is quite tedious. If you accept to handle indices instead of letters for the variables, you can initialise them in a loop, e.g.
Scanner in = new Scanner(System.in);
int[] numbers = new int[20];
int index = 0;
while (index < numbers.length) {
System.out.println("Enter the "+(index+1)+"th number");
int n = in.nextInt();
numbers[index] = n;
index++;
}
System.out.println(Arrays.toString(numbers));
And use the array of numbers
// arrays start at 0
int num_ab = numbers[0] / numbers[1];
And if you want to be able to access the variables through names, you can define constants
static final int a = 0;
static final int b = 1;
static final int c = 2;
//...
int num_ab = numbers[a] / numbers[b];
But in your case, it may be handy to store initial variables and computed ones in some place where you can retrieve them for further computations:
// the store for all the variables and their value
static Map<String, Integer> vars = new HashMap<>();
// the function to read in the store
static Integer var(String name) {
return vars.get(name);
}
The store is initialised by a loop:
Scanner in = new Scanner(System.in);
// The 20 variables...
String alpha = "abcdefghijklmnopqrst";
for (char c : alpha.toCharArray()) {
String varName = String.valueOf(c);
System.out.println("Enter the value for "+ varName);
int n = in.nextInt();
vars.put(varName, n);
}
System.out.println(vars.toString());
int num_ab = var("a")/var("b");
// Store ab for further computation
vars.put("ab", num_ab);
System.out.println("ab is " + var("ab");
How can I get the sum of the three Total prices inside the if else statements for red velvet, buttercream and vanilla? And display it in allTextArea text area?
Here's my code:
double redVelvetPrice = 4.00;
double buttercreamPrice = 7.00;
double vanillaPrice = 3.00;
double firstHalf = 6.00;
double firstDozen = 12.00;
double firstBox = 25;
double secondHalf = 6.00;
double secondDozen = 12.00;
double secondBox = 25;
double thirdHalf = 6.00;
double thirdDozen = 12.00;
double thirdBox = 25;
String s1 = "";
String s2 = "The flavors you selected is/are: \n";
String s3 = "";
String s4 = "";
String s5 = "";
String totalPrice = "";
if (redVelvetCB.isSelected()){
s1=s1+ " "+ redVelvetCB.getText() + '\n';
if (firstHalfRB.isSelected()){
s3 ="A " + firstHalfRB.getText() + " of Red Velvet Cupcakes\n = $" + redVelvetPrice * firstHalf + '\n' + '\n';
}
else if (firstDozenRB.isSelected()){
s3 =firstDozenRB.getText() + " of Red Velvet Cupcakes\n = $" + redVelvetPrice * firstDozen + '\n' + '\n';
}
else if (firstBoxRB.isSelected()){
s3 =firstBoxRB.getText() + " of Red Velvet Cupcakes\n = $" + redVelvetPrice * firstBox + '\n' + '\n';
}
}
if (buttercreamCB.isSelected()){
s1=s1+ " "+ buttercreamCB.getText() + '\n';
if (secondHalfRB.isSelected()){
s4 ="A " + secondHalfRB.getText() + " of Buttercream Cupcakes\n = $" + buttercreamPrice * secondHalf + '\n' + '\n';
}
else if (secondDozenRB.isSelected()){
s4 =secondDozenRB.getText() + " of Buttercream Cupcakes\n = $" + buttercreamPrice * secondDozen + '\n' + '\n';
}
else if (secondBoxRB.isSelected()){
s4 =secondBoxRB.getText() + " of Buttercream Cupcakes\n = $" + buttercreamPrice * secondBox + '\n' + '\n';
}
}
if (vanillaCB.isSelected()){
s1=s1+ " "+ vanillaCB.getText() + '\n';
if (thirdHalfRB.isSelected()){
s5 ="A " + thirdHalfRB.getText() + " of Vanilla Cupcakes\n = $" + vanillaPrice * thirdHalf + '\n' + '\n';
}
else if (thirdDozenRB.isSelected()){
s5 =thirdDozenRB.getText() + " of Vanilla Cupcakes\n = $" + vanillaPrice * thirdDozen + '\n' + '\n';
}
else if (thirdBoxRB.isSelected()){
s5 =thirdBoxRB.getText() + " of Vanilla Cupcakes\n = $" + vanillaPrice * thirdBox + '\n' + '\n';
}
allTextArea.setText(greeting+s2+"\n"+s1+"\n"+s3+s4+s5+"\nTotal Price is "+totalPrice+".\n"+deliv+payment+bye);
I tried to set the total Price equal to redVelvetPrice + butercreamPrice + vanillaPrice, but the answer would be 14.0 which is the sum of the variables I initialized outside the if else statements (4.00,7.00,3.00),
I want it to be the sum of the prices of the three after selecting the quantity of each flavor. Help me.
You should use an other data type for the totalPrice. It's easier to calculate with numbers than strings.
double totalPrice = 0f;
After that you add up all the different combinations in your if/else statements
if (firstHalfRB.isSelected()){
s3 = "A " + firstHalfRB.getText() + " of Red Velvet Cupcakes\n = $" + redVelvetPrice * firstHalf + "\n\n";
totalPrice += (redVelvetPrice * firstHalf);
}
else if (firstDozenRB.isSelected()){
s3 = firstDozenRB.getText() + " of Red Velvet Cupcakes\n = $" + redVelvetPrice * firstDozen + "\n\n";
totalPrice += (redVelvetPrice * firstDozen);
}
When printing the total in the TextArea you may want to format it so it only has 2 positions after decimal point:
String.format("%.2f", totalPrice);
Hi I am new to Java programming. Why are my values returning null after I enter them on the input dialog. I have two classes, one called VehicleApp and the other called VehicleFactory. Help would be appreciated. Thanks.
Full code VehicleApp.java
package romprojectname;
import java.text.NumberFormat;
import javax.swing.JOptionPane;
public class VehicleApp{
public static void main(String[] args) {
String firstname = JOptionPane.showInputDialog("Enter your first name");
String lastname = JOptionPane.showInputDialog("Enter your last name");
long phone = Long.parseLong(JOptionPane.showInputDialog("Enter your phone"));
int nbrVehicles = Integer.parseInt(JOptionPane.showInputDialog("Enter number of vehicles"));
int nbrTanks = Integer.parseInt(JOptionPane.showInputDialog("Enter number of tanks"));
VehicleFactory vehicleObject = new VehicleFactory();
vehicleObject.getSummary();
vehicleObject.HayloFactory(firstname, lastname, phone, nbrVehicles, nbrTanks);
vehicleObject.calcFuelTankCost();
vehicleObject.calcManufacturingCost();
vehicleObject.calcSubtotal();
vehicleObject.calcTax();
vehicleObject.calcTotal();
}
}
Full code VehicleFactory.java
package romprojectname;
import java.text.NumberFormat;
import javax.swing.JOptionPane;
public class VehicleFactory{
private String firstname;
private String lastname;
private Long phone;
private int nbrVehicles =0;
private int nbrTanks =0;
private double manufactureCost =0;
private double fuelTankCost =0;
private double subtotal =0;
private double tax =0;
private double total = 0;
private final double VEHICLE_PRICE = 500.19;
private final double FUELCELL_PRICE = 2.15;
private final int CELLS_PER_TANK = 12;
private final double taxrate = 7.25 / 100 ;
public void HayloFactory(String firstname, String lastname, Long phone, int nbrVehicles, int nbrTanks){
this.firstname = firstname;
this.lastname = lastname;
this.phone = phone;
this.nbrVehicles = nbrVehicles;
this.nbrTanks = nbrTanks;
}
public void calcManufacturingCost(){
double manufactureCost = nbrVehicles * VEHICLE_PRICE;
}
public void calcFuelTankCost(){
double fuelTankCost = nbrVehicles * nbrTanks * CELLS_PER_TANK * FUELCELL_PRICE;
}
public void calcSubtotal(){
double subtotal = manufactureCost + fuelTankCost;
}
public void calcTax(){
double tax = subtotal * taxrate;
}
public void calcTotal(){
double total = subtotal + tax;
}
NumberFormat cf = NumberFormat.getCurrencyInstance();
public void getSummary(){
String summary = "WELCOME TO HAYLO MANUFACTURING" + "\n" + "\n";
summary += "Customer Name: " + firstname + " " + lastname + "\n";
summary += "Customer Phone: " + phone + "\n";
summary += "Number of Vehicles: " + nbrVehicles + "\n";
summary += "Number of Tanks: " + nbrTanks + "\n";
summary += "Vehicle Cost ($500.19 / vehicle): " + cf.format(manufactureCost) + "\n";
summary += "Tanks Cost ($2.15 / fuel cell): " + cf.format(fuelTankCost) + "\n";
summary += "Subtotal: " + cf.format(subtotal) + "\n";
summary += "Tax (7.25%): " + cf.format(tax) + "\n";
summary += "Total: " + cf.format(total) + "\n";
//display the summary
JOptionPane.showMessageDialog(null, summary);
}
}
Problem (code taken from VehicleFactory.java)
All of the summaries such as customer name are returning null values and all the costs and totals are $0.00.
public void getSummary(){
String summary = "WELCOME TO HAYLO MANUFACTURING" + "\n" + "\n";
summary += "Customer Name: " + firstname + " " + lastname + "\n";
summary += "Customer Phone: " + phone + "\n";
summary += "Number of Vehicles: " + nbrVehicles + "\n";
summary += "Number of Tanks: " + nbrTanks + "\n";
summary += "Vehicle Cost ($500.19 / vehicle): " + cf.format(manufactureCost) + "\n";
summary += "Tanks Cost ($2.15 / fuel cell): " + cf.format(fuelTankCost) + "\n";
summary += "Subtotal: " + cf.format(subtotal) + "\n";
summary += "Tax (7.25%): " + cf.format(tax) + "\n";
summary += "Total: " + cf.format(total) + "\n";
//display the summary
JOptionPane.showMessageDialog(null, summary);
You haven't really described the problem, but I suspect this is the cause:
VehicleFactory vehicleObject = new VehicleFactory();
vehicleObject.getSummary();
vehicleObject.HayloFactory(firstname, lastname, phone, nbrVehicles, nbrTanks);
You're calling getSummary before you call HayloFactory - so it's trying to display the values in the object before you've set them to useful values.
Additionally, all your calcXyz methods are introducing new local variables, like this:
public void calcTotal(){
double total = subtotal + tax;
}
Instead, they should be setting the field values:
public void calcTotal(){
total = subtotal + tax;
}
If you change all of your calculation methods appropriately, then move the getSummary() call to the very end, it will work. (It's not quite how I'd have written the code, but that's a different matter.)
The variables defined insides your methods have local scope only for example
double manufactureCost = nbrVehicles * VEHICLE_PRICE; it actually hides your class variable manufactureCost .. they should be instead used as
manufactureCost = nbrVehicles * VEHICLE_PRICE;
This way you can actually set the class variable which in turn displayed inside your getSummary method
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();