Answer To: (07AL) Programming Assignment 6 (PRE-FINAL BUILD) Students, For this programming assignment, take...
Kshitij answered on May 06 2021
may05_21/one/Mod7Main.java
may05_21/one/Mod7Main.java
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 06-May-21
* Time: 4:07 PM
* File: Mod7Main.java
*/
package May.may05_21.one;
import May.may05_21.two.Banking.Transaction;
import May.may05_21.two.Retail.Customer;
import May.may05_21.two.Retail.Inventory;
import May.may05_21.two.Retail.Location;
import May.may05_21.two.Retail.Person;
import java.util.Scanner;
public class Mod7Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 1 for new and 2 for old");
int choice = sc.nextInt();
if (choice == 1) {
mod7Main();
} else if (choice == 2) {
RetailMain1.run();
} else {
System.out.println("wrong entry");
}
}
private static void mod7Main() {
Customer[] customers = new Customer[2];
for (int i = 0; i < 2; i++) {
customers[i] = new Customer(new Person(i + "2", "john", "Sue", new Location("Itly", "Yenn", i + i + i + "33", 33)), new Inventory("22" + i + i, "Phone", 10 + (i * 4), 900.0 + i * 8));
}
for (int i = 0; i < 2; i++) {
System.out.println(customers[i].toString());
}
May.may05_21.two.Banking.Customer[] bCustomer = new May.may05_21.two.Banking.Customer[2];
for (int i = 0; i < 2; i++) {
bCustomer[i] = new May.may05_21.two.Banking.Customer(new May.may05_21.two.Banking.Person("2" + i, "sam", "john", new May.may05_21.two.Banking.Location("Itly", "Yenn", i + i + i + "33", 33)), true, 900.0 * (i + 1), new Transaction("k", "333", "2929298", 88.0));
}
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Perosn id");
String id = sc.next();
for (int i = 0; i < 2; i++) {
if (bCustomer[i].getPersonInfo().getPersonId().equalsIgnoreCase(id)) {
System.out.println(bCustomer[i].toString());
break;
}
}
}
}
may05_21/one/output.txt
may05_21/one/RetailMain1.java
may05_21/one/RetailMain1.java
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 22-Apr-21
* Time: 9:05 PM
* File: RetailMain1.java
*/
package May.may05_21.one;
import javax.swing.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class RetailMain1 {
/**
* By the end of this program the customer should have already found the best pick for her special
* occasion.
*/
public static void run() {
System.out.println("FDFD");
/**
* Author Mercedes Bautista
* This program helps the customers find the perfect
* dress for their special occasion and by entering their info they help us find
* the right size for them. The program at the beginning it starts by giving information about the company
* for example who is the owner, the year the company was found.
* The target for this program is mainly the customers. But the program also will include special
* deals for the employees just so they can also use the program.
*/
String outFileName = "C:\\Users\\kshitij varshney\\IdeaProjects\\GreyNodes\\src\\May\\may05_21\\one\\output.txt";
PrintWriter out = null;
for (int i = 1; i <= 2; i++) {
JOptionPane.showMessageDialog(null, i + " st time ", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
try {
out = new PrintWriter(new File(outFileName));
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
JFrame jf1 = new JFrame();
jf1.setAlwaysOnTop(true);
String nameCo = "LoreZ"; // Company Name
String myName = "Lorena Zepeda"; // Owner's name
String myName2 = "Mercedes B"; // Owner's name
JOptionPane.showMessageDialog(null, "About us" + "Name of company" + nameCo + " " + " " + "Founded by " + myName, "MESSAGE ", JOptionPane.PLAIN_MESSAGE);
out.println("About us" + "Name of company" + nameCo + " " + " " + "Founded by " + myName);
// Comparing Strings
if (myName.compareTo(myName2) < 0) {
JOptionPane.showMessageDialog(null, myName + " has less authority in the company than " + myName2, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
} else if (myName.compareTo(myName2) == 0) {
JOptionPane.showMessageDialog(null, myName + "is equal to " + myName2, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
} else if (myName.compareTo(myName2) > 0) {
JOptionPane.showMessageDialog(null, myName + "is greater than " + myName2, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
}
String typeOfIndustry = "Retail"; // Type of Industry
String typeOfIndustry2 = "Health"; // Type of Industry 2
JOptionPane.showMessageDialog(null, "Type of Industry:" + typeOfIndustry, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
if (typeOfIndustry.equals(typeOfIndustry2)) // Comparing Industries
{
JOptionPane.showMessageDialog(null, "Industries are the same", "message", JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Industry Retail and Health are not the same", "Message", JOptionPane.PLAIN_MESSAGE);
}
final int yearFound = 1999; // Company was found
JOptionPane.showMessageDialog(null, "What year was the company found?" + yearFound, "message", JOptionPane.PLAIN_MESSAGE);
long numOfEmp = 100000; // Number of Employees
JOptionPane.showMessageDialog(null, "Number of Employees:" + numOfEmp, "message", JOptionPane.PLAIN_MESSAGE);
double empSalary = 20.99; // Employee Salary
JOptionPane.showMessageDialog(null, "What is the salary for employees:$ " + empSalary, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
double discountPercent = 15.00; // Discount per employee
JOptionPane.showMessageDialog(null, "Member Discount: $ %.2f\n" + discountPercent, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(jf1, "Discount Percent per employee " + discountPercent + "%");
char isHiring = 'Y'; // Company Hiring Status
String myStr = String.valueOf(isHiring); // Convert char to String
JOptionPane.showMessageDialog(null, "Is the company hiring? " + myStr, "MESSAGE", JOptionPane.PLAIN_MESSAGE); // Print string value
boolean isMember = true; // Member Discount
JOptionPane.showMessageDialog(null, "Membership Discount:" + isMember, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
int companyPay = 100000; // Company Penalties
JOptionPane.showMessageDialog(null, "Company Penalties: $" + companyPay, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
long companyBenefit = 805000; // Company Benefits
JOptionPane.showMessageDialog(null, "Company Benefits: $" + companyBenefit, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
float totalEmpSal; // Total Employee's Salary
totalEmpSal = (float) (empSalary * numOfEmp); // Calculates Total Employees' Salary
System.out.println("Total Employees' Salary: $" + totalEmpSal);
final double companyCost; // Company Cost
companyCost = totalEmpSal + companyPay; // Calculates Company Cost
JOptionPane.showMessageDialog(null, "Company Cost: $" + companyCost, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
double netCost; // Net Cost
netCost = companyCost - companyBenefit; // Calculates Net Cost
JOptionPane.showMessageDialog(null, "Net Cost: $" + netCost, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
double netPerEmp; // Net Per Employee
netPerEmp = netCost / numOfEmp; // Calculates Net per Employee
System.out.println();
JOptionPane.showInputDialog(null, "Net Cost per Employee: $" + netPerEmp, "MESSAGE", JOptionPane.PLAIN_MESSAGE);
int budget = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter your budget: ", "INPUT", JOptionPane.PLAIN_MESSAGE));
JOptionPane.showMessageDialog(null, "The budget is " + budget, "Message", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(jf1,
"At Lorez, we tried to find you the perfect dress for your special occasion, "
+ "We're amazed you have picked us");
String getDiscountStr; // Get the customer to decide if he/she wants a discount
// Decision of customer regarding discount
JOptionPane.showMessageDialog(null, "Do you want to get a discount by joining? (Enter yes or no)", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
int count = 0;
do {
count++;
getDiscountStr = JOptionPane.showInputDialog(null, "Enter next", "INPUT", JOptionPane.PLAIN_MESSAGE);
if (!getDiscountStr.equalsIgnoreCase("yes") && !getDiscountStr.equalsIgnoreCase("no")) {
JOptionPane.showMessageDialog(null, "Enter yes or no", "INPUT", JOptionPane.PLAIN_MESSAGE);
}
} while (!getDiscountStr.equalsIgnoreCase("yes") && !getDiscountStr.equalsIgnoreCase("no") && count < 3);
if (!getDiscountStr.equalsIgnoreCase("yes")) {
JOptionPane.showMessageDialog(null, "Program exist due to wrong input", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
System.exit(1);
}
boolean getDiscount = getDiscountStr.equalsIgnoreCase("yes");
count--;
// Customers Phone Number
String phoneNumber;
if (getDiscount) {
do {
phoneNumber = JOptionPane.showInputDialog(null, "Enter phone number", "INPUT", JOptionPane.PLAIN_MESSAGE);
if (phoneNumber == null || phoneNumber.trim().length() == 0) {
JOptionPane.showMessageDialog(null, "Enter valid phone number", "INPUT", JOptionPane.PLAIN_MESSAGE);
}
} while (phoneNumber == null || phoneNumber.trim().length() == 0);
// for
// discount
JOptionPane.showMessageDialog(jf1,
"Thank You, for entering your Phone Number. You get a 15% discount!!"); // Display Message
}
JOptionPane.showMessageDialog(null, "Enter the number of items you want to buy. Pick 1-3 to get an extra 5% off!!", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
int numberOfItems;
do {
numberOfItems = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter no of items", "INPUT", JOptionPane.PLAIN_MESSAGE));
if (numberOfItems < 1 || numberOfItems > 3) {//number of items to buy should be at least 1
JOptionPane.showMessageDialog(null, "Number of items should be between 1 and 3", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
}
} while (numberOfItems < 1 || numberOfItems > 3);
int discountPercentage = 0;
if (getDiscount) {
switch (numberOfItems) // determine number picked by customer
{
case 1:
JOptionPane.showMessageDialog(null, "You picked 2, you get an extra 5% off\"You picked 1, sorry you don't get a discount ", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
discountPercentage = 0;
break;
case 2:
JOptionPane.showMessageDialog(null, "You picked 2, you get an extra 5% off", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
discountPercentage = 5;
break;
case 3:
JOptionPane.showMessageDialog(null, "You picked 3, Surprise you get 10% off instead!!!!", "MESSAGE", JOptionPane.PLAIN_MESSAGE);
discountPercentage = 10;
break;
default:
break;
}
}
//get the size of the customer
int size = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter size ", "INPUT", JOptionPane.PLAIN_MESSAGE));
int itemPrice = 0;
//check if the size of greater than 10
if (size > 10) {
JOptionPane.showMessageDialog(jf1, ("Sorry we don't have that size for now. We're workin...