Heyas, I'm struggling to come up with some working code for a piece of software I've to make. I know it's got something to do with Arrays, or array lists, which just so happen to be the one thing I missed in C and Java! Student life, eh? :P
Anyway, the thing I've to do is write a piece of software that permits a user to enter up to 100 contract details (ie. name, number, expected completion date). Although the user to enter an 'actual' completion date for the contracts, and finally, determines whether each contract was completed on schedule, and prints out the contracts completed late.
Any help would be great and yeah, I know it's a bit to ask, but, you don't ask, you don't get right? :P
The following is the code I've came up with so far, Apologies for the lack of indentation, it reset it all once posted:
Code:
import java.util.Scanner;
public class Contract {
class ContractArray {public static void main(String[] args) {String[] contArray; //Declares string of arrays
contArray = new String[100];
class Date
{ // propertiesprivate int day, month, year;
// methodspublic void readDate(){
// prompts for and reads in a Date from the keyboard
Scanner sc = new Scanner(System.in);do
{ System.out.print("Enter day: "); day = sc.nextInt();System.out.print("Enter month: ");month = sc.nextInt();System.out.print("Enter year: ");year = sc.nextInt();if (!validDate())System.out.println("Date not valid! Try again...");
}while (!validDate());
}//readDate
public boolean after(Date D){
// checks if a Date is after Date D
if (year > D.year)
return true;
else if ((year == D.year) && (month > D.month))
return true;
else if ((year == D.year) && (month == D.month) && (day > D.day))
return true;
else
return false;
}//after
public void printDate() {
System.out.println(day + "/" + month + "/" + year);
}//printDate
public boolean validDate()
{ if (!validYear(year))
return false;
else if (!validMonth(month))
return false;
else if (!validDay(day,month))
return false;
else
return true;
}//validDate
private boolean validYear(int y)
{ if ((y < 1990) || (y > 2100))
return false;
else
return true;
}//validYear
private boolean validMonth(int m)
{ if ((m < 0) || (m > 12))
return false;
else
return true;
}//validMonth
private boolean validDay(int d, int m)
{ if ((d < 0) || (d > daysinMonth(m)))
return false;
else
return true;
}//validDay
private int daysinMonth(int m)
{ int NumDays;
switch(m)
{ case 1:case 3:case 5:case 7:
case 8:case 10:case 12 : NumDays = 31;
break;
case 4:case 6:case 9:case 11:
NumDays = 30;
break;
case 2 : NumDays = 28;
break;
default: NumDays = 0;
}
return NumDays;
}//daysinMonth
} // end of class Date
public class contractRecord {
String custName;
String contractNum;
int cost;
int exCompDate;
// int actCompDate;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter Customer Name: ");
custName = sc.nextString();
System.out.println("Please enter Contract Number: ");
contractNum = sc.nextString();
System.out.println("Please enter Expected cost:£ ");
cost = sc.nextInt ();
System.out.println("Please enter Expected completion date (DDMMYYYY): ");
exCompDate = sc.nextInt();
// System.out.println("Please enter Actual completion date (DDMMYYYY): "); // Not meant for here.
// actCompDate = sc.nextInt();
}
//Run Date Class
/*
//if late
System.out.println("********* Contract Number: " + contractNum[]);
System.out.print("*********");
System.out.println("");
System.out.println("Customer: " + custName);
System.out.println("");
System.out.println("Expected Date of Completion: " + exCompDate);
System.out.println("");
System.out.println("Actual Date of Completion: " +actCompDate);
System.out.println("");
System.out.println("Cost:£ " + cost);
*/
}