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: Dont understand what to write.. :/

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dont understand what to write.. :/

    any help is appreciated!

    This is for an assignment, its quite basic stuff as were new to it and i went through the practise stuff in the book so i thought id get it but im stuck whenn it comes to this work, Grr!

    ok so the questions are;
    "2.1 Add an Order class to your project to store the following information about an Order: the Order's reference number, the customer's name , a description and total cost. In addition, the class also stores the order's call-in time and the delivered time (all of type Time).

    2.2 Write a constructor which sets the order reference number, customer name, description, total cost and call-in time from suitable formal parameters. Call-in time should be represented by two formal parameters of type int which are passed as actual parameters to a Time constructor. The delivered time should initially be set to null."

    Im having problems with making this "Order" class, i get confused where the two classes mix :/

    this is some of the time class;
    public class Time
    {
        //fields
        private int hour;
     
        private int minute;
     
     
        //constructor
        public Time ()
        {
            hour = 0;
            minute = 0;
        }
     
       //method
    private void setHour(int newHour)
        {
            if ((newHour >= 0) & (newHour < 24)) {
                hour = newHour;
            }
            else{
            hour=0;
        }
    //##more methods down here##
    }
    and well heres what ivei done in the "Order" class which im supposed to be doing now
    public class Order
    {
        // 2.1 - fields
        private int orderNumber;
        private String customerName;
        private String description;
        private int totalCost;
        private Time callInTime;
        private Time deliveredTime;
     
        //2.2 - constructor
        public Order (int newOrderNumber, String newCustomerName, String newDescription, int newTotalCost )
        {
            orderNumber = newOrderNumber;
            customerName = newCustomerName;
            description = newDescription;
            totalCost = newTotalCost;
            callInTime = ;
            deliveredTime = ;
     
        }
    thanks for any help
    Last edited by helloworld922; December 4th, 2010 at 07:27 PM.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Dont understand what to write.. :/

     
    private int hour;
    private int minute;
    private String time;
     
    public Time(int hour, int minute)
    {
    hour = this.hour;
    minute = this.minute;
    }
     
    public void setHour(int hour)
    {
    if (hour <=12 && hour >=1)
    this.hour = hour;
    else
    this.hour = 12;
    }
     
    public int getHour()
    {
    return hour;
    }
     
    public void setMinute(int minute)
    {
    if (minute >= 0 && minute <=59)
    this.minute = minute;
     
     
    else
    this.minute = 0;
    }
     
    public int getMinute()
    {
    return minute;
    }
     
    /*
    if you need seconds, change the Time constructor to include int second and include the following methods, plus add int second to setTime.
    and create variable int second
     
    public void setSecond (int second)
    {
    if (second >=0  && second <=59)
    this.second = second;
    else
    this.second = 0;
    }
     
    public int getSecond()
    {
    return second;
    }
     
    */
     
    // sets the time to hour:minute
    // if minute >
    public void setTime(int hour, int minute)
    {
    if (hour >=1 && hour <=12)
    {
    if (minute >=10 && minute <=59)
    time = hour + ":" + minute;
    else if (minute < 10 && minute >=0)
     
    time = hour + ":0" + minute;
     
     
    else
    time = hour + ":00";
    }
     
    else 
    {
    if (minute >=10 && minute <=59)
    time = "12:" + minute;
    else if (minute < 10 && minute >=0)
     
    time = "12:0" + minute;
     
     
    else
    time = "12:00";
     
    }
    }
     
     
    // returns time
    public String getTime()
    {
    return time;
    }
    }

    private int orderNumber;
    private String customerName;
    private String description;
    private double totalCost; // usually cost has decimal points
    // but if not, use int
    private Time callInTime;
    private Time deliveredTime;
    public Order (int newOrderNumber, String newCustomerName, String newDescription, double newTotalCost, int hour, int minute)
    {
    orderNumber = newOrderNumber;
            customerName = newCustomerName;
            description = newDescription;
            totalCost = newTotalCost;
           callInTime = new Time(hour,minute);
            deliveredTime = null;
     
     
    }
     
    public int  getOrderNumber()
    {
    return orderNumber;
    }
     
    public void setOrderNumber(int orderNumber)
    {
    this.orderNumber = orderNumber;
    }
     
    public void setCustomerName(String customerName)
    {
    this.customerName = customerName;
    }
     
    public String getCustomerName()
    {
    return customerName;
    }
     
    public void setDescription(String description)
    {
    this.description = description;
    }
     
    public String getDescription()
    {
    return description;
    }
     
    public void setTotalCost(double totalCost)
    {
    this.totalCost = totalCost;
    }
     
    public double getTotalCost()
    {
    return totalCost;
    }
     
    public void setCallInTime(int hour, int minute)
    {
    callInTime = new Time(hour, minute);
    }
     
    // this returns the Time object getCallInTime, which is needed to call Time method getTime() in method below this one which returns the String time
    public Time getCallInTime()
    {
    return callInTime;
    }
     
    public String getCallInTime2()
    {
    return callInTime.getTime();
    }
    public void setDeliveredTime(int hour, int minute)
    {
    deliveredTime = new Time(hour, minute);
    }
     
    public Time getDeliveredTime()
    {
    return deliveredTime;
    }
     
    public String getDeliveredTime2()
    {
    return deliveredTime.getTime();
    }
     
    public String toString()
    {
    String str = "Order number is: " + getOrderNumber() + ". Customer name is: " + getCustomerName() + ". Description is: " + getDescription() + ". Total cost is: " + getTotalCost() + ".  Call in time is: " + getCallInTime2() + ". Delivered time is: " + getDeliveredTime2() + ".";
    return str;
    }
    }
    Last edited by javapenguin; December 4th, 2010 at 11:26 PM.

Similar Threads

  1. Dont know whats happening
    By JJTierney in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 4th, 2010, 11:50 AM
  2. [SOLVED] I dont know how to complete this code?
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 21st, 2010, 09:07 AM
  3. I dont get it....please help
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 30th, 2010, 03:16 AM
  4. Dont laugh at me
    By Neblin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2009, 08:18 AM
  5. How to write above a JPanel
    By bruno88 in forum AWT / Java Swing
    Replies: 4
    Last Post: June 23rd, 2009, 06:16 PM