User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,552 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,473 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1882 | Replies: 9
Reply
Join Date: Oct 2007
Posts: 3
Reputation: WVTraveler1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
WVTraveler1 WVTraveler1 is offline Offline
Newbie Poster

Help with ending a program

  #1  
Oct 16th, 2007
Hello, I would like some help with ending a program. I am working on some homework for writing code and everything I try will not allow me to end the program. I keep getting a syntax error "expected "}"" and I can not figure it out. I have checked for the brackets and they are both there, if I remove them it still says the same thing. Could some one please advise? Here is the end portion of my code:

{
System.exit(0);
}
}
}
} //end program


Thank you!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,517
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Help with ending a program

  #2  
Oct 16th, 2007
We would need more than the end portion. The problem is, you have an open { without a closing }. Double check all your braces and make sure that for every { there is a corresponding } .
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: WVTraveler1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
WVTraveler1 WVTraveler1 is offline Offline
Newbie Poster

Help Re: Help with ending a program

  #3  
Oct 17th, 2007
Sorry, I am new at this and quite frankly, Java programming is not my bailiwick. Here is the program I have written and have been working on for several weeks for my IT class. Any help would be appreciated, several portions are not working, but right now the ending is frustrating me more as there is no information on how to do this. Thank you!

* Inventory.java
*
* Created on September 30, 2007, 3:34 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package inventory;
/**
*
* @author xxxxxxxxxxx (left intentionally blank)
*/
import java.util.Scanner;

class Inventory {

private String NameOfItem;

private int NameOfItems;

/** Creates a new instance of Inventory */
public Inventory() {
String inventoryName = null;
int items = 0;

}
public String getNameOfItem() {
return this.getNameOfItem();
}
public int items() {
return this.items();
}
public void setNameOfItem(String name) {
this.NameOfItem = name;
}
public void setNameOfItem(int item) {
this.NameOfItem = NameOfItem;
}
} // End Inventory class class

/*
* DVD.java
*
* Created on September 30, 2007, 3:34 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
class DVD {

/** Creates a new instance of Inventory */
public DVD() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Inventory Set[] = new Inventory[4]; // I am using array

Set[0] = new Inventory();
Set[0].setNameOfItem("Breakdown Palace");
Set[0].getNameOfItem();
inventory.add(dvd);

Set[1] = new Inventory();
Set[1].setNameOfItem("The Incredibles");
Set[1].getNameOfItem();
inventory.add(dvd);

Set[2] = new Inventory();
Set[2].setNameOfItem("Click");
Set[2].getNameOfItem();
inventory.add(dvd);

Set[3] = new Inventory();
Set[3].setNameOfItem("The Man");
Set[3].getNameOfItem();
inventory.add(dvd);

Set[4] = new Inventory();
Set[4].setNameOfItem("Christmas with the Kranks");
Set[4].getNameOfItem();
inventory.add(dvd);

Set[5] = new Inventory();
Set[5].setNameOfItem("Roll Bounce");
Set[5].getNameOfItem();
inventory.add(dvd);

Set[6] = new Inventory();
Set[6].setNameOfItem("American Outlaws");
Set[6].getNameOfItem();
inventory.add(dvd);
}
}// End DVD class class
/**** This is a subclass that adds 5% restocking fee and new feature genres***/

class FeatDVD extends DVD
{
private String genres;

// class constructor
FeatDVD(int item, String title, int stock, double price, String genres)
{
super(item, title, stock, price);
this.genres = genres;
}
public String getGenres()
{
return genres;
}

public double getValue()
{// getvalue method overrides
// getvalue method in the superclass
double value = 1.05F * super.getValue();
return value;
}// end getValue method

public String toString()
{//toString method overrides the superclass toString method
//adding another fields
return super.toString() + "Genre:" + genres;
}// end toString method

} // end class FeatDVD

/*****class has inventory of DVDs.
* This class has methods to add and display dvds****/


class Inventory {
}
/** Creates a new instance of Inventory */
public Inventory() {
}

/**
* @param args the command line arguments
*/
{
private DVD_name[];
private number;
private String name;

}
//Constructor to store data
public Inventory(String DVD_name, number, DVD_price)
{
String name = DVD_name;
stock = DVD_number;
cost = DVD_price;
}//Constructor end

//main method begins execution of Java application

