sslobecheski - 1 year ago 130
Java Question

# Java Ticket Price Calculator if statement

Okay, so I would really appreciate this community's advice. I recently received my first programming project and I'm way in over my head. I have zero experience with programming, but I'm going to give as much information as I can.

The project is a basic ticket pricing program that runs in the command prompt using java. We have to introduce the program with the name of the creator, ask for number of adult tickets wanted (\$10 a piece), the number of student tickets (\$5 a piece), use a switch statement or if statement to allow the user to select a discount (free shipping, 10% off, or best option), and finally calculate the total depending on the users choices.

The problem is that I'm just stuck on this whole switch statement thing and calculating the total. I'll include the code I have so far and I would really appreciate any help you can give.

``````import java.util.Scanner;

public class Project1
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
double student; //number of student/senior tickets
int option;
double aamount = 10.00;
double samount = 5.00;
double purchasePrice = adult * aamount + student * samount;
double total;

final double DISCOUNT = 0.1;
final double SHIPPING = 5.00;

System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("******** WELCOME TO THE TICKET PRICE CALCULATOR ********");
System.out.println("            created by Shane Slobecheski");
System.out.println();
System.out.println("               Press enter to continue");
kb.nextLine();
System.out.println();
System.out.print("How many adult tickets do you wish to purchase? (ages 18-64): ");
System.out.println();
System.out.print("How many student/senior tickets do you wish to purchase? (ages 0-17 or 65+): ");
student = kb.nextInt();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("-----------------");
System.out.println("1. Free Shipping");
System.out.println("2. 10.0% discount");
System.out.println("3. Apply whichever discount will save me the most money");
System.out.println();
option = kb.nextInt();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println ("Purchase price \$"+ purchasePrice);

purchasePrice = adult * aamount + student * samount;

}
}//end program
``````

not forget their first initialize variables

``````double adult=0;
double student=0;
int option=0;
double total=0;
``````

and the switch structure has the following syntax, where p is the variable to assess its serious case option

``````   switch(op)
{
case 1:operations; break;
case 2: operations;break;
default: System.out.println("option no valid");
}
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download