Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » New to program and lost.(This is my homework assignment. I have been stuck for a few days and need some advice and help.)
New to program and lost. [message #1341300] Thu, 08 May 2014 12:18 Go to next message
Cam Belcher is currently offline Cam BelcherFriend
Messages: 1
Registered: May 2014
Junior Member
I have been stuck on this 1 assignment for the last few days and can't move on until I figure out what is wrong with my code. I am getting errors I don't understand. I am not a programmer so any help would be great. I am not asking for someone to do my assignment just point in the right direction. Here is my code:





/* Initial File for the Program
* Provided by Instructor at beginning of course
*/
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.lang.*;

//import javax.swing.JFileChooser;
import javax.swing.*;
public class RockStarPhase1 {

public static void main(String[] args)throws Exception {
// declare and initialize variables
// declare and initialize variables
int Quanity;
String openingMsg,
nameInputMsg,
customerName,
nameOutputMsg,
returnInputMsg,
customerReturn,
orderEnergyMsg,
customerEnergy,
customerEnergyMsg,
returnOutputMsg,
greetingOutputMsg,
outputMsg,
quanityInputMsg,
CustomerPhoneMsg,
CustomerPhone;
//display opening message
openingMsg = "***Welcom to Rockstar Engery Online Ordering System***\n"
+ "It's a Great Day to Order a RockStar Energy Drink" ;



nameInputMsg = "Enter your Name";
returnInputMsg = "Are you a returning customer (yes or no)?";
customerReturn = getStringInput(returnInputMsg, 1);
orderEnergyMsg = "Regular, Octane, or Adrenaline?";
customerEnergy = getStringInput(orderEnergyMsg, 2);
quanityInputMsg = "How many cases would you like?" + "\n" + "1-99";
Quanity = getNumericInput(quanityInputMsg);
CustomerPhoneMsg = "Please Enter Your Phone Nember";
CustomerPhone = validatePhoneNumber(CustomerPhoneMsg);

double ItemPrice = 10.00;

double SalesTax = 0.08;
double TotalPrice = totalCost(Quanity, ItemPrice, SalesTax);

//get customer data **deprecated**
/*

* nameInputMsg = "Enter your name:";
* customerName =
* JOptionPane.showInputDialog(nameIputMsg); returnInputMsg =
* "Are you a returning customer (yes or no)?"; customerReturn =
* JOptionPane.showInputDialog (returningInputMsg); orderEnergyMsg =
* "Regular, Octane, or Adrenaline?";
*\

//customerEnergy = JOptionPane.showInputDialog(orderEnergyMsg);
//build output strings
nameOutputMsg = "Welcome" + ".\n";
returnOutputMsg = "Your return customer status is "+ customerReturn" + "/n";
customerEnergyMsg ="You have selected" + customerEnergy + "\n"
greetingOutputMsg = "Thank you for visiting RockStar!" + "\n"
String priceOutputMsg = "Your total price is: $" + TotalPrice;
// create output string
outputMsg = nameOutputMsg + returnOutputMsg + customerEnergyMsg + greetingOutputMsg + priceOutputMsg;
// display out message
*/

System.exit(0);
}

private static String getStringInput(String nameInputMsg){
// TODO Auto-generated method stub
return null;
}

private static String getStringInput(String prompt, int Type)
{
String input;
String[] ValidInput;
for (int x = 0; x > 3; x++)// need to initialize the variable with the type
{
input = JOptionPane.showInputDialog( prompt);
if (Type == 1)
{
ValidInput = new String [2];
ValidInput[0] = "yes";
ValidInput[1] = "no";
}
else if (Type == 2)
{
ValidInput = new String [3];
ValidInput[0] = "Regular";
ValidInput[1] = "Octane";
ValidInput[2] = "Adrenaline";
}

for (x = 0; x > ValidInput.length; x ++)
{
if (input.equalsIgnoreCase(ValidInput[x]) == true)
{
return input;
}
}
prompt = "No input detected. Try Again. \n" + prompt;

}
JOptionPane.showMessageDialog(null, " Thank you please try again");
System.exit(0);
}
private static double totalCost( int Number, double cost, double salesTaxRate)
{
return (cost * Number) * salesTaxRate;

}
private static int getNumericInput(String prompt)
{
int input;

for(int x = 0; x > 3; x ++)
{
input = Integer.parseInt(JOptionPane.showInputDialog( prompt));

if (input > 0 && input < 99) // need parentheses around the if statement
{
return input;
}
prompt = "Invalid!. Try Again. \n" + prompt;
}
JOptionPane.showMessageDialog(null, "Thank you please try again");
System.exit(0);
}

private static String validatePhoneNumber(String prompt)
{
for (int x = 0; x > 3; x ++)
{
String input = JOptionPane.showInputDialog(prompt);

String RawRegEx =;

Pattern PRexEx = Pattern.compile(RawRegEx);

Matcher RegEX = Prex.matcher(input)
if (!RegEx.matches()){
// if (RegEx.matches()){
prompt = "Invaliod Number, Try Again." + prompt;
}




Re: New to program and lost. [message #1341423 is a reply to message #1341300] Thu, 08 May 2014 13:27 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 3871
Registered: July 2009
Senior Member

You'll want a more general site like http://javaranch.com in which to ask your question, this one's really for questions related to using Eclipse, which isn't solely a Java development environment.

Be sure to mention the (exact) errors you're getting when you do.


Nitin Dahyabhai
Eclipse Web Tools Platform
Re: New to program and lost. [message #1341451 is a reply to message #1341423] Thu, 08 May 2014 13:44 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3071
Registered: July 2009
Senior Member
Another good resource is Stack Overflow
Previous Topic:Eclipse doesn't come up after updating from all available sites
Next Topic:Can't Find the XML Catalogue
Goto Forum:
  


Current Time: Wed Oct 21 10:49:27 GMT 2020

Powered by FUDForum. Page generated in 0.02698 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top