New TO JAVA Programming

Dear Forummembers,
I am student doing postgraduate studies in IT.i have some queries related to one of my programming staff.i am very much new into Java programming and i am finding it a bit difficult to handle this program.The synopsis of the program is given below -
You are required to design and code an object-oriented java program to process bookings for a theatre perfomance.
Your program will read from a data file containing specifications of the performance,including the names of the theatre, the play and its author and the layout of the theatre consisting of the number of seats in each row.
It will then run a menu driven operation to accept theatre bookings or display the current
status of seating in the theatre.
The name of the file containing the details of the performance and the theatre should be
provided at the command line, eg by running the program with the command:
java Booking Theatre.txt
where Theare.txt represents an example of the data file.
A possible data file is:
Opera
U and Me
Jennifer Aniston
5 10 10 11 12 13 14
The data provided is as follows
Line 1
Name of the Theatre
Line 2
Name of the play being performed
Line 3
Name of the author of the play being performed
Line 4
A list of the lengths (number of seats) of each row in the theatre, from front to
back.
The program must start by reading this file, storing all the appropriate parameters and
establishing an object to accept bookings for this performance with all details for the theatre
and performance.
The program should then start a loop in which a menu is presented to the user, eg:
Select from the following:
B - Book seats
T - Display Theatre bookings
Q - Quit from the program
Enter your choice:
And keep performing selected operations until the user�s selects the quit option, when the
program should terminate.
T - Display Theatre bookings
The Display Theatre Bookings option should display a plan of the theatre. Every available
seat should be displayed containing its identification, while reserved seats should contain an
Rows in each theatre are indicated by letters starting from �A� at the front. Seats are
numbered from left to right starting from 1. A typical seat in the theatre might be designated
D12, representing seat 12 in row D.
B - Book seats
The booking of seats is to offer a number of different options.
First the customer must be asked how many adjacent seats are
required. Then start a loop offering a further menu of choices:
Enter one of the following:
The first seat of a selected series, eg D12
A preferred row letter, eg F
A ? to have the first available sequence selected for you
A # to see a display of all available seats
A 0 to cancel your attempt to book seats
Enter your selection:
1. If the user enters a seat indentifier such B6, The program should attempt to
reserve the required seats starting from that seat. For example if 4 seats are
required from B6, seats B6, B7, B8 and B9 should be reserved for the customer,
with a message confirming the reservation and specifying the seats reserved..
Before this booking can take place, some testing is required. Firstly, the row
letter must be a valid row. Then the seat number must be within the seats in the
row and such that the 4 seats would not go beyond the end of the row. The
program must then check that none of the required seats is already reserved.
If the seats are invalid or already reserved, no reservation should be made and the
booking menu should be repeated to give the customer a further chance to book
seats.
If the reservation is successful, return to the main menu.
2. The user can also simply enter a row letter, eg B.IN this case, the program should
first check that the letter is a valid row and then offer the user in turn each
adjacent block of the required size in the specified row and for each ask whether
the customer wants to take them. Using the partly booked theatre layout above, if
the customer wanted 2 seats from row B, the customer should be offered first:
Seats B5 to B6
then if the customer does not want them:
Seats B10 to B11
and finally
Seats B11 to B12
If the customer selects a block of seats, then return to the main menu. If none are
selected, or there is no block of the required size available in the row, then report
that no further blocks of the required size are available in the row and repeat the
booking menu.
3. If the user enters a ? the program should offer the customer every block of seats
of the required size in the whole theatre. This process should start from the first
row and proceed back a row at a time. For example, again using the partially
booked theatre shown above, if the user requested 9 seats, the program should
offer in turn:
Seats A1 to A9
Seats C1 to C9
Seats C2 to C10
Seats E3 to E11
Seats E4 to E12
If the customer selects a block of seats, then return to the main menu. If none are
selected, or there is no block of the required size available in the whole theatre,
then report that no further blocks of the required size are available and repeat the
booking menu.
4. If the user enters a # the program should display the current status of the seating
in the theatre, exactly the same as for the T option from the main menu and then
repeat the booking menu.
5. If the user enters a 0 (zero), the program should exit from the booking menu back
to the main menu. If for example the user wanted 9 seats and no block of 9 was
left in the theatre, he would need to make two separate smaller bookings.
The program should perform limited data validation in the booking process. If a single
character other than 0, ? and # is entered, it should be treated as a row letter and then tested
for falling within the range of valid rows, eg A to H in the example above. Any invalid row
letters should be rejected.
If more than one character is entered, the first character should be tested as a valid row letter,
and the numeric part should be tested for falling within the given row. You are NOT
required to test for valid numeric input as this would require the use of Exception handling.
You are provided with a class file:
Pad.java
containing methods that can be used for neat alignment of the seat identifiers in the theatre
plan.
File Processing
The file to be read must be opened within the program and if the named file does not exist, a
FileNotFoundException will be generated. It is desirable that this Exception be caught and
a corrected file name should be asked for.
This is not required for this assignment, as Exception handling has not been covered in this
Unit. It will be acceptable if the method simply throws IOException in its heading.
The only checking that is required is to make sure that the user does supply a file on the
command line, containing details of the performance. This can be tested for by checking the
length of the parameter array args. The array length should be 1. If not, display an error
message telling the user the correct way to run the program and then terminate the program
System.exit(0);
The file should be closed after reading is completed.
Program Requirements
You are expected to create at least three classes in developing a solution to this problem.
There should be an outer driving class, a class to represent the theatre performance and its
bookings and a class to represent a single row within the theatre.
You will also need to use arrays at two levels. You will need an array of Rows in the Theatre
class.
Each Row object will need an array of seats to keep track of which seats have been reserved.
Your outer driving class should be called BookingOffice and should be submitted in a file named BookingOffice.java
Your second, third and any additional classes, should be submitted in separate files, each
class in a .java file named with the same name as the class
I am also very sorry to give such a long description.but i mainly want to know how to approach for this program.
also how to designate each row about it's column while it is being read from the text file, how to store it, how to denote first row as row A(second row as row B and so on) and WHICH CLASS WILL PERFORM WHICH OPERATIONS.
pls do give a rough guideline about designing each class and it's reponsibilty.
thanking u and looking forward for your help,
sincerely
RK

