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

Thread: Beginner struggling with homework question

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Beginner struggling with homework question

    Hello, I'm struggling with this java programming question

    Create a class named Invoice that holds an invoice number, balance due and three fields representing the month, day, and year that the balance is due. Create a constructor that accepts values for all five data fields within the constructor, assign each argument to the appropriate field with the following exceptions:
    -if an invoice number is less than 1000, force the invoice number to 0
    -if the month field is less than 1 or grater than 12, force the month field to 0
    -if the day field is less than 1 or greater than 31, force the day field to 0
    -if the year field is les than 2011 or greater than 2017, force the year field to 0

    In the invoice class, include a display method that displays all the fields on an Invoice object.

    I'm completely lost on what to do next. Hope you guys can help, this is what I currently have

    public class Invoice{
    private String month,day,year;
    private double BalanceDue;
    private double InvoiceNumber;
    public Invoice(String m, String d, String y, double balance, double number){
    m=month;
    d=day;
    y=year;
    balance=BalanceDue;
    number=InvoiceNumber;}
    }


  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: Beginner struggling with homework question

    First off you need to switch around your assignment statements. Your constructors purpose is to set the values of the object to that of the parameters passed to it.

Similar Threads

  1. Homework question having to do with arrays...
    By TheoAnderson in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 3rd, 2013, 12:55 PM
  2. Predicting the Outcome without a compiler **Not a Homework Question**
    By sternfox in forum Java Theory & Questions
    Replies: 1
    Last Post: February 25th, 2013, 04:53 PM
  3. [SOLVED] Homework Question
    By EPC in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 24th, 2013, 01:33 PM
  4. Question about homework problem.
    By Rain_Maker in forum Java Theory & Questions
    Replies: 13
    Last Post: February 7th, 2013, 08:11 PM
  5. Homework assignment (beginner)
    By z3ohyr84 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 30th, 2011, 01:32 PM