Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Home assignment

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Home assignment

    Hi,

    I am a very beginner in java coding and would need help on getting the codes for these exercises. Why I'm asking is because time is running out and deadline coming up too fast.

    1. Small mathematics application. Write a program that asks the user mathematical questions (at
    least 5 questions) such as “What is 5*21?”. The user should be able to stop the program by writing 0
    or by answering correctly and thus getting the next question. (Hint you can use for example .equals()
    if you want to compare Strings).

    2. Ticket vending application. Create a vending system for individual train ticket system. We assume
    that there are only four possible stations called: Helsinki, Pasila, Tampere and Turku. The tracks of
    trains are built in a way that all the trains need to go from Helsinki to Pasila. From Pasila they can go
    either to Turku or Tampere. We assume that you have to travel from Tampere to Turku via Pasila.
    Our system only sells one way tickets, which have fixed prices for the different possible journeys. All
    the combinations of one departing and one destination stations are possible.
    Build an application which asks the user his name and then asks the journey he wants to undertake.
    Then print to the screen the journey and the cost of the ticket (hint: you can invent the price table
    for the different tickets, but they should be somehow logical, or current, prices).

    3. Restaurant reservation management system. The restaurant has 5 tables and 18 possible seats
    (tables of 6, 4, 4, 2, 2). We assume that one table can only be reserved once for one evening and
    that the seating cannot be changed.
    Make a management system of a restaurant clerk, which stores the availability of tables. The clerk
    taking the reservations is the user. In the beginning of the evening, there are no reservations.
    Reservations come one at a time. Reservations can be for any number of people, but the seating
    cannot be changed.
    Reservations can only be accepted if there is room for them and otherwise the clerk should be
    notified that there is room.
    To minimize the empty tables, system should place the customers to the smallest possible table, if
    there is room. For example a reservation of 3 must be placed to the table of 4, if there is still room.
    Otherwise, it will need to be placed on the table of 6. If both are full, the reservation cannot be
    accepted and the user needs to be notified. Store the reservation information to the system and
    print the reservation situation out, if clerk wants to see the reservations, if all the tables are full or if
    the clerk wants to stop accepting new reservations.


  2. #2
    Member
    Join Date
    Sep 2012
    Location
    The Netherlands
    Posts
    84
    My Mood
    Inspired
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Re: Home assignment

    Show us your code, and ask questions about it.
    Then we can help you solving your question.

    Now it looks like you want us to do your homework....
    And that is not where this forum is for.
    On the other hand, we do help people who are stuck with there code. :-)

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Home assignment

    /**

    *
    * This is a train ticket vending program for a train system with 4 stations.
    * The system only sells one way tickets.
    */
    import java.util.*;
    public class TicketApp
    {
    public static int HP = 3, PTa = 31, PTu = 31; //Defining the variables
    public static String from, to, name;

    public static void main (String[] args)
    {
    Scanner reader = new Scanner(System.in);
    System.out.println("Please enter your name:"); //System output
    name = reader.nextLine(); //The user's name

    System.out.println("From where are you travelling:"); //Sytem output
    System.out.println("Helsinki, Pasila, Tampere or Turku?");
    from = reader.nextLine(); //The city of departure

    while (! from.equals("Helsinki") && ! from.equals("Pasila") && ! from.equals("Tampere") && ! from.equals("Turku")) //Checking the validity of the input
    {
    System.out.println("Invalid location. Please choose between Helsinki, Pasila, Tampere and Turku");
    from = reader.nextLine();
    }

    System.out.println("What is your destination:"); //System output
    System.out.println("Helsinki, Pasila, Tampere or Turku?");
    to = reader.nextLine(); //The destination

    while (! to.equals("Helsinki") && ! to.equals("Pasila") && ! to.equals("Tampere") && ! to.equals("Turku")) //Checking the validity of the input
    {
    System.out.println("Please enter a valid destination city (Helsinki/Pasila/Tampere/Turku)");
    to = reader.nextLine();
    }

    if (from.equals(to)) //Making sure that the city of departure and the destination are not the same
    {
    System.out.println("The city of departure and the destination are the same. You do not need a ticket.");
    }

    //This is the switch for the different routes
    switch(from+to)
    {
    case "HelsinkiPasila": HP();
    break;
    case "PasilaHelsinki": HP();
    break;
    case "HelsinkiTampere": HTa();
    break;
    case "TampereHelsinki": HTa();
    break;
    case "HelsinkiTurku": HTu();
    break;
    case "TurkuHelsinki": HTu();
    break;
    case "PasilaTampere": PTa();
    break;
    case "TamperePasila": PTa();
    break;
    case "PasilaTurku": PTu();
    break;
    case "TurkuPasila": PTu();
    break;
    case "TampereTurku": TaTu();
    break;
    case "TurkuTampere": TaTu();
    break;
    }
    }

    public static String HP() //Outcome if the user travels from Helsinki to Pasila
    {
    System.out.println("Here is your journey:\nFrom: "+from+"\nTo: "+to+"\nPrice: "+HP+" euros");
    return "0";
    }
    public static String HTa() //Outcome if the user travels from Helsinki to Tampere, and so on
    {
    System.out.println("Here is your journey:\nFrom: "+from+"\nTo: "+to+"\nPrice: "+(HP+PTa)+" euros");
    return "0";
    }
    public static String HTu()
    {
    System.out.println("Here is your journey:\nFrom: "+from+"\nTo: "+to+"\nPrice: "+(HP+PTu)+" euros");
    return "0";
    }
    public static String PTa()
    {
    System.out.println("Here is your journey:\nFrom: "+from+"\nTo: "+to+"\nPrice: "+PTa+" euros");
    return "0";
    }
    public static String PTu()
    {
    System.out.println("Here is your journey:\nFrom: "+from+"\nTo: "+to+"\nPrice: "+PTu+" euros");
    return "0";
    }
    public static String TaTu()
    {
    System.out.println("Here is your journey:\nFrom: "+from+"\nTo: "+to+"\nPrice: "+(PTa+PTu)+" euros");
    return "0";
    }
    }

    I cant get the switch working; it says that: incompatible type; found java.lang.String but expected int. What should i do?

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Home assignment

    I cant get the switch working; it says that: incompatible type; found java.lang.String but expected int. What should i do?
    Switch statements do not work with strings in all versions. You are using an older version where switch only supports int. Upgrade or use int instead of String.

Similar Threads

  1. JDK + Netbeans for XP Home
    By djl1990 in forum Java IDEs
    Replies: 1
    Last Post: March 5th, 2012, 01:48 PM
  2. Assembling a Home System....
    By kclumsyxasian in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 7th, 2011, 08:44 PM
  3. A place to call home
    By Tsarin in forum Member Introductions
    Replies: 1
    Last Post: October 14th, 2011, 07:56 AM
  4. home work ..
    By shane1987 in forum Collections and Generics
    Replies: 8
    Last Post: November 16th, 2010, 08:45 AM
  5. How to Get users home directory
    By JavaPF in forum Java Programming Tutorials
    Replies: 0
    Last Post: September 2nd, 2010, 10:37 AM