In: Computer Science
Part four: using JDBC with mysql for project management program. I cannot copy the whole code, so will split it into a few parts.
See part one and two and three.
Part four of The code is (starts at line 499, rest of code):
}
}
catch (Exception e)
{
e.printStackTrace();
}
if (foundSomething)
{
// pass
}
else
{
System.out.print("Search result is empty!\n");
}
goBacktoMenu(); // go back to main menu
}
static void finalizeMenu(ArrayList<ProjectDetails>
projectList)
{
System.out.print("========================Finalize
project==========================\n\n");
System.out.print("Note that there are currently " + projectNum + "
project(s) registered.\n"
+ "Project numbers start from 1\n");
if (projectNum == 0)
{ // there are 0 projects do not allow user to continue
return;
}
System.out.print("\nEnter the project number you want to finalize:
");
int index = 0;
try
{
String i = userInput.nextLine();
index = Integer.parseInt(i); // convert user input to integer
}
catch (Exception e)
{
System.out.print("**wrong input format!**");
return;
}
index = index - 1; // subscript start at 0
if (index >= 0 && index < projectNum &&
projectList.isEmpty() == false && projectList.get(index) !=
null)
{
System.out.print("\n\n"); // newlines
projectList.get(index).finalizeProject(projectList.get(index));
}
else
{
System.out.print("Make sure you enter a valid project
number!\n");
}
}
static void getExistingProjects(ArrayList<ProjectDetails>
projectList) throws FileNotFoundException
{
ArrayList<String> list = new ArrayList<String>(); //
list will store projects from txt file
ProjectDetails proj = new ProjectDetails(); // create project
object that will be stored in projectList
proj.setProjectName(list.get(0));
boolean finalized =
Boolean.parseBoolean(list.get(1));
proj.setIsFinalized(finalized);
proj.setBuildingType(list.get(2));
proj.setPhysicalAddress(list.get(3));
proj.setErfNum(list.get(4));
proj.setTotalFee(Double.parseDouble(list.get(5)));
proj.setTotalPaidtoDate(Double.parseDouble(list.get(6)));
LocalDate dateObj = null;
DateTimeFormatter myFormatObj = null;
myFormatObj =
DateTimeFormatter.ofPattern("yyyy-MM-dd"); // format how date
object will be
dateObj = LocalDate.parse(list.get(7),
myFormatObj);
proj.setDate(dateObj); // project date assigned
dateObj = LocalDate.parse(list.get(8),
myFormatObj);
proj.setProjectDeadline(dateObj); // project
deadline
ProjectDetails.setCustomer(list.get(9), list.get(10),
list.get(11), list.get(12), "customer");
ProjectDetails.setArchitect(list.get(13),
list.get(14), list.get(15), list.get(16), "architect");
ProjectDetails.setContractor(list.get(17),
list.get(18), list.get(19), list.get(20), "contractor");
projectList.add(proj); // add project to the list of
projects
proj.setProjectNum(++projectNum); // increment number
of projects
list.clear(); // list is cleared for next new
project
for(ProjectDetails obj: projectList)
{
displayExistingProjects(obj); // display projects to
the user
}
goBacktoMenu(); // Function to go back to main menu.
}
// Method to go back to main menu.
static void goBacktoMenu()
{
System.out.print("\n*** Press enter to go back to main menu
***\n");
try
{
System.in.read();
}
catch (Exception e)
{
}
}
public static void displayExistingProjects(ProjectDetails
proj)
{
String content = " "; // this variable will store all information
pertaining to the project
content = "**************Project number: " + proj.getProjectNum() +
" ************************\n\n";
content += "Is project finalized ?: " + proj.isFinalized() +
"\n";
content += "Project name: " + proj.getProjectName() + "\n";
content += "Type of building: " + proj.getBuildingType() +
"\n";
content += "The physical address for the project: " +
proj.getPhysicalAddress() + "\n";
content += "ERF number: " + proj.getErfNum() + "\n";
content += "The total fee charged for the project: " +
proj.getTotalFee() + "\n";
content += "The total amount paid to date: " +
proj.getTotalPaidtoDate() + "\n";
DateTimeFormatter myFormatObj;
myFormatObj = DateTimeFormatter.ofPattern("dd MMMM yyyy");
String formattedDate = proj.getDate().format(myFormatObj);
content += "Project date assigned: " + formattedDate + "\n";
formattedDate =
proj.getProjectDeadline().format(myFormatObj);
content += "Project deadline: " + formattedDate + "\n";
content += "\n";
content += "Customer\'s details:\n";
content += "Name: " + proj.getCustomer().getName() + "\n";
content += "Email: " + proj.getCustomer().getEmail() + "\n";
content += "Telephone: " + proj.getCustomer().getTelNum() +
"\n";
content += "address: " + proj.getCustomer().getPhysicalAddress() +
"\n";
content += "\n";
content += "Architect\'s details:\n";
content += "Name: " + proj.getArchitect().getName() + "\n";
content += "Email: " + proj.getArchitect().getEmail() + "\n";
content += "Telephone: " + proj.getArchitect().getTelNum() +
"\n";
content += "address: " + proj.getArchitect().getPhysicalAddress() +
"\n";
content += "\n";
content += "Contractor\'s details:\n";
content += "Name: " + proj.getContractor().getName() + "\n";
content += "Email: " + proj.getContractor().getEmail() +
"\n";
content += "Telephone: " + proj.getContractor().getTelNum() +
"\n";
content += "address: " + proj.getContractor().getPhysicalAddress()
+ "\n\n";
System.out.print(content); // display projects
}
}
VHDL: Creating a Hierarchical Design
This example describes how to create a hierarchical design using VHDL. The top-level design, called top.vhd, implements an instance of the function logic.vhd. In the top.vhd file, a component for the logic function is declared inside the architecture in which it is instantiated. The Component Declaration defines the ports of the lower-level function.
Related Links
For more information on using this example in your project, refer to the How to Use VHDL Examples section on the VHDL web page.
top.vhd (Top-level file)
LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY top IS PORT(w_in, x_in, y_in :IN std_logic; clock :IN std_logic; z_out :OUT std_logic); END top; ARCHITECTURE a OF top IS COMPONENT logic PORT(a,b,c :IN std_logic; x :OUT std_logic); END COMPONENT; SIGNAL w_reg, x_reg, y_reg, z_reg :std_logic; BEGIN low_logic : logic PORT MAP (a => w_reg, b => x_reg, c => y_reg, x => z_reg); PROCESS(clock) BEGIN IF (clock'event AND clock='1') THEN w_reg<=w_in; x_reg<=x_in; y_reg<=y_in; z_out<=z_reg; END IF; END PROCESS; END a; </PRE>
logic.vhd
LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY logic IS PORT(a,b,c : IN std_logic; x : OUT std_logic); END logic; ARCHITECTURE a OF logic IS BEGIN PROCESS (a,b,c) BEGIN x<=(a and b) or c; END PROCESS; END; </pre>