yes i do know that........but can u ppl pls mention
atleast what classes shud i consider and what will be
the functions of each class?No, sorry. Maybe somebody else will, but in general, this is not a good question for this forum. It's too broad, and the question you're asking is an overall problem solving approach that you should be familiar with at this point.
These forums are best suited to more specific questions. "How do I approach this homework?" is not something that most people are willing or able to answer in a forum like this.

Similar Messages

  • Help needed, new to java programming

    hi,
    I have craeted a Frame with some check boxes and button called "button1".
    Can anyone tell me how can i count the number of CHECKED check boxes so that when i press the button1 in my code it should display the result as number of checked check boxes divided by total number of check boxes. It should display the result in a textfield here RESULT textfield in my code
    Thanks in advance ...i am sending the code i have written so far....
    public class Frame extends java.awt.Frame {
        /** Creates new form Frame */
        public Frame() {
            initComponents();
            setSize(600, 600);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            buttonGroup1 = new javax.swing.ButtonGroup();
            checkbox1 = new java.awt.Checkbox();
            checkbox2 = new java.awt.Checkbox();
            checkbox3 = new java.awt.Checkbox();
            button1 = new java.awt.Button();
            textField1 = new java.awt.TextField();
            setLayout(null);
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            checkbox1.setLabel("checkbox1");
            add(checkbox1);
            checkbox1.setBounds(160, 50, 84, 20);
            checkbox2.setLabel("checkbox2");
            add(checkbox2);
            checkbox2.setBounds(160, 70, 84, 20);
            checkbox3.setLabel("checkbox3");
            add(checkbox3);
            checkbox3.setBounds(160, 90, 84, 20);
            button1.setLabel("button1");
            button1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    button1ActionPerformed(evt);
            add(button1);
            button1.setBounds(150, 180, 57, 24);
            textField1.setText("Result");
            textField1.setName("Result");
            add(textField1);
            textField1.setBounds(260, 180, 44, 20);
            pack();
        private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
            // Add your handling code here:
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new Frame().show();
        // Variables declaration - do not modify
        private java.awt.Button button1;
        private javax.swing.ButtonGroup buttonGroup1;
        private java.awt.Checkbox checkbox1;
        private java.awt.Checkbox checkbox2;
        private java.awt.Checkbox checkbox3;
        private java.awt.TextField textField1;
        // End of variables declaration
    }

    Two problems in the code you repost-ed:
    1. It lacks import statements.
    2. There is an extraneous } at the end of the button1ActionPerformed method.
    Correct them and it'll work fine. Posting the full source code:
    import java.awt.Component;
    import java.awt.Checkbox;
    public class Frame extends java.awt.Frame
         /** Creates new form Frame */
         public Frame()
              initComponents();
          * This method is called from within the constructor to initialize the form.
          * WARNING: Do NOT modify this code. The content of this method is always
          * regenerated by the Form Editor.
         private void initComponents()
              checkbox1 = new java.awt.Checkbox();
              checkbox2 = new java.awt.Checkbox();
              checkbox3 = new java.awt.Checkbox();
              button1 = new java.awt.Button();
              textField1 = new java.awt.TextField();
              setLayout( null );
              addWindowListener( new java.awt.event.WindowAdapter()
                   public void windowClosing( java.awt.event.WindowEvent evt )
                        exitForm( evt );
              checkbox1.setLabel( "checkbox1" );
              add( checkbox1 );
              checkbox1.setBounds( 120, 40, 84, 20 );
              checkbox2.setLabel( "checkbox2" );
              add( checkbox2 );
              checkbox2.setBounds( 120, 60, 84, 20 );
              checkbox3.setLabel( "checkbox3" );
              add( checkbox3 );
              checkbox3.setBounds( 120, 80, 84, 20 );
              button1.setLabel( "button1" );
              button1.addActionListener( new java.awt.event.ActionListener()
                   public void actionPerformed( java.awt.event.ActionEvent evt )
                        button1ActionPerformed( evt );
              add( button1 );
              button1.setBounds( 50, 170, 57, 24 );
              textField1.setText( "textField1" );
              add( textField1 );
              textField1.setBounds( 240, 170, 60, 20 );
              pack();
         private void button1ActionPerformed( java.awt.event.ActionEvent evt )
              // Add your handling code here:
              Component[] components = getComponents();
              int numOfCheckBoxes = 0;
              int numChecked = 0;
              for ( int i = 0; i < components.length; i++ )
                   if ( components[i] instanceof Checkbox )
                        numOfCheckBoxes++;
                        Checkbox checkBox = (Checkbox) components;
                        if ( checkBox.getState() )
                             numChecked++;
              double ratio = (double) numChecked / (double) numOfCheckBoxes;
              textField1.setText( Double.toString( ratio ) );
         /** Exit the Application */
         private void exitForm( java.awt.event.WindowEvent evt )
              System.exit( 0 );
         * @param args the command line arguments
         public static void main( String args[] )
              new Frame().show();
         // Variables declaration - do not modify
         private java.awt.Button button1;
         private java.awt.Checkbox checkbox1;
         private java.awt.Checkbox checkbox2;
         private java.awt.Checkbox checkbox3;
         private java.awt.TextField textField1;
         // End of variables declaration
    I can see from the code that the GUI was generated by a tool. Since you're new to Java programming, I'd recommend ditching the tool and writing everything by hand, otherwise you're not learning much. It's just like when you're learning proofs in Maths, where you start with first principles before making use of the proofs on their own.
    Also, it'll help tremendously if you could spend some time going through the Java Tutorial (http://java.sun.com/docs/books/tutorial/). It's free, and I find it very useful.
    Hth.

  • Please help me in this tough problem in Java...im just new in Java program

    my teacher give this as a problem. so tough. we are just starting and we are now in control structures. please help me to finish this problem. And my problem is...
    Write an astrology program. The user types in his or her birthday(month,day,year),
    and the program responds with the user's zodiac sign, the traits associated with each sign
    the user's age(in years,months,day), the animal sign for the year(e.g., Year of the Pig,
    Year of the Tiger), the traits associated with each animal sign, and if the year is a leap
    year or not. The dates covered for each sign can be searched through the horoscope section
    of a newspaper or through the internet. Then enhance your program so that if the user is one
    or two days away from the adjacent sign, the program outputs the nearest adjacent sign as well
    as the traits associated with the nearest sign. The month may be entered as a number from 1 to 12
    or in words, i.e.,January to December. Limit the year of the birthday from 1900 to 2010 only.
    The program should allow the user to repeat the entire process as often as desired.
    You can use:
    import java.text.DateFormat;
    import java.util.Date;
    import java.util.Calendar;
    please...those who are genius out there in java program...help us to pass this project. Im begging! thanks!

    Frowner_Stud wrote:
    According to the second commandment: Thou shall not use the name of the Lord in vain.Is this not the definition of ironic, Mr. Morality?
    i am not cheating. And more of the same.
    we all know that an assignment is an assignment. a homework. homework means you can raise other help from somebody so that you will know the answer.You're not asking for "help" bucko, because you've been given decent help but have chosen to ignore it. No, you're asking for someone to do the work for you, and you may call it what you want, but in anyone else's book, that's cheating.
    dont be fool enough to reply if you dont know the reason why i am typing here Don't be fool enough to think that you can control who can or can't respond.
    because if you are in my part and if i know the answer there is no doubt that i will help you as soon as possible! Just because you have low morals doesn't mean that the rest of us do.
    Thanks for time of reading and God bless you including you family!and to you and yours. Have a blessed day.

  • Im new to java programming and cant this program to help

    Dear All
    I using a Java Book called Java Gently written by J.Bishop Im working on a program and its typed out correctly and compiled corretcly, but for some reason wont work i dont know what parameters i need to enter.
    take a look:
    class CurioStore1 {
    * Write a description of class CurioStore1 here.
    * @author (your name)
    * @version (a version number or a date)
    // Declare three object variables
    Curio mugs, tshirts, carvings;
    // The constructor for the program is
    // where the inital work gets done
    CurioStore1 () {
    // Create three objects with different initial values
    mugs = new Curio ("Traditional mugs", 6, "beaded in Ndebele style");
    tshirts = new Curio ("Traditional mugs" , 30, "sizes M to XL");
    carvings = new Curio ("Masks", 80, "carved in wood");
    // Print out a header
    System.out.println ("The Polelo Curio Store sells\n");
    // Print the values contained in each of the objects
    mugs.write();
    tshirts.write();
    carvings.write();
    // All programs must have a main method
    public static void main (String [ ] args) {
    // Start the program running from its constructor
    new CurioStore1 ();
    class Curio {
    //Declare variables related to a curio
    String name;
    int price;
    String description;
    //The constructor copies the initial values
    // into the ogjects variables
    Curio (String n, int p, String d) {
    name = n;
    price = p;
    description = d;
    // a method to ouput the vlaurd of the object's variables
    void write () {
    System.out.println (name + " " + description + " for G" + price);

    What is currently happening when you attempt to run the above program?
    Try changing your main method as I have changed it below and see if anything is displayed.
    class CurioStore1 {
    * Write a description of class CurioStore1 here.
    * @author (your name)
    * @version (a version number or a date)
    // Declare three object variables
    Curio mugs, tshirts, carvings;
    // The constructor for the program is
    // where the inital work gets done
    CurioStore1 () {
    // Create three objects with different initial
    ial values
    mugs = new Curio ("Traditional mugs", 6, "beaded
    ded in Ndebele style");
    tshirts = new Curio ("Traditional mugs" , 30,
    30, "sizes M to XL");
    carvings = new Curio ("Masks", 80, "carved in
    in wood");
    // Print out a header
    System.out.println ("The Polelo Curio Store
    ore sells\n");
    // Print the values contained in each of the
    the objects
    mugs.write();
    tshirts.write();
    carvings.write();
    // All programs must have a main method
    public static void main (String [ ] args) {
    // Start the program running from its constructor
    System.out.println ("before constructor");
    new CurioStore1 ();
    System.out.println ("after constructor");
    class Curio {
    //Declare variables related to a curio
    String name;
    int price;
    String description;
    //The constructor copies the initial values
    // into the ogjects variables
    Curio (String n, int p, String d) {
    name = n;
    price = p;
    description = d;
    // a method to ouput the vlaurd of the object's
    ect's variables
    void write () {
    System.out.println (name + " " + description +
    ption + " for G" + price);

  • I'm new with Java programming

    I'm having a problem with compiling my source files using Javac.exe.
    I type the command using the command prompt.
    (javac ClickMe.java)
    and I get a error message.
    (error: cannot read: ClickMe.java 1 error)
    my op system is win2000

    Enclose the name in quotes when you save.
    Eg:
    "ClickMe.java"
    instead of
    ClickMe.java
    Also, you should switch to a more capable editor as a matter of urgency. At the very least, your editor should support line numbers.
    Hope this helps.--
    <sig> http://www.itswalky.com http://www.crfh.net </sig>

  • I'm new in java program... ineed help

    i need to post a table to a web page from database using java..
    these are the parameters given by my boss.. pls help...
    SELECT DISTINCT PROD_GRP,
    NVL(SHIPPED,0) AS SHIPPED,
    NVL(NET_SCRAP,0) AS NET_SCRAP,
    ROUND(NVL(TOTAL_ASSY,0),2) AS TOTAL_ASSY,
    ROUND(NVL(TEST_YLD,0),2) AS TEST_YLD,
    ROUND(NVL("CONT%",0),2) AS CONT_PS,
    ROUND(NVL(ATY,0),2) AS ATY,
    NVL("$SHIPPED",0) AS DS_SHIPPED,
    NVL("$NET_SCRAP",0) AS SCRAP,
    NVL("TEST_$SCR",0) AS TEST_SCRAP,
    ROUND(NVL(CWATY,0),2) AS CWATY,
    NVL(LOT_BONUS,0) AS LOT_BONUS,
    NVL(LOT_SCRAP,0) AS LOT_SCRAP,
    NVL("TEST_$COST",0) AS test_dollar_cost,
    ROUND(NVL("TEST_COST%",0),2) AS test_cost_percent
    FROM prod_grp
    WHERE facility = 'CLARK-AT'
    AND run_date = 'D20100425'
    AND prod_grp in (select distinct prod_grp
    FROM device
    WHERE facility = 'CLARK-AT'
    AND MFG_GRP = 'QFN')
    AND EXCLUSION_ON ='Y'
    ORDER BY PROD_GRP ASC
    ** font in bold blue means dynamic
    Connection string:
    # Cwaty Clark
    db.connectString.Cwatydb=jdbc:oracle:thin:cwatyclk/[email protected]:1521:cwatydb
    db.driverString.Cwatydb=oracle.jdbc.driver.OracleDriver
    db.minConnections.Cwatydb=0
    db.maxConnections.Cwatydb=16
    db.testQuery.Cwatydb=SELECT * FROM dual
    db.conURL.Cwatydb=jdbc:oracle:thin:@smsdwsp3.itg.ti.com:1521:cwatydb
    db.host.Cwatydb=smsdwsp3.itg.ti.com
    db.sid.Cwatydb=cwatydb
    db.usr.Cwatydb=cwatyclk
    db.pwd.Cwatydb=reserved
    db.dbName.Cwatydb=cwatydb
    thanks alot..

    These aren't parameters. Youve got a SQL SELECT statement and a snippet of Java code to connect with the oracle database.
    What you need to do is to create a PreparedStatement and read the ResultSet. But franckly, if you don't know anything about this, i would go for a little help from my colleaques.
    Edited by: hsc71 on 6-mei-2010 9:38
    Edited by: hsc71 on 6-mei-2010 9:39

  • New to java - glitch in my program/game? should be a simple fix :)

    hey everyone, I'm a student who's new to java programming :) It's is also the first programming language that I'm learning. I know the basics, but nothing very complicated.
    I'm making a pong-like game, in an applet.
    As I was making the paddle and using a mouselistener to make it move vertically, I came across this problem, the paddle will move vertically with the mouse's position, but one end of my paddle will grow abnormally (I want it to stay the same size as it moves up and down)
    Here's my code: (I'm not using most of the mouselistener and keylistener classes yet, so you can ignore them. I'm guessing the problem is probably in one of the last classes, at the bottom)
    ypaddle is the variable used for getting the co-ordinates of the mouse and transferring them to the paddle itself
    // The "Ping" class.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    *Ping
    public class Ping extends Applet
        implements KeyListener, MouseListener, MouseMotionListener
        int width, height, x, ypaddle;
        Graphics g;
        char move;
         *Initializes variables
        public void init ()
            resize (700, 500);
            setBackground (Color.white);
            addKeyListener (this);
            addMouseListener (this);
            addMouseMotionListener(this);
        public void keyPressed (KeyEvent e)
        public void keyReleased (KeyEvent e)
        public void keyTyped (KeyEvent e)
        public void mouseEntered (MouseEvent e)
        public void mouseExited (MouseEvent e)
        public void mousePressed (MouseEvent e)
        public void mouseReleased (MouseEvent e)
        public void mouseClicked (MouseEvent e)
        public void mouseMoved (MouseEvent e)
            ypaddle = e.getY ();
            repaint();
        public void mouseDragged (MouseEvent e)
        public void paint (Graphics g)
            paddle (g, ypaddle);
         * Creates the paddle for hitting the ball
         *@param    y   value used to move the paddle vertically
        public void paddle (Graphics g, int y)
            g.fillRect (10, 10+y, 15, 60+y);
    } // Ping classI'm totally stumped, I've tried for 2 hours to find the problem, and I have a feeling it's something very simple that I'm passing over...
    If you have any questions about the variables or other things, please ask!
    And one last little quick question, is there a way I can restrict the movement of the paddle between two Y values? (i.e not higher than y=10 or lower than y=100)
    Thanks in advance :)

    soundweave wrote:
    I'm not exactly sure how to find out, Eh?
    You wrote this code:
    g.fillRect (10, 10+y, 15, 60+y);Do you understand what fillRect does? If I call fillRect(10, 20, 30, 40) where will that rectangle be drawn? If you don't know how to answer that, I don't see how you could have written that line of code.
    but here's some pictures of what happens ( I put in 0 and 80 as the y values in each picture, and left the code window open so you can see )I don't need to see them.
    Y at 0: [http://i731.photobucket.com/albums/ww314/len56/Untitled.jpg?t=1263077701|http://i731.photobucket.com/albums/ww314/len56/Untitled.jpg?t=1263077701]
    Y at 80: [http://i731.photobucket.com/albums/ww314/len56/Untitled2.jpg?t=1263077625|http://i731.photobucket.com/albums/ww314/len56/Untitled2.jpg?t=1263077625]
    So, given that the first one comes from fillRect(10, 10, 15, 60), (you get where that comes from I hope) and the second comes from fillRect(10, 90, 15, 150) (that too), does that not suggest that something is wrong with the numbers you're passing to fillRect? And since you have read the docs for fillRect and know what it does and what each of its parameters represents (right?), does it not suggest exactly what is wrong with those numbers?

  • How to put a startup picture in a java program?

    Hi there,
    I'm extremely new in Java programming and have a very weak knowledge in C programming. I managed to download a Java source file from the internet which I need to use for my school's project. I was wondering would it be possible for me to put a start up picture or video clip before the program runs? And if so, how do I go about doing it? Thanks in advance.
    LostInJava

    Requires the latest Java version, Java 6.And there are fairly simple ways to program your own splash screens in earlier versions.

  • Java programming

    I am new to Java programming and using the compiler "javac" from the command prompt. When I get morethan 6 or 7 errors the screen scrolls so fast I cannot read the first error message. Is there a way I can use to pause the screen or redirect the error messages to a text file?
    My second question is how do you convert a double value to an integer value. I tried "intValue" but it's not working. Please reply as soon as possible.

    I am new to Java programming and using the compiler
    "javac" from the command prompt. When I get morethan 6
    or 7 errors the screen scrolls so fast I cannot read
    the first error message. Is there a way I can use to
    pause the screen or redirect the error messages to a
    text file?
    If its WIN 2000 or NT first execute your programs from batch files. last line of batch file should be "pause". while the window is still open, right click on the top left corner and increase the buffer size.
    If that doesent work you can try
    javac classfile > outputfile
    That might work on windows systems
    My second question is how do you convert a double
    value to an integer value. I tried "intValue" but it's
    not working. Please reply as soon as possible.Math.round()

  • Java Programming Help

    I'm new to Java programming, and I have a pretty basic question. I'm writing a simple loan calculator, and I need to know how to format the output of my variables to two decimal places. I've been doing this for about a week, so be nice, please.
    Thanks in advance,
    Wayne

    NumberFormat nf = NumberFormat.getCurrencyInstance();
    double cash = 123.45;
    System.out.println(nf.format(cash));
    Your First Cup of Java
    Essentials, Part 1, Lesson 1: Compiling & Running a Simple Program
    The Java Tutorial - A practical guide for programmers
    New to Java Center
    How To Think Like A Computer Scientist
    Introduction to Computer Science using Java
    The Java Developers Almanac 1.4
    JavaRanch: a friendly place for Java greenhorns
    jGuru
    Object-Oriented Programming Concepts
    Object-oriented language basics
    Don't Fear the OOP
    Books:
    Bert Bates and Kathy Sierra's Head First Java
    Bruce Eckel's Thinking in Java (Free online)
    Joshua Bloch's Effective Java
    Java Design: Building Better Apps and Applets (2nd Edition)

  • Java program HELPPPP!!!!!

    Hello, I'm very new to Java programming, and well I'm taking Computer Science as my major, and I need a little help to this program:
    You will develop an inheritance hierarchy of classes to enhance your understanding of inheritance, encapsulation, and polymorphism.
    All classes developed must be complete including:
    appropriate symbolic constants
    appropriate data fields
    constructors (default, complete, and, if appropriate, partial)
    accessor methods
    mutator methods
    standard methods inherited and overridden from Object:
    boolean equals(Object other)
    String toString()
    problem specific methods
    The project involves working with washers. A Washer is a circular metallic disc with its circular center removed. As such, the relevant data fields for a washer are:
    the outer diameter (OD) of the larger circle
    the inner diameter (ID) of the smaller circle
    the thickness of the disc
    When constructing or mutating these data fields remember that they need to be validated such that all fields are greater than zero and the outer diameter must be larger than the inner diameter (use helper methods for validation so that the code only appears once).
    In addition to the Washer class you will also need to define two derived classes based on the type of metal used for the washer. These will be BrassWasher and SteelWasher. Brass has a density of 8.4 g/cm3 while steel has a density of 7.8 g/cm3 (both of these numbers are approximate since both metals are alloys and their densities depend on the composition of the alloys). The densities should be defined as symbolic constants in the appropriate derived classes.
    The problem specific methods needed are:
    double volume()
    double weight()
    These should be placed in the appropriate classes.
    The main program (in class TestWashers) will create an array of Washer instances (generate reasonable values for the inner and outer diameters and thickness of the washers as well as the material types by using random numbers (see Math.random())) (discussed in class and look up the documentation). The program will then compute the total weight of the collection of washers as stored in the array. The program will display the list of washers (i.e., by using toString() for each array element) and then the total weight of the whole collection of washers (properly annotated).
    My question is what should I put in the Washer class? you know the parent class. Because I'm confuse on the boolean equals(object other) and String toString(), and the double volume and double weight.
    and how to do the Math.random()?
    This is the program that my teacher told us to do, but I'm having problems on how to start.
    Thanks.

    Please change your code tags. Even you must see that they aren't working.
    You can do this by changing your curly braces to square braces[code]
    Your code is still editable so you can do this without having to repost the whole thing.
    regarding toString: if you wanted a quick way to represent what data a Washer object contains, what would this one line string look like?  Model your toString() after this.
    regarding your equals: what object variables need to be all equal for two washers to be the same type?  Write an equals method to match that.  Note that equals must be passed an object as its parameter.  So the first thing you must do is check to make sure that the passed parameter object is in fact a Washer object (use instanceOf for this).  If not, return false.
    Edited by: Encephalopathic on Oct 1, 2008 7:28 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Java programing in XCODE 3.0

    Hi
    Im new to JAVA programming so i guess my question is pretty basic. I just upgraded to XCODE 3.0 and now I have trouble debugging and running the simple code i write. Previosly I used XCODE 2.4 and had no trouble there. Is there anyone of you that know a setting you would recommend for XCODE 3.0. Again, I do very , very basic code so far.
    Thx

    if you are using very very basic java coding, then why not just compile it on a Terminal and use a simple text editor?
    XCode is apple specific and it involves many tools and environments. Asking them on their list would get better response.

  • Error compiling Java Program

    I am new to java programming.
    I recently took a java class. In the lab we created a simple program.
    The program was split up in two separate files.
    //Vehicle.java
    public class Vehicle {
         private double load;
         private double maxLoad;
              public Vehicle(double max_Load) {
                   load = 0.0;     
                   maxLoad = max_Load;
              public double getLoad(){
                   return load;
              public double getMaxLoad(){
                   return maxLoad;
              boolean addBox(double weight) {
                   if ((weight + load) > maxLoad)
                        return false;
                   else
                        load=weight+load;     
                        return true;
    }//end of class Vehicle
    on a complete separate file
    public class TestVehicle {
    public static void main(String[] args) {
    // Create a vehicle that can handle 10,000 kilograms weight
    System.out.println("Creating a vehicle with a 10,000kg maximum load.");
    Vehicle vehicle = new Vehicle(10000.0);
    // Add a few boxes
    System.out.println("Add box #1 (500kg) : " + vehicle.addBox(500.0));
    System.out.println("Add box #2 (250kg) : " + vehicle.addBox(250.0));
    System.out.println("Add box #3 (5000kg) : " + vehicle.addBox(5000.0));
    System.out.println("Add box #4 (4000kg) : " + vehicle.addBox(4000.0));
    System.out.println("Add box #5 (300kg) : " + vehicle.addBox(300.0));
    // Print out the final vehicle load
    System.out.println("Vehicle load is " + vehicle.getLoad() + " kg");
    when we complied the program we ONLY compiled TestVechile.java
    ( javac TestVechile.java) and BOTH the class compiled successfully. When I tried to compile the TestVehicle class at home I got an error at line 6 in TestVehicle.java.
    Please any help would be greatly appreciated.
    - Alex

    To compile TestVehicle.java, you need either Vehicle.java or Vehicle.class -- with neither of them, the compiler doesn't know whether "new Vehicle(10000.0)" is legal or not.

  • Newbie to java programming

    Hi
    I'm completely new to Java programming, I have worked for a year in Qbasic, but that is like kids play kind of programming, im unsure as to the similarities/differences between the 2 languages.
    Also: I know that Java is an "Object oriented" form of programming, can anyone explain what this means?
    Im going to start at the beginning of the manual, is it ok if i come here and ask questions if im stuck with anything? I don't know what the community is like here...
    Thanks,
    Chloe

    Here are some good introductions to OOP:
    Object-Oriented Programming Concepts
    Object-oriented language basics
    Don't Fear the OOP
    And here are some other great resources for beginning Javites:
    http://java.sun.com/docs/books/tutorial/
    http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/compile.html
    http://java.sun.com/learning/new2java/index.html
    http://javaalmanac.com
    http://www.jguru.com
    http://www.javaranch.com
    Bruce Eckel's Thinking in Java
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java
    Good luck, and Happy Coding!
    &#167;

  • New to java  -especially linked lists

    I�m trying to work with linked lists but not having much luck�
    Overall, the program must create a datastructure that will hold titles of articles. Up to 10 keywords can be added to each article and it must then be possible to search all of the titles for matches to the keyword.
    Currently I�m stuck in a for-loop � my linked list (articleList) is not accepted. Any help would be much appreciated. The following error occurs when I attempt to compile:
    SearchMachine.java:30: cannot resolve symbol
    symbol : variable articleList
    location: class SearchMachine
              for(ListIterator listiter = articleList.listIterator(); listiter.hasNext();)
    ^
    import java.util.*;
    class Document
         private String title;
         private String keywords [] = new String [10];
         private int last = 0;
         public Document (String _title)
              String title = _title;
         public void addKeyword(String kw)
              if(last < 9)
                   keywords [last]= kw;
                   last ++;
                   System.out.println("The keyword " + kw + " has now been added");
              else if (last == 9)
                   keywords [last]= kw;
                   System.out.println ("The document now has 10 keywords. No more can be added");
    class SearchMachine
         SearchMachine()
              LinkedList articleList = new LinkedList ();
              articleList.add (new Document ("Oracle 8 the new SQL programming"));
              articleList.add (new Document ("Java programming made easy"));
         public void print()
              for(ListIterator listiter = articleList.listIterator(); listiter.hasNext();)
                   System.out.println(listiter.next());
         public static void main (String [] args)
              SearchMachine search;     
              search = new SearchMachine();
              search.print();

    This is a basic scope issue. You declare the variable articleList inside the constructor block and thus it's visible only in the constructor block. The variable doesn't exist anywhere else but in SearchMachine() {...} The solution is to move the line "LinkedList articleList = new LinkedList();" three lines up, outside the constructor but inside the class definition, so that articleList becomes a member of the SearchMachine class.

Maybe you are looking for