Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 First Java Program
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
slider203




PostPosted: Wed Feb 10, 2010 6:25 pm   Post subject: First Java Program

Hello I have never used Java before this monday and in class we have to make a program that is sort of like ticket master. This will be my first ever Java program and I got the worst teacher in the school teaching my class, so I dont know what to do I have started my program but I got stuck....heres what I have so far:

// Program Name: Ticket King
//
// This program takes as input the movie title the user wants to see, the tax
// rate and the number of tickets along with the price of tickets,
// then calculates the total cost and adds the tax onto the total price
// and outputs the price of the movie tickets and the price including tax.
/////////////////////////////////////////////////////////////////////////////////
// Movie - this is the title of the movie the user wants to see
// Tax - this is the amount of tax on the ticket
// Tiktprc - this is the price per ticket
// Tiktnum - this is the number of tickets the user wants

class TicketKing
{
public static void main (String args [])
{
System.out.println ("Hello Welcome to Ticket King");
System.out.println ("What movie do you want to see?")

after this I would like to have the user type in the title of the movie, but I am sure on how to do this.
I know in turing you would have to create a variable (e.g. movie) then put get movie to get the user input is this similar to Java. Thank you any help would be appericated.
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Wed Feb 10, 2010 7:58 pm   Post subject: RE:First Java Program

I'm surprised your teacher did not tell you how to do this. Here is an example of Java console input:

Java:
import java.awt.*;
import java.io.*;

public class ConsoleInput
{
    public static void main (String[] args) throws Exception
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       
        String input = in.readLine();
       
        System.out.println("input was: '" + input + "'");
    }
}


Hope that helps.
TheGuardian001




PostPosted: Wed Feb 10, 2010 8:02 pm   Post subject: Re: First Java Program

Alternatively, the BufferedReader/InputStreamReader combo can be replaced with a java.util.Scanner(System.in), although as far as I can tell they're pretty much the same thing in the end.

Edit: Also, for future reference:

code:

[code="java"]
Java code goes here
[/code]
DemonWasp




PostPosted: Wed Feb 10, 2010 9:02 pm   Post subject: RE:First Java Program

An important note: if you are using Ready To Program (made by HoltSoft), it uses a version of Java so old it doesn't have Scanner, so you have to use the other route.
slider203




PostPosted: Thu Feb 11, 2010 7:16 pm   Post subject: Re: First Java Program

Wow thanks for the help I have to have this finished by monday so hopefuly all of you have helped me out havnt had time to try anything out yet but thanks for the repy Ill let you know how I make out when I get it going. Thanks
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: