1 Replies - 708 Views - Last Post: 03 May 2014 - 04:55 PM Rate Topic: -----

#1 Tyler Who?   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-May 14

Help with my project

Posted 03 May 2014 - 04:34 PM

I need help on my code mostly with my Array and loop for my Array.

My program is this:For programming project 2 you will modify your program to use methods and arrays. You will be breaking your program up into methods. You should have 4 methods within your program: one for entering customer information, one for price lookup, one for the total bill, and then one to hold your main menu information.

Modify your program to do the following:

From Previous programming project (If the sales associate selects option 1, the program should allow the sales associate to input their name, address, and e-mail address. Your program should then display this customer information to the screen with a message that the customer has been added to the customer list.) Modify your option 1 by adding the new customer information to an external file.


Create a method for customer information. Your program should call a customer information method from the main program when the sales associate selects option 1. The program should allow the sales associate to input their name, address and e-mail address. Once the sales associate has entered this information the data entered should be written to an external file. (Hint* your method should contain your code that you created for your previous programming projects to add the customer information to an external file.)

Modify your option 3, total bill so that the customer information is retrieved from the external file. Also, modify your program to retrieve the price of the product.

Create a method for price lookup. Your program should call a price lookup method that returns the cost of the item to the screen.(Hint*Again your method should contain your code that you created from the previous programming projects) The sales associate should now be allowed to enter multiple products to be displayed on the total bill.
Modify your program to include a loop that will ask the sales associate the products the customer is purchasing and the quantity. This loop should continue until the sales associate decides to not enter any more products.
Store this information in an array. Display the total bill to your sales associate with all of the products entered. (You can use an array or an arrayList) Hint*You will need to loop through the array or arrayList to display the products, quantity and price in the totalBill.
Modify your program to include a loop so that the user is continually asked the main menu until they have selected option number 4 to Quit the program.
The user should be continually asked to go to the main menu until they have selected option number 4 to quit the program.

Your option menu will now look like this:
1. Enter customer information
2. Price Lookup
3. Display Total Bill
4. Quit

Your total bill should still look like this:


John Doe
2206 Anywhere Street
Anywhere, TX. 88888
[email protected]

Product Purchased Quantity Total Cost

Shoes 2 $100.00
Shorts 1 $75.00

Tax (@8%): $14.00
Total Cost: $189.00

Now here's my code:

import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Morah_PP2 {


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

DecimalFormat df= new DecimalFormat ("###.00");
double taxrate= .08;

Map<String,Integer> Priceproduct= new HashMap<String,Integer>();
Priceproduct.put("shoes", 50);
Priceproduct.put("shirts", 30);
Priceproduct.put("shorts", 75);
Priceproduct.put("caps", 15);
Priceproduct.put("jackets", 100);

Scanner keyboard=new Scanner(System.in);
String answer=keyboard.nextLine();

String input;
char repeat;

int option = 0;

do
{


System.out.print("Main Menu ");
System.out.println("\n 1. Enter customer information");
System.out.println("\n 2. Price Lookup");
System.out.println("\n 3. Display Total Bill");
System.out.println("\n 4. Quit");

switch (option) {
case 1: System.out.print(" Enter the customer's name: ");
String name1=keyboard.next();

System.out.print("\n Enter the customer's address: ");
String Address=keyboard.next();

System.out.print(" Enter the customer's E-mail: ");
String Email=keyboard.next();

System.out.print("Customer has been added to the list.");
PrintWriter outputFile = new PrintWriter("CustomerData.txt");
outputFile.println(name1);
outputFile.println(Address);
outputFile.println(Email);
outputFile.close();


break;


case 2:System.out.print("Enter the product");
System.out.println(df.format (Priceproduct.get(("product+"))));
break;

case 3:System.out.print("Enter the customer's name: ");
String name2=keyboard.next();

do
{
System.out.print( "\n Enter the product");
String product1=keyboard.nextLine();

System.out.print("\n Enter the quantity");
int quantity=keyboard.nextInt();

input=keyboard.nextLine();
repeat=input.charAt(0);
System.out.print("\n Would you like to add another product? [Y/N]");
}while(repeat=='y');
ArrayList<String> productList = new ArrayList<String>();
String product1=keyboard.next();
productList.add((String) (String) product1);
for(int i = 0; i ; ++i) {

}
int quantity=keyboard.nextInt();

int cost= (Priceproduct.get(product1)*quantity);
double tax= cost*taxrate;
System.out.println("\n tax=" +df.format(cost*taxrate));

double TotalBill= cost+tax;
System.out.println("Total="+df.format(cost + tax));

break;
case 4:System.out.println("Exiting");
}







}while( answer.toLowerCase().equals( "y" ) );


}



}


Any help would be good.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with my project

#2 x68zeppelin80x   User is offline

  • D.I.C Addict

Reputation: 130
  • View blog
  • Posts: 576
  • Joined: 07-March 09

Re: Help with my project

Posted 03 May 2014 - 04:55 PM

Just a tip, feel free to use methods, They will help organize your code better and allow you to reuse code blocks.

Throw the print menu logic into a method:

public static void printMenu() {
    System.out.print("Main Menu ");
    System.out.println("\n 1. Enter customer information");
    System.out.println("\n 2. Price Lookup");
    System.out.println("\n 3. Display Total Bill");
    System.out.println("\n 4. Quit");
}


Then call the method using printMenu().
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1