How do I add strings together with different names

user3225968

I've already created the ticketAgent and ticketType class and I'm having a tough time trying to add the strings. I've tried using a wrapper class but not sure if that's even the right approach. I've pasted my code and then the prompt respectively. Thanks for the help. I'm a first time poster, so I hope I've followed the posting guidelines.

Prompt:

Write a program called TicketBooth that instantiates at 3 different ticket agents. The TicketBooth program should prompt the user for the ticket agent they wish to purchase a ticket from and then display the list of ticket types and prices that are available. The TicketBooth program should allow the user to make a selection for the ticket to purchase. After a ticket type is selected, the TicketBooth program should display the:

• total sales for that ticket agent • total number of tickets sold by the ticket agent • total number of tickets sold by all ticket agents

The TicketBooth program should continue to prompt the user to purchase tickets from one of the ticket agents until the user types quit.

 package Exercises;
    import java.util.Scanner;

    public class TicketBooth {

        private static Scanner input;

        public static void main(String[] args) {

            input = new Scanner(System.in);

                String ticketAgent = "sam", "nicole" , "alex";
                String ticketType = "one";
                int t = Integer.parseInt(ticketAgent);
                int s = Integer.parseInt(ticketType);
                int sum;

                System.out.println("Please select your ticket agent: ");
                ticketAgent = input.next();

                System.out.println("Please select your ticket type or press -1 to quit: ");
                ticketType = input.next();  

                sum = t +s;
                System.out.println("The total tickets that were sold were: " + sum);



        }
    }






package exercises;

public class TicketAgent {

private static int numOfTicksPerAgent;

    private String agentName;
    private int numSold = 0;
    private double totalSales = 0.0;

    public TicketAgent(String agent) {
        agentName = agent;

        numSold = 0;
        totalSales = 0.0;
        numOfTicksPerAgent += 1;
    }

    public void sellTicket(TicketType tt) {
        numSold++;
        totalSales = totalSales + tt.getticketPrice();
        numOfTicksPerAgent++;
    }

    public double gettotalSales() {
        return totalSales;
    }

    public double getnumSold() {
        return numSold;
    }

    public double getnumOfTicksPerAgent() {
        return numOfTicksPerAgent;

    }
}








package exercises;




public enum TicketType 
{
    CHILD (6.50),
    ADULT (9.50),
    SENIOR (6.50);

private double tikPrice;
TicketType(double price) 
{
    tikPrice = price;
}
public double getticketPrice()
{   
return tikPrice;

    }
}
JacksOnF1re

The problem is, that it seems that this is your homework and nobody wants to make your homeworks for you.

edit: I saw that you added your classes just now. All you have to do is to add the do while loop and instantiate your Agents in the right way. Where, exactly, is your problem? So we can help you better.

My first approach would be, to make it simple, to write a TicketAgent class and a TicketType class.

Write the TicketAgent in a way, you can put the name of the agent and the types into the constructor.

TicketAgent agentSam = new TicketAgent("Sam", new ExpensiveTicket());

Add setter and getter methods.

And the TicketType needs a float value for the price and maybe a String description or something like that.

After you are done with this, go back to your main class. Open a do while loop and set as the loop argument a boolean value for the user abort, which is false at the beginning and changes if the user types in the quit command.

Before the loop, instantiate the Agents with the tickets.

Display names and prices. Display tickets. Count together. Ask for abort.

Hope this helps a little. And sorry for my english, it is not my mother-tongue.

    additional:



private boolean userWantsToQuit = false;
private List<TicketAgent> avaibleAgents = new ArrayList<TicketAgent>();
private List<TicketAgent> usedAgents= new ArrayList<TicketAgent>();
private List<TickeType> boughtTickets= new ArrayList<TicketType>();

main(...){

   agents.add(new TicketAgent("Sam"));
   agents.add(new TicketAgent("wise"));
   agents.add(new TicketAgent("gamgee"));

   do{

   usedAgents.add(askUserForAgent()); //extra static method
   boughtTickets.add(askUserForType(agent)); //extra static method
   userWantsToQuit = askUserToQuit();//extra static method
   }while(!userWantsToQuit);

   displayAgentSummary(usedAgents);
   displayTicketSummary(boughtTickets);
}

[...]

