I need help in two areas:
Both are at the bottom of my program where a client has two choice to make,
1. When the client enter "Y" it takes him to the begin of the program. I would like to know what this is done ie maybe at the part where it ask you do you want to enter a new product.
2. If the client enters the wrong value or then "Y" or "N" then they are prompted with "error - Please try again" for some reason my no matter what I enter I get the prompted.
Any help or tips would be helpful and great.
here is my code so far
Thanks
sandy
Both are at the bottom of my program where a client has two choice to make,
1. When the client enter "Y" it takes him to the begin of the program. I would like to know what this is done ie maybe at the part where it ask you do you want to enter a new product.
2. If the client enters the wrong value or then "Y" or "N" then they are prompted with "error - Please try again" for some reason my no matter what I enter I get the prompted.
Any help or tips would be helpful and great.
here is my code so far
Code:
package dw;
//import util for Scanner
import java.util.*;
public class ProjectClass3 {
/**
* @param args
*/
public static void main(String[] args) {
// define some variables to hold the data from the scanner
String answer_flag; // scanner yes or no
String product_flag; // scanner for product
double price_flag; // scanner for price
double Tax; // for taxes takes price_flag and convert it to Price
String color_flag; // scannerfor color
int weight_flag; // scanner for weight
String product2_flag; // scanner yes or no
// Prompt the user Do you want to create a new product yes or no
// make a scanner for the response
Scanner kbd_answer = new Scanner(System.in);
// add loop info here for result Y or N
System.out.print("\nPlease press Enter afer each response");
System.out.print("\nDo you want to create a Product? (Y/N): ");
answer_flag = kbd_answer.next();
while (answer_flag.equalsIgnoreCase("N")){
System.out.println("Thank You");
System.exit(1);
}// close the response loop
/**
* @param args
*/
// Make a scanner for product
Scanner kbd_product = new Scanner(System.in);
/**
* @param args
*/
System.out.print("\nEnter the Product Name: ");
product_flag = kbd_product.next();
// Make a scanner for price
Scanner kbd2 = new Scanner(System.in);
System.out.print("\nEnter the Price: ");
price_flag = kbd2.nextDouble();
Tax = price_flag; //new variable
Tax = ((int) Tax * 0.08); // taxes on product
while (price_flag >= 10000) {
System.out.println("Please enter a price below 10000:");
price_flag = kbd2.nextDouble(); // if wrong goes back until right
}//close the Price loop
/**
* @param args
*/
// make a Scanner object for weight
Scanner kbd = new Scanner(System.in);
// prompt the user for data and start adding it to the object
System.out.print("\nEnter the Weight: ");
weight_flag = kbd.nextInt();
while (weight_flag >= 150) {
System.out.print("Incorrect Weight - try again"); // if weight is greater then return you to input
weight_flag = kbd.nextInt();
}
/**
* @param args
*/
// Prompt the user Do you want to create a new product yes or no
// make a scanner for the response
Scanner kbd_answer2 = new Scanner(System.in);
System.out.print("\nPlease press Enter afer each response");
System.out.print("\nDo you want to create a Product? (Y/N): ");//Y on N response
product2_flag = kbd_answer2.next();
if (product2_flag.equalsIgnoreCase("Y"));
if (product2_flag.equalsIgnoreCase("N"))
System.out.println("Thank You");
while (product2_flag != "y" || product2_flag != "Y" || product2_flag != "n" || product2_flag != "N")
{System.out.println("Error - Please try again");
product2_flag = kbd_answer2.next();
}
System.out.print("Product: ");
System.out.println(product_flag);
System.out.print("Price: $ ");
System.out.println(price_flag);
System.out.print("Tax: ");
System.out.println(Tax);
}// close the public static void
}// close the public class
sandy
Comment