public static void main(String[] args) {
// TODO code application logic here

boolean stop = false; //controls if loop below executed while (!stop)
{
// create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);

System.out.println("Welcome to DVD World");

System.out.print("Enter DVD name or stop to quit: ");// prompt
String DVD_name = input.nextLine(); // read DVD name entered

if (DVDname.equals("stop")) // check for sentinal
{
System.out.println("Thank you, this program has ended.");
stop = true;
} else {
float DVD_number;// First number
float DVD_price;// Second number multiplied
float total;// Total of DVD_number*DVD_price

System.out.print("Enter the number of DVD:");// prompt
DVD_number = input.nextFloat();// read number of DVDs
while (DVD_number <= 0)// Validate for positive number
{
System.out.println();// Enter blank line
System.out.println("Please enter the number of DVDs again:");
DVD_number = input.nextFloat();// read number of DVDs
System.out.println();// Enter blank line
}
System.out.print("Enter the amount of the DVDs:");// prompt
DVD_price = input.nextFloat();// read price of DVD
while (DVD_price <= 0)// validate for positive number
{
System.out.println();// Enter a blank line
System.out.println("DVD_number must be a positive number. No negative numbers allowed.");
System.out.print("Please enter the number of DVDs again:");
DVD_price = input.nextFloat(); //read price of DVD
System.out.println();// Enter a blank line
}
total = (float) DVD_number * DVD_price; // Multiply DVD_price by number of DVD_number
System.out.println();//Enter blank line
System.out.println("DVD_name:"); //display name
System.out.println("Number of DVDs" + DVD_number);//display number of DVDs
System.out.printf("DVD_price: $%,.2f\n", total);//display total
System.out.println();//Enter's blank line
System.out.println();//Enter's blank line
}// end else
}// end while
}//end main
}// end program
Last edited by WVTraveler1 : Oct 17th, 2007 at 8:45 am.
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,090
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 307
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Help with ending a program

  #4  
