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 7 of 7

Thread: Understanding Classes and Objects

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

    Default Understanding Classes and Objects

    Hey everyone. Before I post my error and my code I just wanted to explain my situation and say thanks for the help. I am in college and this is a project assignment. I don't want anyone to help me for a second, I just need help in understanding what's going on. We have recently moved into "Classes and Objects". If you need anymore information after I post my code, I will gladly supply it. Thanks for helping!
    /**************************************************************************************
    * ------------------------------------------------------------------------------------
    * File name: BookOrder.java
    * Project name: CSCI 1250 Project 4
    * ------------------------------------------------------------------------------------
    * Author Name: Austin Stanley
    * Author E-mail: 
    * Course-Section: CSCI-1250-001
    * Creation Date: 11/08/2012
    * Date of Last Modification: 11/08/2012
    * ------------------------------------------------------------------------------------
    */
    import java.util.Scanner; //Allow the user input from keyboard
     
    import java.text.DecimalFormat; //Allowing us to limit the Decimal Place
     
    /**************************************************************************************
    * Class Name: BookOrder <br>
    * Class Purpose: The class for our driver program <br>
    *
    * <hr>
    * Date created: 11/08/2102 <br>
    * Date last modified: 11/08/2012
    * @author Austin Stanley
    */
     
    public class BookOrder //The beginning of the BookOrder class
    {
    	//**********************CLASS ATTRIBUTES****************************
    	private String author; //Establishing the author variable
    	private String title; //Establishing the title variable
    	private int quantity; //Establishing the quantity variable
    	private double costPerBook; //Establising the costPerBook variable
    	private String orderDate; // Establishing the orderDate variable
    	private double weight; //Establishing the weight variable
    	private char shipType; //Establishing the shipType variable
     
    	//**********************CLASS METHODS*******************************
    	//-----------------------CONSTRUCTORS-------------------------------
    	public BookOrder()
    	{
    		setAuthor(" ");
    		setTitle(" ");
    		setQuantity(0);
    		setCostPerBook(0.0);
    		setOrderDate(" ");
    		setWeight(0.0);
    		setShipType(' ');
    	}//end BookOrder
     
    	public BookOrder(String authorName, String titleName)
    	{
    		setAuthor(authorName);
    		setTitle(titleName);
    	}//end BookOrder(String authorName, String titleName)
     
    	publc BookOrder(String authorName, String titleName, int quantityAmmount, double costPerBookAmmount, String orderDateName, double weightAmmount, char shipTypeLetter)
    	{
    		setAuthor(authorName);
    		setTitle(titleName);
    		setQuantity(quantityAmmount);
    		setCostPerBook(costPerBookAmmount);
    		setOrderDate(orderDateName);
    		setWeight(weightAmmount);
    		setShipType(shipTypeLetter);
     
    	}//end publc BookOrder(String authorName, String titleName, int quantityAmmount, double costPerBookAmmount, String orderDateName, double weightAmmount, char shipTypeLetter)
     
    	//--------------------------SETTERS---------------------------------
    	public void setAuthor(String authorName)
    	{
    		authorName = authorName;
    	}//end setAuthor
    	public void setTitle(String titleName)
    	{
    		titleName = titleName;
    	}//end setTitle
    	public void setQuantity(int quantityAmmount)
    	{
    		quantityAmmount = quantityAmmount;
    	}//end setQuantity
    	public void setCostPerBook(double costPerBookAmmount)
    	{
    		costPerBookAmmount = costPerBookAmmount;
    	}//end setCostPerBook
    	public void setOrderDate(String orderDateName)
    	{
    		orderDateName = orderDateName;
    	}//end setOrderDate
    	public void setWeight(double weightAmmount)
    	{
    		weightAmmount = weightAmmount;
    	}//end setWeight
    	public void setShipType(char shipTypeLetter)
    	{
    		shipTypeLetter = shipTypeLetter;
    	}//end setShipType
    	//--------------------------GETTERS---------------------------------
    	public String getAuthor()
    	{
    		return authorName;
    	}//end getAuthor
    	public String getTitle()
    	{
    		return titleName;
    	}//end getTitle
    	public int getQuantity()
    	{
    		return quantityAmmount;
    	}//end getQuantity
    	public double getCostPerBook()
    	{
    		return costPerBookAmmount;
    	}//end getCostPerBook
    	public String getOrderDate()
    	{
    		return orderDateName;
    	}//end getOrderDate
    	public double getWeight()
    	{
    		return weightAmmount;
    	}//end getWeight
    	public char getShipType()
    	{
    		return shipTypeLetter;
    	}//end getShipType
    	//---------------------OTHER CLASS METHODS--------------------------
     
     
    }//end BookOrder
    Last edited by pbrockway2; November 8th, 2012 at 02:21 AM. Reason: code tags added


  2. #2
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Understanding Classes and Objects

    Let me know what error are you getting exactly !!

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

    Default Re: Understanding Classes and Objects

    Sorry about that. I thought I included it. Here is the error I get from Command Prompt.


    E:\IntroToComputerSci\Programs\Project4>javac BookOrder.java
    BookOrder.java:57: error: cannot find symbol
    publc BookOrder(String authorName, String titleName, int quantityAmmount
    , double costPerBookAmmount, String orderDateName, double weightAmmount, char sh
    ipTypeLetter)
    ^
    symbol: class publc
    location: class BookOrder
    BookOrder.java:101: error: cannot find symbol
    return authorName;
    ^
    symbol: variable authorName
    location: class BookOrder
    BookOrder.java:105: error: cannot find symbol
    return titleName;
    ^
    symbol: variable titleName
    location: class BookOrder
    BookOrder.java:109: error: cannot find symbol
    return quantityAmmount;
    ^
    symbol: variable quantityAmmount
    location: class BookOrder
    BookOrder.java:113: error: cannot find symbol
    return costPerBookAmmount;
    ^
    symbol: variable costPerBookAmmount
    location: class BookOrder
    BookOrder.java:117: error: cannot find symbol
    return orderDateName;
    ^
    symbol: variable orderDateName
    location: class BookOrder
    BookOrder.java:121: error: cannot find symbol
    return weightAmmount;
    ^
    symbol: variable weightAmmount
    location: class BookOrder
    BookOrder.java:125: error: cannot find symbol
    return shipTypeLetter;
    ^
    symbol: variable shipTypeLetter
    location: class BookOrder
    8 errors

    E:\IntroToComputerSci\Programs\Project4

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Understanding Classes and Objects

    CSCI 1250 Project 4 Fall 2012.doc

    That is also the Coding project requirement page if it helps you understand what I am asking. Sorry for the noobish...well the noobish everything. Thanks again.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Understanding Classes and Objects

    U had declared variables but didn't assigned the values yet.
    It is suggestion that u must know about "local variable and class variable " and u must know about "this" keyword in java it help in rectifying your bugs.

  6. #6
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Understanding Classes and Objects

    What does that mean though...Sorry noob here.

  7. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Understanding Classes and Objects

    Quote Originally Posted by AustinStanley View Post
    What does that mean though...Sorry noob here.
    public void setAuthor(String authorName)
    {
    authorName = authorName;
    }

    here compiler gets ambiguity because of parameter of function and class variable having same name.
    public void setAuthor(String authorName)
    {
    this.authorName = authorName;
    }
    here 'this.authorName' is class variable , 'authorName' is functional parameter.
    Just check your code.

Similar Threads

  1. Difficulty with understanding interaction between Classes
    By JBRPG in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 14th, 2012, 07:16 AM
  2. Replies: 3
    Last Post: July 8th, 2012, 03:44 PM
  3. Creating classes with generic objects
    By rbt in forum Collections and Generics
    Replies: 2
    Last Post: April 23rd, 2012, 08:08 PM
  4. NEEDING HELP UNDERSTANDING A CODE FROM THREE CLASSES!!!
    By BlackShadow in forum Java Theory & Questions
    Replies: 1
    Last Post: April 6th, 2012, 10:11 PM
  5. NEEDING HELP UNDERSTANDING A CODE FROM THREE CLASSES!!!
    By BlackShadow in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 5th, 2012, 09:29 AM