Hi all just joined the forum and am new to everything Java and programming in general
I was just looking for some help with an issue i have if anyone would be able to help?
I am trying to do a ticketing system, very basic, and need to add/multiply the cost of the ticket by the amount of the ticket requested.
e.g.
User offered different kinds of tickets
user types '1'
User offered to choose how many tickets they want.
user types '3'
What i need to be able to do is assign a value to the first input and the multiply it by the second.
I have put the code for my current project below
I am looking to do what i said above toward the end of the piece eg in the output of public static void ConfirmPurchase()
I need to assign the values 1,2,3 a dollar value to get a grand total in the System.out.println("Total Amount for "+tickets+": $");
Just struging on how to do it.
Thanks in advance for anything and for letting me be apart of your community.
package movie; // Import Utils import java.io.InputStream; import java.util.Scanner; /** * * @author Mark */ public class Movie { static Scanner scan = new Scanner(System.in); //static String name; static String [] list = {"1) Child","2) Adult","3) Senior"}; static int number; static int tickets; static int confirm; // Might put this in //public static void getName(){ // System.out.println("Please enter you name"); // name=scan.nextLine(); // System.out.println("Hello "+name); // getOption(); //} public static void getOption(){ System.out.println("Enter you option:"); //for(int i=0;i<list.length;i++){ // System.out.println(list[i]); //} number=scan.nextInt(); if (number > 3) { System.out.println("Please enter a valid number from 1 - 3"); getOption(); } if (number < 1) { System.out.println("Please enter a valid number from 1 - 3"); getOption(); } System.out.println("You selected "+list[number-1].substring(3, list[number-1].length())); getTickets(); } public static void getTickets(){ System.out.println("Please Enter total number of Tickets"); tickets=scan.nextInt(); System.out.println("Thank You, \nYou Have selected "+tickets+" ticket(s) for "+list[number-1].substring(3, list[number-1].length())); ConfirmPurchase(); } public static void ConfirmPurchase(){ //System.out.println("You are purchasing "+tickets+" at $ each \nPress 1 for confirmation of purchase:"); System.out.print("You are purchasing "+tickets+" "+list[number-1].substring(3, list[number-1].length())); System.out.println(" at TOTAL $$$"); System.out.println("CONFIRM PURCHASE:"); confirm=scan.nextInt(); if (confirm < 1){ getOption(); } if (confirm > 1){ getOption(); } else{ System.out.println("Total Amount for "+tickets+": $"); } } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here System.out.println(" @@@@@ Welcome To Zoos Victoria @@@@@"); System.out.println(" M A I N M E N U "); System.out.println(" Zoo Has the following ticketing options:"); System.out.println(" 1 = Child (4-5 yrs)"); System.out.println(" 2 = Adult (18+ yrs)"); System.out.println(" 3 = Senior (60+ yrs)"); System.out.println(""); getOption(); } }