Oct 17th, 2007
Well, if you don't start your while loop within a comment, it will probably exit as you expect.
         boolean stop = false; //controls if loop below executed while (!stop)
        {
Reply With Quote  
Join Date: Feb 2006
Posts: 1,517
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Help with ending a program

  #5  
Oct 17th, 2007
I'm sorry, but, if you're not even willing to try, why should I. I gave you what you need to fix yourproblem, regardless of whether or not "Java is your bailiwick". And, if you're opening and closing braces in comments, it's not surprising it doesn't work.
Last edited by masijade : Oct 17th, 2007 at 5:37 pm. Reason: typo
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: WVTraveler1 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
WVTraveler1 WVTraveler1 is offline Offline
Newbie Poster

Re: Help with ending a program

  #6  
Oct 26th, 2007
Originally Posted by masijade View Post
I'm sorry, but, if you're not even willing to try, why should I. I gave you what you need to fix yourproblem, regardless of whether or not "Java is your bailiwick". And, if you're opening and closing braces in comments, it's not surprising it doesn't work.


Not willing to try? I am trying and have been for almost 9 weeks! You asked me for more than just the end and that is what I included. You seem to forget that not everyone is a programmer and that some of us are TRYING to learn, we won't get it immediately. I have checked every brace and can not find where you refer. You should be a little nicer when commenting instead of demeaning someone who is attempting to learn.
Reply With Quote  
Join Date: Oct 2007
Posts: 17
Reputation: uonsin is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
uonsin uonsin is offline Offline
Newbie Poster

Re: Help with ending a program

  #7  
Oct 27th, 2007
if you are trying to exit the program if a condition is met if stop == false
boolean stop = false; //controls if loop below executed while (!stop)
{

have you try an if statement to check for that condition that will make the program abort
while ( ...... )
{
if(condition to abort)
break;
else
code of the program
}

at least that is what i usually do to abort a program or if you want to check for that condition as soon as the program starts just put the while loop in the else
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Help with ending a program

  #8  
Oct 27th, 2007
Originally Posted by WVTraveler1 View Post
I have checked every brace and can not find where you refer. You should be a little nicer when commenting instead of demeaning someone who is attempting to learn.


I doubt this, since every { must have a matching }. In your program this ain't true. So quit moaning and fix it honey.

import java.util.Scanner;

class Inventory
{
  private String NameOfItem;
  private int NameOfItems; 

  public Inventory()
  {
    String inventoryName = null;
    int items = 0;
  }
  public String getNameOfItem()
  {
    return this.getNameOfItem();
  }
  public int items()
  {
    return this.items();
  }
  public void setNameOfItem ( String name )
  {
    this.NameOfItem = name;
  }
  public void setNameOfItem ( int item )
  {
    this.NameOfItem = NameOfItem;
  }
} 

class DVD
{ 
  public DVD()
  {} 

  public static void main ( String[] args )
  {
    Inventory Set[] = new Inventory[4];

    Set[0] = new Inventory();
    Set[0].setNameOfItem ( "Breakdown Palace" );
    Set[0].getNameOfItem();
    inventory.add ( dvd );

    Set[1] = new Inventory();
    Set[1].setNameOfItem ( "The Incredibles" );
    Set[1].getNameOfItem();
    inventory.add ( dvd );

    Set[2] = new Inventory();
    Set[2].setNameOfItem ( "Click" );
    Set[2].getNameOfItem();
    inventory.add ( dvd );

    Set[3] = new Inventory();
    Set[3].setNameOfItem ( "The Man" );
    Set[3].getNameOfItem();
    inventory.add ( dvd );

    Set[4] = new Inventory();
    Set[4].setNameOfItem ( "Christmas with the Kranks" );
    Set[4].getNameOfItem();
    inventory.add ( dvd );

    Set[5] = new Inventory();
    Set[5].setNameOfItem ( "Roll Bounce" );
    Set[5].getNameOfItem();
    inventory.add ( dvd );

    Set[6] = new Inventory();
    Set[6].setNameOfItem ( "American Outlaws" );
    Set[6].getNameOfItem();
    inventory.add ( dvd );
  }
} 

class FeatDVD extends DVD
{
  private String genres; 
  FeatDVD ( int item, String title, int stock, double price, String genres )
  {
    super ( item, title, stock, price );
    this.genres = genres;
  }
  public String getGenres()
  {
    return genres;
  }

  public double getValue()
  {
    double value = 1.05F * super.getValue();
    return value;
  }

  public String toString()
  {
    return super.toString() + "Genre:" + genres;
  }
} 


class Inventory
{

} 
public Inventory()
{

} 

{
  private DVD_name[];
  private number;
  private String name;

} 
public Inventory ( String DVD_name, number, DVD_price )
{
  String name = DVD_name;
  stock = DVD_number;
  cost = DVD_price;
} 
// <--wtf is this all doing? Consider rewriting this

public static void main ( String[] args )
{ 
  boolean stop = false;
  {
    Scanner input = new Scanner ( System.in );

    System.out.println ( "Welcome to DVD World" );

    System.out.print ( "Enter DVD name or stop to quit: " );
    String DVD_name = input.nextLine();

    if ( DVDname.equals ( "stop" ) )
    {
      System.out.println ( "Thank you, this program has ended." );
      stop = true;
    }
    else
    {
      float DVD_number;
      float DVD_price;
      float total;

      System.out.print ( "Enter the number of DVD:" );
      DVD_number = input.nextFloat();
      while ( DVD_number <= 0 )
      {
        System.out.println();
        System.out.println ( "Please enter the number of DVDs again:" );
        DVD_number = input.nextFloat();
        System.out.println();
      }
      System.out.print ( "Enter the amount of the DVDs:" );
      DVD_price = input.nextFloat();
      while ( DVD_price <= 0 )
      {
        System.out.println();
        System.out.println ( "DVD_number must be a positive number. No negative numbers allowed." );
        System.out.print ( "Please enter the number of DVDs again:" );
        DVD_price = input.nextFloat();
        System.out.println();
      }
      total = ( float ) DVD_number * DVD_price;
      System.out.println();
      System.out.println ( "DVD_name:" );
      System.out.println ( "Number of DVDs" + DVD_number );
      System.out.printf ( "DVD_price: $%,.2f\n", total );
      System.out.println();
      System.out.println();
    }
  }
}
} //<- wtf

Oh and if you hit compile and run at the very end after writing the whole thing, take this as a lesson learnt. Hit compile and run as many times as you can after every method written, so you can fix the errors bit by bit instead of all at the end!
Last edited by iamthwee : Oct 27th, 2007 at 5:37 am.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Feb 2006
Posts: 1,517
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is online now Online
Posting Virtuoso

Re: Help with ending a program

  #9  
Oct 27th, 2007
Originally Posted by WVTraveler1 View Post
Not willing to try? I am trying and have been for almost 9 weeks! You asked me for more than just the end and that is what I included. You seem to forget that not everyone is a programmer and that some of us are TRYING to learn, we won't get it immediately. I have checked every brace and can not find where you refer. You should be a little nicer when commenting instead of demeaning someone who is attempting to learn.


Why the hell should I try to sugarcoat what I tell you? And why the hell should I do your work for you? I not only told you that we would need the rest of the code, I also told you what the error meant, and how to fix it. Considering that, it was expected that you do that before posting the code, then only posting the code if there was still a problem (probably a different one), and you didn't, that is showing no effort. Checking the braces is easy. Simply count up for each opening and down for each closing, and you should end at 0. Then, if that's the case, and it still doesn't work, then start looking closer to ensure that none of the blocks "overlap". How is that so hard? And why should anyone have to it for you? And as far as showing no effort? Posting your code and saying do it for me, is showing no effort. And complaining when someone makes a suggestion (regardless of the language used), because they haven't done it for you, is showing no effort. That shows that you simply want someone to do it for you, not "help" in completing it. "Help" is when someone tells you what you're doing wrong, and how to fix it. If they then, do the fix for you, it is no longer "helping", but "cheating", whether it concerns homework, work, or hobby, doesn't matter.
Last edited by masijade : Oct 27th, 2007 at 5:43 am. Reason: typo
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,090
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 307
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Help with ending a program

  #10  
Oct 27th, 2007
Well, matching braces or no, unless the while loop statement is moved from the end of the comment on the boolean "stop", you won't even have a loop. Statements in comments don't execute so well
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 5:17 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC