Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By SurfMan

Thread: New to Java. Need help writing code. (Classes and Objects)

  1. #1
    AustinStanley is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default New to Java. Need help writing code. (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



    This is all apart of a class that will be used by a "driver program" I have yet to write. Thanks again.

  2. #2
    AustinStanley is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: New to Java. Need help writing code. (Classes and Objects)

    I also receive this error while trying to compile

    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.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: New to Java. Need help writing code. (Classes and Objects)

    The first error is a typo: it' 'public', not 'publc' and it upsets the compiler and it starts spewing many error messages; fix the typo and compile again.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,028
    Rep Power
    4

    Default Re: New to Java. Need help writing code. (Classes and Objects)

    - The large constructor has a typo: publc
    - The getters that you define are not returning the fields in your class. For example, you have a field author, but getAuthor() is returning authorName, which doesn't exist.
    Hint: the compiler is always right:
    symbol: variable authorName
    location: class BookOrder
    BookOrder.java:105: error: cannot find symbol
    - Your setters assign values to the parameter instead of the class field:
    Java Code:
    public void setAuthor(String authorName) {
       authorName = authorName;
    }
    Since authorName is not a field, you assign the value of the parameter to the... parameter. This would be better:
    Java Code:
    public void setAuthor(String authorName) {
       this.author = authorName;
    }
    Kagiso likes this.

  5. #5
    AustinStanley is offline Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Default Re: New to Java. Need help writing code. (Classes and Objects)

    Sorry about that, it still left me with the following errors


    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>javac BookOrder.java
    BookOrder.java:62: error: cannot find symbol
    authorName2 = authorName;
    ^
    symbol: variable authorName2
    location: class BookOrder
    BookOrder.java:66: error: cannot find symbol
    titleName2 = titleName;
    ^
    symbol: variable titleName2
    location: class BookOrder
    BookOrder.java:70: error: cannot find symbol
    quantityAmmount2 = quantityAmmount;
    ^
    symbol: variable quantityAmmount2
    location: class BookOrder
    BookOrder.java:74: error: cannot find symbol
    costPerBookAmmount2 = costPerBookAmmount;
    ^
    symbol: variable costPerBookAmmount2
    location: class BookOrder
    BookOrder.java:78: error: cannot find symbol
    orderDateName2 = orderDateName;
    ^
    symbol: variable orderDateName2
    location: class BookOrder
    BookOrder.java:82: error: cannot find symbol
    weightAmmount2 = weightAmmount;
    ^
    symbol: variable weightAmmount2
    location: class BookOrder
    BookOrder.java:86: error: cannot find symbol
    shipTypeLetter2 = shipTypeLetter;
    ^
    symbol: variable shipTypeLetter2
    location: class BookOrder
    BookOrder.java:91: error: cannot find symbol
    return authorName2;
    ^
    symbol: variable authorName2
    location: class BookOrder
    BookOrder.java:95: error: cannot find symbol
    return titleName2;
    ^
    symbol: variable titleName2
    location: class BookOrder
    BookOrder.java:99: error: cannot find symbol
    return quantityAmmount2;
    ^
    symbol: variable quantityAmmount2
    location: class BookOrder
    BookOrder.java:103: error: cannot find symbol
    return costPerBookAmmount2;
    ^
    symbol: variable costPerBookAmmount2
    location: class BookOrder
    BookOrder.java:107: error: cannot find symbol
    return orderDateName2;
    ^
    symbol: variable orderDateName2
    location: class BookOrder
    BookOrder.java:111: error: cannot find symbol
    return weightAmmount2;
    ^
    symbol: variable weightAmmount2
    location: class BookOrder
    BookOrder.java:115: error: cannot find symbol
    return shipTypeLetter2;
    ^
    symbol: variable shipTypeLetter2
    location: class BookOrder
    14 errors

    E:\IntroToComputerSci\Programs\Project4>javac BookOrder.java
    BookOrder.java:91: error: cannot find symbol
    return authorName;
    ^
    symbol: variable authorName
    location: class BookOrder
    BookOrder.java:95: error: cannot find symbol
    return titleName;
    ^
    symbol: variable titleName
    location: class BookOrder
    BookOrder.java:99: error: cannot find symbol
    return quantityAmmount;
    ^
    symbol: variable quantityAmmount
    location: class BookOrder
    BookOrder.java:103: error: cannot find symbol
    return costPerBookAmmount;
    ^
    symbol: variable costPerBookAmmount
    location: class BookOrder
    BookOrder.java:107: error: cannot find symbol
    return orderDateName;
    ^
    symbol: variable orderDateName
    location: class BookOrder
    BookOrder.java:111: error: cannot find symbol
    return weightAmmount;
    ^
    symbol: variable weightAmmount
    location: class BookOrder
    BookOrder.java:115: error: cannot find symbol
    return shipTypeLetter;
    ^
    symbol: variable shipTypeLetter
    location: class BookOrder
    7 errors

    E:\IntroToComputerSci\Programs\Project4>javac BookOrder.java
    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
    7 errors

    E:\IntroToComputerSci\Programs\Project4>

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default Re: New to Java. Need help writing code. (Classes and Objects)

    See reply #3 again.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: New to Java. Need help writing code. (Classes and Objects)

    You only need to paste the one compilation run.
    You have several there in that post.

    Taking the last lot, where is the variable 'authorName' declared?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. java question on classes & objects
    By joe98 in forum New To Java
    Replies: 16
    Last Post: 04-08-2011, 10:45 AM
  2. help writing a java code
    By joshsmith3400 in forum Forum Lobby
    Replies: 1
    Last Post: 02-02-2011, 08:06 AM
  3. Need help on writing Java source code
    By k4it0xtr3me in forum New To Java
    Replies: 29
    Last Post: 01-24-2011, 04:56 PM
  4. How to Lookup Code for Java API Classes
    By user0 in forum New To Java
    Replies: 2
    Last Post: 12-30-2010, 05:37 AM
  5. Is this the right way of writing html code in java??
    By raju.i in forum Advanced Java
    Replies: 1
    Last Post: 05-18-2010, 09:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •