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;
Code Java:
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
Code Java:
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
Re: Dont understand what to write.. :/
Code java:
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;
}
}
Code java:
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;
}
}