public static displayAgentSummary(List<TicketAgent> agents)
{
    for(TicketAgent agent : agents)
    {
       System.out.println("Served by: " + agent.getName());
    }
}

public static displayTicketSummary(List<TicketType> tickets)
{
    float totalPrice = 0;
    for(TicketType ticket : tickets)
    {
       totalPrice =+ ticket.getPrice();
       System.out.println("You bought a " + ticket.getName() + " for " + ticket.getPrice()";
    }
    System.out.println("You bought tickets in total for " + totalPrice + " dollar".
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I insert a list of sequentially numbered (or different) strings concatenated together in emacs?

From Dev

how do i add this list together? I keep on getting an error

From Dev

How do I add columns together after Google Script runs?

From Dev

How do I add 2 arrays together and get the average of the sum?

From Dev

How do I add two variables together that have decimal values?

From Dev

How do I compare two domain names in URL strings?

From Dev

How do I create a named set of strings in nftables (for interface names)?

From Dev

How to add two scanner strings together? in 'if' statement

From Dev

How do I shim executables with the same names in different directories?

From Dev

How do I call templates with same names at different directories in Django?

From Dev

How do I save ArrayLists with different names in a while loop?

From Dev

How can I add two date strings in the format HH:MM:SS together?

From Dev

How do I add a prefix to several variable names using dplyr?

From Dev

How do I append two attributed strings with different fonts?

From Dev

How do I retrieve multiple items of data from Firebase and merge these strings together?

From Dev

Why can't I add these two strings together?

From Dev

How do I add alternating strings to filenames and renumber them pairwise?

From Dev

Swift How do I convert document file URLs to strings so I can display the file names in tableview

From Dev

Gulp - How do i chain together tasks or streams that use different src?

From Dev

How can i add numbers together that was extracted

From Java

How do I find the duplicate companies and merge them into one and add together their weights

From Dev

How do I add two arrays together and collect ids where one or both can be null

From Dev

In PHP, how do I add values together from 2 arrays where specific keys match?

From Dev

How do I count the number of files in all subdirectories and add the counts together

From Dev

How do I add another column to a SQL table based on rows grouped together

From Dev

How do I add different button clicks in one event method?

From Dev

How do I add a queue to one thread from a different thread?

From Dev

How do i add different background colors to multiple figcaptions?

From Dev

How do I add multiple button that go to different scenes please?

Related Related

  1. 1

    How do I insert a list of sequentially numbered (or different) strings concatenated together in emacs?

  2. 2

    how do i add this list together? I keep on getting an error

  3. 3

    How do I add columns together after Google Script runs?

  4. 4

    How do I add 2 arrays together and get the average of the sum?

  5. 5

    How do I add two variables together that have decimal values?

  6. 6

    How do I compare two domain names in URL strings?

  7. 7

    How do I create a named set of strings in nftables (for interface names)?

  8. 8

    How to add two scanner strings together? in 'if' statement

  9. 9

    How do I shim executables with the same names in different directories?

  10. 10

    How do I call templates with same names at different directories in Django?

  11. 11

    How do I save ArrayLists with different names in a while loop?

  12. 12

    How can I add two date strings in the format HH:MM:SS together?

  13. 13

    How do I add a prefix to several variable names using dplyr?

  14. 14

    How do I append two attributed strings with different fonts?

  15. 15

    How do I retrieve multiple items of data from Firebase and merge these strings together?

  16. 16

    Why can't I add these two strings together?

  17. 17

    How do I add alternating strings to filenames and renumber them pairwise?

  18. 18

    Swift How do I convert document file URLs to strings so I can display the file names in tableview

  19. 19

    Gulp - How do i chain together tasks or streams that use different src?

  20. 20

    How can i add numbers together that was extracted

  21. 21

    How do I find the duplicate companies and merge them into one and add together their weights

  22. 22

    How do I add two arrays together and collect ids where one or both can be null

  23. 23

    In PHP, how do I add values together from 2 arrays where specific keys match?

  24. 24

    How do I count the number of files in all subdirectories and add the counts together

  25. 25

    How do I add another column to a SQL table based on rows grouped together

  26. 26

    How do I add different button clicks in one event method?

  27. 27

    How do I add a queue to one thread from a different thread?

  28. 28

    How do i add different background colors to multiple figcaptions?

  29. 29

    How do I add multiple button that go to different scenes please?

HotTag

Archive