Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java

ID: 3590121 • Letter: P

Question

Programming Project 3

See Dropbox for due date

Project Outcomes:

Develop a Java program that uses:

Exception handling

File Processing(text)

Regular Expressions

Prep Readings:

Absolute Java, chapters 1 - 9 and Regular Expression in Java

Project Overview:

Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.   

Project Requirements

Develop a text based menu driven program that calculates cell phone package costs.  You may see Java code for a text based menu at the bottom of this description.

The menu might look something like this:

1. Purchase Cell Plan Package

2. Purchase Cell Phone

3. Purchase Data Plan

4. Search for Transaction by ID

5. Exit

Choosing 1, 2, or 3 should still offer the user the opportunity to buy the other two. For instance, if the user chooses 2 (purchase cell phone) the system will then offer them a cell phone plan and a data plan.

The Cell phone provider has the following monthly talk packages:

1000 minutes, $29.99

5000 minutes, $49.99

unlimited,   $69.99

The provider also sells cells phones:

Model 100, $39.95

Model 200, $49.95

Model 300, $59.95

The following monthly data options are available:

3 GB, $19.99

6 GB, $49.99

Unlimited, $69.99

The following phone shipping cost and information will apply:

zip codes within 325XX - free shipping

Continental United States - 5.00 shipping cost.

zip codes for Alaska (995xx - 999xx) or Hawaii (967xx - 968xx) - 10.00 shipping fee.

Regular Expressions

Zip code input should be ONLY 5 DIGITS.

Phone numbers must be in the form (xxx) xxx-xxxx.

Must Use the Regular Expressions to test the zip code and phone number. Create a User Defined Exception that will require the user to enter the zipcode or phone in correct format before continuing. To learn about Regular Expression in Java try http://www.youtube.com/watch?v=s_PfopWcMwI.  

Customer Information must include: Customer's name, address (street, city, state, zip), phone number,customerID number.

The cell phone company is concerned with the volatile cell phone market so they want the application to be flexible.

The application will read all the talk packages, cell phones and data options from a file. This includes talk package max minutes and cost, cell phone model and cost, and data options and cost. Please name the file“packages.txt” and have the program read it in automatically at startup.

The file format is left up to the developer however; it must be easily readable and maintainable by a non-programmer.

The number of talk packages (3), cell phone models (3) and options (3) are constant.  

Write all completed transaction data to a text file named appropriately. Again file format is up the developer but should be readable. The data should include customerid number, total startup cost and total reoccurring monthly cost.

A menu option to search the Transaction file for a transaction based on customerid number. Assume only one transaction per customer ID.

The remaining design details are left up to the developer, including how to structure the application, how many classes to develop and the interrelationship of those classes. Use the techniques you've learned in this course, including good object oriented design.

Create two UML Class Diagram for this project.

The class diagrams should be created in multiple iterations.

The first series of iterations should be done before you code and should provide a design that the code follows. (Design Version)

The second series of iterations should be completed after the code is complete and should reflex the EXACT class structure of you final program. (Final Version)

The class diagrams should include

Access specifier (- or +).

All instance fields with type.

All methods with return type and parameter types.

Associations, Generalization (Inheritance) and Aggregation and Multiplicity

Stereotyping – Interface or Abstract Classes.

Design Version - completed prior to coding the project to assist with coding.

Final Version - completed after the coding that accurately represents the final version of the code, generally used for maintenance purposes.

No need to include the class with main method in the UML diagrams. Refer to the UML Distilled pdf on the content page as a reference for creating class diagrams

Submission Requirements - Follow the submission requirements posted on elearning. MAKE SURE YOU TURN IN A COPY OF THE TEXT FILE THAT POPULATES THE CELL PHONE PACKAGE, PHONE AND DATA PLAN DATA.

Simple Text-based Menu Code

import java.util.Scanner;

public class SwitchOperatedTextMenu {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

// print menu

for (int i = 1; i <= 5; i++)

System.out.println(i + ". Menu item #" + i);

System.out.println("0. Quit");

// handle user commands

boolean quit = false;

int menuItem;

do {

System.out.print("Choose menu item: ");

menuItem = in.nextInt();

switch (menuItem) {

case 1:

System.out.println("Item #1");

// do something...

break;

case 2:

System.out.println("Item #2");

// do something...

break;

case 3:

System.out.println("Item #3");

// do something...

break;

case 4:

System.out.println("Item #4");

// do something...

break;

case 5:

System.out.println("Item #5");

// do something...

break;

case 0:

quit = true;

break;

default:

System.out.println("Invalid choice.");

}

} while (!quit);

System.out.println("Bye-bye!");

}

Explanation / Answer

/****** This is what I did here *******/

// txt files containing data are here as below

1. menu.txt (containg menu details)

2. cellPhone.txt

3. plan.txt

4. dataPlan.txt

package coreConcepts;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

/**

* @author ABC

* I think this is what you looking here we use file reading, Exception Handling

* and oops concepts.

*

*/

public class Exercise {

public static void main(String[] args) throws FileNotFoundException {

SwitchOperatedTextMenu obj = new SwitchOperatedTextMenu();

obj.menu(obj.menuFile);

obj.setOption();

}

}

class SwitchOperatedTextMenu {

String menuFile = "menu.txt";

public void setOption() {

boolean quit = false;

int option;

String cell = "cellPhone.txt", plan = "plan.txt", dataPlan = "dataPlan.txt";

Scanner sc = new Scanner(System.in);

do {

System.out.print("Choose menu item: ");

option = sc.nextInt();

switch (option) {

case 1:

menu(plan);

System.out.println("==========================");

// do something...

break;

case 2:

menu(cell);

System.out.println("==========================");

// do something...

break;

case 3:

menu(dataPlan);

System.out.println("==========================");

// do something...

break;

case 4:

System.out.println("No transaction is available");

System.out.println("==========================");

// do something...

break;

case 0:

quit = true;

break;

default:

System.out.println("Invalid choice.");

System.out.println("==========================");

}

} while (!quit);

}

public void menu(String fileName) {

File file =new File(fileName);

try {

Scanner sc = new Scanner(file);

while (sc.hasNextLine()) {

System.out.println(sc.nextLine());

}

sc.close();

}

catch (FileNotFoundException e) {

e.printStackTrace();

}

}

}

/*********** These classes for extending this into miniProject ************/

//class DataPlans {

// private String data;

// private float cost;

//

// public DataPlans() {

// // TODO Auto-generated constructor stub

// }

// public DataPlans(int data, float cost) {

// this.data = data;

// this.cost = cost;

// }

// @Override

// public String toString() {

// String s = "" + data + " GB, $" + cost;

// return s;

// }

//}

//

//class Plans {

// private String min;

// private float cost;

//

// public Plans() {

// // TODO Auto-generated constructor stub

// }

// public Plans(int min, float cost) {

// this.min = min;

// this.cost = cost;

// }

// @Override

// public String toString() {

// String s = "" + min + " minutes, $" + cost;

// return s;

// }

//}

//

//class CellPhone {

// private String model;

// private float cost;

//

// public CellPhone() {

// // TODO Auto-generated constructor stub

// }

// public CellPhone(String model, float cost) {

// this.model = model;

// this.cost = cost;

// }

// @Override

// public String toString() {

// String s = "Model" + model + ", $" + cost;

// return s;

// }

//}