Java Programming
I have an assignment that is almost complete but there are some lines of code causing it not compile and I can’t get to any of the logic errors. I would like these fixed along with some explanation of what you did. You can put this is lines of comment and I can delete them later.
The syntax errors I caught are as follows on the lines I see: Controller class: 167; Person class: 139, 143 (there was a third at the end but i got rid of an extra }) Several lines in the Controller class don’t have a syntax error but they probably are logic errors: 39, 42, 69, 74, 79, 82, 86, 108, 111, 127, 130, 150, 153, 159, 163.
There could also be logic errors elsewhere. There may also be typographical errors as well because the professor has always had at least one.
COP2210: Project 3
Important:
Do not copy someone’s code. You may be randomly selected to explain your code. If you cannot
explain your code, you will get a zero for the project grade. If you are stuck please ask me. I will
gladly help you. Remember the goal is to learn.
SUPER IMPORTANT !!!!
Start looking at this code right away and work on it a little at a time. It will be a pain, but you will
learn a lot from this project. Here is a road map to get this project right. Follow the order below
and you will get the project done with you understanding each part of it.
Grading
What I am checking in your code:
• The Code is not a copy. If it is a copy you will get a grade of zero.
• Code indentation
• The Code runs correctly
• The Code output is correct and is in the correct format
• The Code adheres to the UML specifications
Steps:
1) Create a Netbeans Project that matches the figure below. The Controller.java has the main().
2) Create Package Structure such that it matches the structure shown below:
3) Create the Person.java, Item.java, CreditCard.java files and make sure they are in the correct
package.
4) Copy and paste the Item.java code that the end of the document into your Item.java file. This
code does not need to be modified.
5) You need to add the following file header on the top of the Controller.java file. Not doing this
will result in a 40% reduction for your project grade.
File Header
//=============================================================================
// PROGRAMMER: Your name
// PANTHER ID: Your panther ID
//
// CLASS: COP2210
// SECTION: Your class section: example U01
// SEMESTER: The current semester: example Fall 2018
// CLASSTIME: Your COP2210 course meeting time :example T/TH 9:00-10:15 am
//
// Project: Put what this project is: example Lab 5 or Project 1
// DUE:
//
// CERTIFICATION: I understand FIU’s academic policies, and I certify that this work is my
// own and that none of it is the work of any other person.
//=============================================================================
6) Copy and paste the Person.java code into your Person.java file. Write the code for 1 and 2
that are illustrated below. Look at the comments in the code they state what you need to do.
package client;
import java.util.ArrayList;
import payment.CreditCard;
public class Person {
//—————————————————————————
// Instance Variable
//—————————————————————————
// check the UML diagram to see which instance variable you need
1) // YOUR CODE HERE
ArrayList creditCards;
//—————————————————————————
// Constructor
//—————————————————————————
public Person(String firstName,
String lastName,
String streetAddress,
String suiteAddress,
String cityAddress,
String stateAddress) {
// assign the input values to the instance variables
2) // YOUR CODE HERE
creditCards = new ArrayList<>();
}//end constructor
7) In your project’s Person.java file complete the code for the remaining setter and getters
methods at location 1. Look at the UML diagram to see which methods you need to write.
IMPORTANT: Keep the displayInfo() method commented out for now.
//—————————————————————————
// Setter and Getters
//—————————————————————————
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getSuiteAddress() {
return suiteAddress;
}
public void setSuiteAddress(String suiteAddress) {
this.suiteAddress = suiteAddress;
}
// write the code for the needed setter and getters
// check the UML Diagram
1) // YOUR CODE HERE
8) Copy and paste the Controller.java code into your Controller.java file. Write the code for 1 that
is illustrated below.
package app;
//imports here
// YOUR CODE HERE
public class Controller {
public static void main(String[] args) throws InterruptedException{
// create a person variable named john with following info:
// FirstName: John
// LastName: Doe
// Street Address: 1100 Brickell Ave
// Suite Address: Apt 102
// City: Miami
// State: Florida
1) // YOUR CODE HERE
9) Copy and paste the CreditCard.java code into your CreditCard.java file. Write the code for 1
that is illustrated below. Look at the comments in the code they state what you need to do.
package payment;
import client.Person;
import goods.Item;
import java.util.ArrayList;
import java.util.Date;
public class CreditCard {
Person cardHolder;
String type;
String cardNumber;
double creditLimit;
double currentBalance;
double nextPaymentAmount;
ArrayList
ArrayList
//—————————————————————————
// Constructor
//—————————————————————————
public CreditCard(Person cardHolder, String type, double creditLimit) {
// assign the input to the instance variables
1) // YOUR CODE HERE
transactions = new ArrayList
transactionsTimeStamps = new ArrayList
}
10) In your CreditCard.java file write the code for 1 and 2 that are illustrated below. Look at the
comments in the code they state what you need to do. In 1 you are checking if you can make the
charge by seeing if your item price less than the credit card’s available credit remaining. Hint you
do not have an instance variable for this. Do not create an instance variable for this. If you do
you will lose many points.
public void makeCharge(Item item){
1) if( // YOUR CODE HERE){
transactions.add(item);
Date date = new Date();
transactionsTimeStamps.add(date);
currentBalance += item.getPrice();
System.out.println(“”);
System.out.println(“Charging: ” + item.getName());
System.out.println(“Transaction completed successfully”);
System.out.println(“Please remove your ” + type );
System.out.println(“”);
}else{
System.out.println(“”);
System.out.println(“Charging: ” + item.getName());
System.out.println(“Transaction was not successful”);
System.out.println(“Credit Limit Issue”);
System.out.println(“Please remove your ” + type );
System.out.println(“”);
}
}//end makeCharge
public void transactionsReport(){
System.out.println(“”);
System.out.println(“============================================================================”);
System.out.println(type + ” Transaction Report” );
System.out.println(“============================================================================”);
System.out.printf(“%-20s $%-10.2f\n”, “Credit Limit:”,creditLimit);
// you need print out the Available Credit
2) // YOUR CODE HERE
System.out.printf(“%-20s $%-10.2f\n”, “Current Balance:”, currentBalance);
System.out.println(“————————————————————————“);
double totalCharges = 0.0;
for(int i=0; i 11) // create a Credit Card variable named masterCard with the following info: // create a Credit Card variable named ax with the following info: //adding the masterCard to john // add the American Express to the person john // creating and Item variable named cafeMocha with the following info: // creating and Item variable named gucciSlipper with the following info: // creating and Item variable named coke with the following info: // creating and Item variable named airlinesTicket with the following info: 12) In your Controller.java file write the code for 2, 3, 4, and 5. Uncomment the code for 1 and // john is buying cafeMocha using his MasterCard credit card // john is buying gucciSlipper using his MasterCard credit card // john is buying gucciSlipper using his American Express credit card // john is running a transaction Report on his MasterCard // john is running a transaction Report on his American Express 13) In your Controller.java file write the code for 1,2, and 3. Read the comments to get hints how // buying 7 cafeMocha using different credit cards // buying 5 airlinesTicket using different credit cards 13) In your Controller.java file write the code for 1 and 2. Read the comments to get hints how // john is running a transaction Report on his masterCard // john is running a transaction Report on his American Express 13) In your Controller.java file write the code for 1. Also you need to uncomment the displayInfo // john is running displayInfo method
1) // YOUR CODE HERE Code for the Person Class…… //————————————————————————— System.out.println(“============================================================================”); System.out.println(“============================================================================”); System.out.println(“——————“); for(int i=0; i UML Diagrams
Controller.java code package app; import java.util.Random; public class Controller { public static void main(String[] args) throws InterruptedException{ // create a person variable named john with following info: // create a Credit Card variable named masterCard with the following info: // create a Credit Card variable named ax with the following info: //adding the masterCard to john // add the American Express to the person john // creating and Item variable named cafeMocha with the following info: // creating and Item variable named gucciSlipper with the following info: // creating and Item variable named coke with the following info: // creating and Item variable named airlinesTicket with the following info: // john is buying cafeMocha using his MasterCard credit card // john is buying gucciSlipper using his MasterCard credit card // john is buying gucciSlipper using his American Express credit card Controller.java code continue… // john is running a transaction Report on his MasterCard // john is running a transaction Report on his American Express Random generator = new Random(); // buying 7 cafeMocha using different credit cards }//end for // buying 5 airlinesTicket using different credit cards CreditCard.java code import client.Person; public class CreditCard { Person cardHolder; String cardNumber; double creditLimit; ArrayList //————————————————————————— public CreditCard(Person cardHolder, String type, double creditLimit) { // assign the input to the instance variables transactions = new ArrayList //————————————————————————— public Person getCardHolder() { public String getType() { public String getCardNumber() { public double getCreditLimit() { public void setCreditLimit(double creditLimit, String personal) { public double getCurrentBalance() { public double getNextPaymentAmount() { //————————————————————————— public void makeCharge(Item item){
CreditCard.java code continue… if( // YOUR CODE HERE){ transactions.add(item); System.out.println(“”); }//end makeCharge public void transactionsReport(){ System.out.println(“”); System.out.println(“============================================================================”); System.out.println(“============================================================================”); // you need ound the Avaiable Credit System.out.printf(“%-20s $%-10.2f\n”, “Current Balance:”, currentBalance); double totalCharges = 0.0; for(int i=0; i Person.java code package client; import java.util.ArrayList; public class Person { //————————————————————————— ArrayList creditCards; //————————————————————————— public Person(String firstName, // assign the input values to the instance variables creditCards = new ArrayList<>(); }//end constructor //————————————————————————— public void setFirstName(String firstName) { public String getLastName() { public void setLastName(String lastName) { public String getStreetAddress() { public void setStreetAddress(String streetAddress) { public String getSuiteAddress() { public void setSuiteAddress(String suiteAddress) { Person.java code continue… //————————————————————————— System.out.println(“============================================================================” System.out.println(“============================================================================” System.out.println(“——————“); for(int i=0; i Item.java code package goods; public class Item { String catagory; public Item(String catagory, String name, double price) { public String getCatagory() { public String getName() { public double getPrice() { public void setPrice(double price, String personal) { public void displayInfo(){ } } Code Execution Output Charging: Cafe Mocha Charging: Gucci Princetown Charging: Gucci Princetown ============================================================================ ============================================================================ Charging: Cafe Mocha Charging: Cafe Mocha Charging: Cafe Mocha Charging: Cafe Mocha Charging: Cafe Mocha Charging: Cafe Mocha Charging: Cafe Mocha Charging: MIA-SFO Charging: MIA-SFO Charging: MIA-SFO Charging: MIA-SFO Charging: MIA-SFO randomSelectCard: MasterCard Charging: Coke randomSelectCard: American Express Charging: Coke randomSelectCard: American Express Charging: Coke randomSelectCard: MasterCard Charging: Coke randomSelectCard: American Express Charging: Coke randomSelectCard: American Express Charging: Coke randomSelectCard: American Express Charging: Coke randomSelectCard: MasterCard Charging: Coke randomSelectCard: MasterCard
Charging: Coke randomSelectCard: MasterCard Charging: Coke ============================================================================ ============================================================================ ============================================================================ CreditCard: American Express COP2210_Project3-FALL2020/build.xml COP2210_Project3-FALL2020/build/built-jar.properties C\:\\Users\\user\\Documents\\NetBeansProjects\\COP2210_Project3-FALL2020= COP2210_Project3-FALL2020/manifest.mf COP2210_Project3-FALL2020/nbproject/build-impl.xml Must set javac.includes No tests executed. Must set JVM to use for profiling in profiler.info.jvm COP2210_Project3-FALL2020/nbproject/genfiles.properties COP2210_Project3-FALL2020/nbproject/private/private.properties COP2210_Project3-FALL2020/nbproject/private/private.xml COP2210_Project3-FALL2020/nbproject/project.properties COP2210_Project3-FALL2020/nbproject/project.xml COP2210_Project3-FALL2020 COP2210_Project3-FALL2020/src/app/Controller.java //imports here // YOUR CODE HERE import import import import public john john transactions transactionsTimeStamps
// cardHolder: the person that you create above
// Type: MasterCard
// Credit Limit: 2500.00
1) // YOUR CODE HERE
// cardHolder: the person that you create above
// Type: American Express
// Credit Limit: 5000.00
2) // YOUR CODE HERE
3) //john.getCreditCards().add(masterCard);
4) // YOUR CODE HERE
5) //Item cafeMocha = new Item(“Food”, “Cafe Mocha”, 4.77);
// Cataory: Clothing
// Name: Gucci Princetown
// Price: 2650.00
6) // YOUR CODE HERE
// Cataory: Food
// Name: Coke
// Price: 1.99
7) // YOUR CODE HERE
// Cataory: Travel
// Name: MIA-SFO
// Price: 823.26
8) // YOUR CODE HERE
use it to figure out how to write the code for 2 and 3. Also, uncomment the code for 4 and use it
to figure out the code for 5.
1) //((CreditCard)john.getCreditCards().get(0)).makeCharge(cafeMocha);
// hint this may run into credit limit issues
2) // YOUR CODE HERE
3) // YOUR CODE HERE
4) //((CreditCard)john.getCreditCards().get(0)).transactionsReport();
5) // YOUR CODE HERE
to write the code. Also look at the code execution output to figure out the code.
for(int i=1; i<=7; i++){
// DO NOT MESS WITH THE SLEEP CODE
// sleep for a random time upto 1 seconds
Thread.sleep(generator.nextInt(1001));
// buy cafeMocha on MasterCard if the cafeMocha is a multiple 3
// else buy it on the AX card
// example
// i = 1 -> Buy it on the AX
// i = 2 -> Buy it on the AX
// i = 3 -> Buy it on the MasterCard
// i = 4 -> Buy it on the AX
// …
// hint use if else statement
1) // YOUR CODE HERE
}//end for
for(int i=1; i<=5; i++){
// DO NOT MESS WITH THE SLEEP CODE
// sleep for a random time upto 1 seconds
Thread.sleep(generator.nextInt(1001));
// buy airlinesTicket on MasterCard if i is even
// else buy it on the AX card
// hint use if else statement
2) // YOUR CODE HERE
}//end for
// buying 10 cokes using different credit cards
for(int i=1; i<=10; i++){
// sleep for a random time upto 1 seconds
Thread.sleep(generator.nextInt(1001));
// this is use to randomly select a credit card
int randomSelectCard = generator.nextInt(2);
// if randomSelectCard is 0 use the MasterCard
// if this is the case print out "randomSelectCard: MasterCard"
// if randomSelectCard is 1 use the American Express
// if this is the case print out "randomSelectCard: MasterCard"
// hint use if else statement
3) // YOUR CODE HERE
}//end for
to write the code. Check your code execution output. If something does not look correct at your
Credit Card reporting code.
1) // YOUR CODE HERE
2) // YOUR CODE HERE
method in the Person class for it to output anything on the console when running the code.
// Utility Methods
//—————————————————————————
/*
public void displayInfo(){
System.out.println(“”);
System.out.println(“Display Information” );
System.out.printf(“%-20s %s %s \n”,”Name:”, firstName, lastName);
System.out.printf(“%-20s %-20s \n”, “Address”, streetAddress);
// write the code needed for the output to match the project doc output
// hint look at the code above to have the correct format
// YOUR CODE HERE
System.out.println(“Credit Card Info”);
System.out.println(“——————“);
//imports here
// YOUR CODE HERE
// FirstName: John
// LastName: Doe
// Street Address: 1100 Brickell Ave
// Suite Address: Apt 102
// City: Miami
// State: Florida
// YOUR CODE HERE
// cardHolder: the person that you create above
// Type: MasterCard
// Credit Limit: 2500.00
// YOUR CODE HERE
// cardHolder: the person that you create above
// Type: American Express
// Credit Limit: 5000.00
// YOUR CODE HERE
//john.getCreditCards().add(masterCard);
// YOUR CODE HERE
//Item cafeMocha = new Item(“Food”, “Cafe Mocha”, 4.77);
// Cataory: Clothing
// Name: Gucci Princetown
// Price: 2650.00
// YOUR CODE HERE
// Cataory: Food
// Name: Coke
// Price: 1.99
// YOUR CODE HERE
// Cataory: Travel
// Name: MIA-SFO
// Price: 823.26
// YOUR CODE HERE
//((CreditCard)john.getCreditCards().get(0)).makeCharge(cafeMocha);
// hint this may run into credit limit issues
// YOUR CODE HERE
// YOUR CODE HERE
//((CreditCard)john.getCreditCards().get(0)).transactionsReport();
// YOUR CODE HERE
for(int i=1; i<=7; i++){
// DO NOT MESS WITH THE SLEEP CODE
// sleep for a random time upto 1 seconds
Thread.sleep(generator.nextInt(1001));
// buy cafeMocha on MasterCard if the cafeMocha is a multiple 3
// else buy it on the AX card
// example
// i = 1 -> Buy it on the AX
// i = 2 -> Buy it on the AX
// i = 3 -> Buy it on the MasterCard
// i = 4 -> Buy it on the AX
// …
// hint use if else statement
// YOUR CODE HERE
for(int i=1; i<=5; i++){
// DO NOT MESS WITH THE SLEEP CODE
// sleep for a random time upto 1 seconds
Thread.sleep(generator.nextInt(1001));
// buy airlinesTicket on MasterCard if i is even
// else buy it on the AX card
// hint use if else statement
// YOUR CODE HERE
}//end for
// buying 10 cokes using different credit cards
for(int i=1; i<=10; i++){
// sleep for a random time upto 1 seconds
Thread.sleep(generator.nextInt(1001));
// this is use to randomly select a credit card
int randomSelectCard = generator.nextInt(2);
// if randomSelectCard is 0 use the MasterCard
// if this is the case print out "randomSelectCard: MasterCard"
// if randomSelectCard is 1 use the American Express
// if this is the case print out "randomSelectCard: MasterCard"
// hint use if else statement
// YOUR CODE HERE
}//end for
// john is running a transaction Report on his masterCard
// YOUR CODE HERE
// john is running a transaction Report on his American Express
// YOUR CODE HERE
// john is running displayInfo method
// YOUR CODE HERE
}//end main
}//end class
package payment;
import goods.Item;
import java.util.ArrayList;
import java.util.Date;
String type;
double currentBalance;
double nextPaymentAmount;
ArrayList
// Constructor
//—————————————————————————
// YOUR CODE HERE
transactionsTimeStamps = new ArrayList
}
// Setters and Getters
//—————————————————————————
return cardHolder;
}
return type;
}
return cardNumber;
}
return creditLimit;
}
this.creditLimit = creditLimit;
}
return currentBalance;
}
return nextPaymentAmount;
}
// Utility Methods
//—————————————————————————
Date date = new Date();
transactionsTimeStamps.add(date);
currentBalance += item.getPrice();
System.out.println(“Charging: ” + item.getName());
System.out.println(“Transaction completed successfully”);
System.out.println(“Please remove your ” + type );
System.out.println(“”);
}else{
System.out.println(“”);
System.out.println(“Charging: ” + item.getName());
System.out.println(“Transaction was not successful”);
System.out.println(“Credit Limit Issue”);
System.out.println(“Please remove your ” + type );
System.out.println(“”);
}
System.out.println(type + ” Transaction Report” );
System.out.printf(“%-20s $%-10.2f\n”, “Credit Limit:”,creditLimit);
// YOUR CODE HERE
System.out.println(“————————————————————————“);
import payment.CreditCard;
// Instance Variable
//—————————————————————————
// check the UML diagram to see which instance variable you need
// YOUR CODE HERE
// Constructor
//—————————————————————————
String lastName,
String streetAddress,
String suiteAddress,
String cityAddress,
String stateAddress) {
// YOUR CODE HERE
// Setter and Getters
//—————————————————————————
public String getFirstName() {
return firstName;
}
this.firstName = firstName;
}
return lastName;
}
this.lastName = lastName;
}
return streetAddress;
}
this.streetAddress = streetAddress;
}
return suiteAddress;
}
this.suiteAddress = suiteAddress;
}
// write the code for the needed setter and getters
// check the UML Diagram
// YOUR CODE HERE
// Utility Methods
//—————————————————————————
/*
public void displayInfo(){
System.out.println(“”);
);
System.out.println(“Display Information” );
);
System.out.printf(“%-20s %s %s \n”,”Name:”, firstName, lastName);
System.out.printf(“%-20s %-20s \n”, “Address”, streetAddress);
// write the code needed for the output to match the project doc output
// hint look at the code above to have the correct format
// YOUR CODE HERE
System.out.println(“Credit Card Info”);
System.out.println(“——————“);
String name;
double price;
this.catagory = catagory;
this.name = name;
this.price = price;
}
return catagory;
}
return name;
}
return price;
}
this.price = price;
}
IMPORTANT: Your code output will be different because of the random selection when buying the
10 cokes. Hence the transaction reports and balances will be different at each run.
Transaction completed successfully
Please remove your MasterCard
Transaction was not successful
Credit Limit Issue
Please remove your MasterCard
Transaction completed successfully
Please remove your American Express
MasterCard Transaction Report
============================================================================
Credit Limit: $2500.00
Avaiable Credit: $2495.23
Current Balance: $4.77
—————————————————————————-
Cafe Mocha Food $4.77 Thu Mar 26 14:11:10 EDT 2020
—————————————————————————-
Total Charges: $4.77
American Express Transaction Report
============================================================================
Credit Limit: $5000.00
Avaiable Credit: $2350.00
Current Balance: $2650.00
—————————————————————————-
Gucci Princetown Clothing $2650.00 Thu Mar 26 14:11:10 EDT 2020
—————————————————————————-
Total Charges: $2650.00
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your MasterCard
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your MasterCard
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your MasterCard
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your MasterCard
Transaction was not successful
Credit Limit Issue
Please remove your American Express
Transaction completed successfully
Please remove your MasterCard
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your MasterCard
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your American Express
Transaction completed successfully
Please remove your MasterCard
Transaction completed successfully
Please remove your MasterCard
Transaction completed successfully
Please remove your MasterCard
MasterCard Transaction Report
============================================================================
Credit Limit: $2500.00
Avaiable Credit: $829.22
Current Balance: $1670.78
—————————————————————————-
Cafe Mocha Food $4.77 Thu Mar 26 14:11:10 EDT 2020
Cafe Mocha Food $4.77 Thu Mar 26 14:11:12 EDT 2020
Cafe Mocha Food $4.77 Thu Mar 26 14:11:12 EDT 2020
MIA-SFO Travel $823.26 Thu Mar 26 14:11:14 EDT 2020
MIA-SFO Travel $823.26 Thu Mar 26 14:11:15 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:17 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:20 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:21 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:22 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:22 EDT 2020
—————————————————————————-
Total Charges: $1670.78
American Express Transaction Report
============================================================================
Credit Limit: $5000.00
Avaiable Credit: $669.68
Current Balance: $4330.32
—————————————————————————-
Gucci Princetown Clothing $2650.00 Thu Mar 26 14:11:10 EDT 2020
Cafe Mocha Food $4.77 Thu Mar 26 14:11:10 EDT 2020
Cafe Mocha Food $4.77 Thu Mar 26 14:11:11 EDT 2020
Cafe Mocha Food $4.77 Thu Mar 26 14:11:12 EDT 2020
Cafe Mocha Food $4.77 Thu Mar 26 14:11:12 EDT 2020
Cafe Mocha Food $4.77 Thu Mar 26 14:11:13 EDT 2020
MIA-SFO Travel $823.26 Thu Mar 26 14:11:13 EDT 2020
MIA-SFO Travel $823.26 Thu Mar 26 14:11:15 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:18 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:19 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:20 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:20 EDT 2020
Coke Food $1.99 Thu Mar 26 14:11:21 EDT 2020
—————————————————————————-
Total Charges: $4330.32
Display Information
============================================================================
Name: John Doe
Address 1100 Brickell Ave
Suite: Apt 102
City: Miami
State: Florida
——————
Credit Card Info
——————
CreditCard: MasterCard
Credit Limit: 2500.00
Current Balance: 1670.78
Credit Limit: 5000.00
Current Balance: 4330.32
Builds, tests, and runs the project COP2210_Project3-FALL2020.
#Fri, 04 Dec 2020 14:39:35 -0500
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Must set src.dir
Must set test.src.dir
Must set build.dir
Must set dist.dir
Must set build.classes.dir
Must set dist.javadoc.dir
Must set build.test.classes.dir
Must set build.test.results.dir
Must set build.classes.excludes
Must set dist.jar
Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
build.xml.data.CRC32=0e47a5f4
build.xml.script.CRC32=c8cc2a7e
build.xml.stylesheet.CRC32=f85dc8f2@1.95.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=0e47a5f4
nbproject/build-impl.xml.script.CRC32=37b10357
nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.95.0.48
compile.on.save=true
user.properties.file=C:\\Users\\user\\AppData\\Roaming\\NetBeans\\12.0\\build.properties
file:/C:/Users/user/Documents/NetBeansProjects/COP2210_Project3-FALL2020/src/client/Person.java
file:/C:/Users/user/Documents/NetBeansProjects/COP2210_Project3-FALL2020/src/app/Controller.java
file:/C:/Users/user/Documents/NetBeansProjects/COP2210_Project3-FALL2020/src/payment/CreditCard.java
file:/C:/Users/user/Documents/NetBeansProjects/COP2210_Project3-FALL2020/src/goods/Item.java
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/COP2210_Project3-FALL2020.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/COP2210_Project3-FALL2020
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=14
javac.target=14
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
# The jlink additional root modules to resolve
jlink.additionalmodules=
# The jlink additional command line parameters
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=COP2210_Project3-FALL2020
main.class=app.Controller
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
org.netbeans.modules.java.j2seproject
COP2210_Project3-FALL2020/src/app/Controller.java
package
app
;
java
.
util
.
Random
;
client
.
Person
;
goods
.
Item
;
payment
.
CreditCard
;
class
Controller
{
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
// create a person variable named john with following info:
// FirstName: John
// LastName: Doe
// Street Address: 1100 Brickell Ave
// Suite Address: Apt 102
// City: Miami
// State: Florida
// YOUR CODE HERE
Person
john
=
new
Person
(
“John”
,
“Doe”
,
“1100 Brickell Ave”
,
“Apt 102″
,
” Miami”
,
“Florida”
);
// create a Credit Card variable named masterCard with the following info:
// cardHolder: the person that you create above
// Type: MasterCard
// Credit Limit: 2500.00
// YOUR CODE HERE
CreditCard
masterCard
=
new
CreditCard
(
john
,
“MasterCard”
,
2500.00
);
// create a Credit Card variable named ax with the following info:
// cardHolder: the person that you create above
// Type: American Express
// Credit Limit: 5000.00
// YOUR CODE HERE
CreditCard
ax
=
new
CreditCard
(
john
,
“American Express”
,
5000.00
);
//adding the masterCard to john
.
getCreditCards
().
add
(
masterCard
);
// add the American Express to the person john
.
getCreditCards
().
add
(
ax
);
// creating and Item variable named cafeMocha with the following info:
Item
cafeMocha
=
new
Item
(
“Food”
,
“Cafe Mocha”
,
4.77
);
// creating and Item variable named gucciSlipper with the following info:
// Cataory: Clothing
// Name: Gucci Princetown
// Price: 2650.00
// YOUR CODE HERE
Item
gucciSlipper
=
new
Item
(
“Clothing”
,
“Gucci Princetown”
,
2650.00
);
// creating and Item variable named coke with the following info:
// Cataory: Food
// Name: Coke
// Price: 1.99
// YOUR CODE HERE
Item
coke
=
new
Item
(
“Food”
,
“Coke”
,
1.99
);
// creating and Item variable named airlinesTicket with the following info:
// Cataory: Travel
// Name: MIA-SFO
// Price: 823.26
// YOUR CODE HERE
Item
airlinesTicket
=
new
Item
(
“Travel”
,
“MIA-SFO”
,
823.26
);
// john is buying cafeMocha using his MasterCard credit card
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
cafeMocha
);
// john is buying gucciSlipper using his MasterCard credit card
// hint this may run into credit limit issues
// YOUR CODE HERE
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
gucciSlipper
);
// john is buying gucciSlipper using his American Express credit card
// YOUR CODE HERE
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
gucciSlipper
);
// john is running a transaction Report on his MasterCard
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
transactionsReport
();
// john is running a transaction Report on his American Express
// YOUR CODE HERE
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
transactionsReport
();
Random
generator
=
new
Random
();
// buying 7 cafeMocha using different credit cards
for
(
int
i
=
1
;
i
<=
7
;
i
++
){
// DO NOT MESS WITH THE SLEEP CODE
// sleep for a random time upto 1 seconds
Thread
.
sleep
(
generator
.
nextInt
(
1001
));
// buy cafeMocha on MasterCard if the cafeMocha is a multiple 3
// else buy it on the AX card
// example
// i = 1 -> Buy it on the AX
// i = 2 -> Buy it on the AX
// i = 3 -> Buy it on the MasterCard
// i = 4 -> Buy it on the AX
// …
// hint use if else statement
// YOUR CODE HERE
if
(
i
%
3
==
0
)
{
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
cafeMocha
);
}
else
{
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
cafeMocha
);
}
}
//end for
// buying 5 airlinesTicket using different credit cards
for
(
int
i
=
1
;
i
<=
5
;
i
++
){
// DO NOT MESS WITH THE SLEEP CODE
// sleep for a random time upto 1 seconds
Thread
.
sleep
(
generator
.
nextInt
(
1001
));
// buy airlinesTicket on MasterCard if i is even
// else buy it on the AX card
// hint use if else statement
// YOUR CODE HERE
if
(
i
%
2
==
0
)
{
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
airlinesTicket
);
}
else
{
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
airlinesTicket
);
}
}
//end for
// buying 10 cokes using different credit cards
for
(
int
i
=
1
;
i
<=
10
;
i
++
)
{
// sleep for a random time upto 1 seconds
Thread
.
sleep
(
generator
.
nextInt
(
1001
));
// this is use to be randomly select a credit card
int
randomSelectCard
=
generator
.
nextInt
(
2
);
// if randomSelectCard is 0 use the MasterCard
// if this is the case print out "randomSelectCard: MasterCard"
// if randomSelectCard is 1 use the American Express
// if this is the case print out "randomSelectCard: MasterCard"
// hint use if else statement
// YOUR CODE HERE
if
(
randomSelectCard
==
0
)
{
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
coke
);
}
else
{
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
makeCharge
(
coke
);
}
}
//end for
// john is running a transaction Report on his masterCard
// YOUR CODE HERE
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
transactionsReport
();
// john is running a transaction Report on his American Express
// YOUR CODE HERE
((
CreditCard
)
john
.
getCreditCards
().
get
(
0
)).
transactionsReport
();
// john is running displayInfo method
// YOUR CODE HERE
transactionsReport
().
displayInfo
();
}
//end main
}
//end class
COP2210_Project3-FALL2020/src/client/Person.java
COP2210_Project3-FALL2020/src/client/Person.java
package
client
;
import
java
.
util
.
ArrayList
;
import
payment
.
CreditCard
;
public
class
Person
{
//---------------------------------------------------------------------------
// Instance Variable
//---------------------------------------------------------------------------
// check the UML diagram to see which instance variable you need
private
String
firstName
;
private
String
lastName
;
private
String
streetAddress
;
private
String
suiteAddress
;
private
String
cityAddress
;
private
String
stateAddress
;
private
ArrayList
creditCards
;
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
public
Person
(
String
firstName
,
String
lastName
,
String
streetAddress
,
String
suiteAddress
,
String
cityAddress
,
String
stateAddress
)
{
// assign the input values to the instance variables
// YOUR CODE HERE
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
this
.
streetAddress
=
streetAddress
;
this
.
suiteAddress
=
suiteAddress
;
this
.
cityAddress
=
cityAddress
;
this
.
stateAddress
=
stateAddress
;
creditCards
=
new
ArrayList
<>
();
}
//end constructor
//—————————————————————————
// Setter and Getters
//—————————————————————————
public
String
getFirstName
()
{
return
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
String
getStreetAddress
()
{
return
streetAddress
;
}
public
void
setStreetAddress
(
String
streetAddress
)
{
this
.
streetAddress
=
streetAddress
;
}
public
String
getSuiteAddress
()
{
return
suiteAddress
;
}
public
void
setSuiteAddress
(
String
suiteAddress
)
{
this
.
suiteAddress
=
suiteAddress
;
}
// write the code for the needed setter and getters
// check the UML Diagram
// YOUR CODE HERE
public
String
getCityAddress
()
{
return
cityAddress
;
}
public
void
setCityAddress
(
String
cityAddress
)
{
this
.
cityAddress
=
cityAddress
;
}
public
String
getStateAddress
()
{
return
stateAddress
;
}
public
void
setStateAddress
(
String
stateAddress
)
{
this
.
stateAddress
=
stateAddress
;
}
public
ArrayList
getCreditCards
()
{
return
creditCards
;
}
public
void
setCreditCards
(
ArrayList
creditCards
)
{
this
.
creditCards
=
creditCards
;
}
//—————————————————————————
// Utility Methods
//—————————————————————————
public
void
displayInfo
(){
System
.
out
.
println
(
“”
);
System
.
out
.
println
(
“============================================================================”
);
System
.
out
.
println
(
“Display Information”
);
System
.
out
.
println
(
“============================================================================”
);
System
.
out
.
printf
(
“%-20s %s %s \n”
,
“Name:”
,
firstName
,
lastName
);
System
.
out
.
printf
(
“%-20s %-20s \n”
,
“Address:”
,
streetAddress
);
// write the code needed for the output to match the project doc output
// hint look at the code above to have the correct format
// YOUR CODE HERE
System
.
out
.
printf
(
“%-20s %-20s \n”
,
“Suite:”
,
suiteAddress
);
System
.
out
.
printf
(
“%-20s %-20s \n”
,
“City:”
,
cityAddress
);
System
.
out
.
printf
(
“%-20s %-20s \n”
,
“State:”
,
stateAddress
);
System
.
out
.
println
(
“——————”
);
System
.
out
.
println
(
“Credit Card Info”
);
System
.
out
.
println
(
“——————”
);
for
(
int
i
=
0
;
i
<
creditCards
.
size
();
i
++
){
String
cardName
=
((
CreditCard
)
creditCards
.
get
(
i
)).
getType
();
// get the creditCards credit limit
// hint look at the code for cardName above
double
creditLimit
=
masterCard
.
getCreditLimit
();
// YOUR CODE HERE
// get the creditCards current balance
// hint look at the code for cardName above
double
currentBalance
=
masterCard
.
getCurrentBalance
();
// YOUR CODE HERE
System
.
out
.
printf
(
"%-20s %-20s \n"
,
"CreditCard:"
,
cardName
);
System
.
out
.
printf
(
"%-20s %-20.2f \n"
,
"Credit Limit:"
,
creditLimit
);
System
.
out
.
printf
(
"%-20s %-20.2f \n"
,
"Current Balance:"
,
currentBalance
);
System
.
out
.
println
(
""
);
}
}
//----------------------------------------------------
}
}
//end class
COP2210_Project3-FALL2020/src/goods/Item.java
COP2210_Project3-FALL2020/src/goods/Item.java
package
goods
;
public
class
Item
{
private
String
category
;
private
String
name
;
private
double
price
;
public
Item
(
String
category
,
String
name
,
double
price
)
{
this
.
category
=
category
;
this
.
name
=
name
;
this
.
price
=
price
;
}
public
String
getCategory
()
{
return
category
;
}
public
String
getName
()
{
return
name
;
}
public
double
getPrice
()
{
return
price
;
}
public
void
setPrice
(
double
price
,
String
personal
)
{
this
.
price
=
price
;
}
public
void
displayInfo
(){
}
}
//end class
COP2210_Project3-FALL2020/src/payment/CreditCard.java
COP2210_Project3-FALL2020/src/payment/CreditCard.java
package
payment
;
import
client
.
Person
;
import
goods
.
Item
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Date
;
public
class
CreditCard
{
private
Person
cardHolder
;
private
String
type
;
private
String
cardNumber
;
private
double
creditLimit
;
private
double
currentBalance
;
private
double
nextPaymentAmount
;
private
ArrayList
<
Item
>
transactions
;
private
ArrayList
<
Date
>
transactionsTimeStamps
;
//—————————————————————————
// Constructor
//—————————————————————————
public
CreditCard
(
Person
cardHolder
,
String
type
,
double
creditLimit
)
{
// assign the input to the instance variables
// YOUR CODE HERE
this
.
cardHolder
=
cardHolder
;
this
.
type
=
type
;
this
.
creditLimit
=
creditLimit
;
=
new
ArrayList
<
Item
>
();
=
new
ArrayList
<
Date
>
();
}
//—————————————————————————
// Setters and Getters
//—————————————————————————
public
Person
getCardHolder
()
{
return
cardHolder
;
}
public
String
getType
()
{
return
type
;
}
public
String
getCardNumber
()
{
return
cardNumber
;
}
public
double
getCreditLimit
()
{
return
creditLimit
;
}
public
void
setCreditLimit
(
double
creditLimit
,
String
personal
)
{
this
.
creditLimit
=
creditLimit
;
}
public
double
getCurrentBalance
()
{
return
currentBalance
;
}
public
double
getNextPaymentAmount
()
{
return
nextPaymentAmount
;
}
//—————————————————————————
// Utility Methods
//—————————————————————————
public
void
makeCharge
(
Item
item
){
if
(
item
.
getPrice
()
<=
(
creditLimit
-
currentBalance
))
{
// YOUR CODE HERE){
transactions
.
add
(
item
);
Date
date
=
new
Date
();
transactionsTimeStamps
.
add
(
date
);
currentBalance
+=
item
.
getPrice
();
System
.
out
.
println
(
""
);
System
.
out
.
println
(
"Charging: "
+
item
.
getName
());
System
.
out
.
println
(
"Transaction completed successfully"
);
System
.
out
.
println
(
"Please remove your "
+
type
);
System
.
out
.
println
(
""
);
}
else
{
System
.
out
.
println
(
""
);
System
.
out
.
println
(
"Charging: "
+
item
.
getName
());
System
.
out
.
println
(
"Transaction was not successful"
);
System
.
out
.
println
(
"Credit Limit Issue"
);
System
.
out
.
println
(
"Please remove your "
+
type
);
System
.
out
.
println
(
""
);
}
}
//end makeCharge
public
void
transactionsReport
()
{
System
.
out
.
println
(
""
);
System
.
out
.
println
(
"============================================================================"
);
System
.
out
.
println
(
type
+
" Transaction Report"
);
System
.
out
.
println
(
"============================================================================"
);
System
.
out
.
printf
(
"%-20s $%-10.2f\n"
,
"Credit Limit:"
,
creditLimit
);
// you need to print out the Available Credit
// YOUR CODE HERE
System
.
out
.
printf
(
"%-20s $%-10.2f\n"
,
"Available Credit:"
,
creditLimit
-
currentBalance
);
System
.
out
.
printf
(
"%-20s $%-10.2f\n"
,
"Current Balance:"
,
currentBalance
);
System
.
out
.
println
(
"------------------------------------------------------------------------"
);
double
totalCharges
=
0.0
;
for
(
int
i
=
0
;
i
<
transactions
.
size
();
i
++
)
{
Item
item
=
transactions
.
get
(
i
);
Date
date
=
transactionsTimeStamps
.
get
(
i
);
System
.
out
.
printf
(
"%-20s %-10s $%-10.2f %-10s\n"
,
item
.
getName
(),
item
.
getCategory
(),
item
.
getPrice
(),
date
.
toString
());
totalCharges
+=
item
.
getPrice
();
}
//end for
System
.
out
.
println
(
"------------------------------------------------------------------------"
);
System
.
out
.
printf
(
"%-15s Total Charges: $%-10.2f\n"
,
""
,
totalCharges
);
}
//end transactionsReport
}
//end class