12 Replies - 775 Views - Last Post: 03 August 2010 - 10:38 AM Rate Topic: -----

#1 dragon528  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-August 08

Seek for help, setter not working

Posted 03 August 2010 - 08:32 AM

This is my class file
class Asset{
	// Asset
	private int assetID;
	private String description;
	private String purcDate;
	private String orderNum;
	private double costPrice;
	private boolean status;

	// Non argument Constructure
	public Asset(){
	}

	// Argument Constructure
	public Asset(int assetID, String description, String purcDate, String orderNum, double costPrice, boolean status){
		this.assetID = assetID;
		this.description = description;
		this.purcDate = purcDate;
		this.orderNum = orderNum;
		this.costPrice = costPrice;
		this.status = status;
	}

	// Copy Constructor
	public Asset(Asset A){
		this.assetID = A.assetID;
		this.description = A.description;
		this.purcDate = A.purcDate;
		this.orderNum = A.orderNum;
		this.costPrice = A.costPrice;
		this.status = A.status;
	}

	// Setter Constructor
	public void setAssetID(int newAssetID){
		this.assetID = newAssetID;
	}

	public void setDescription(String newDescription){
		this.description = newDescription;
	}

	public void setPurcDate(String newPurcDate){
		this.purcDate = newPurcDate;
	}

	public void setOrderNum(String newOrderNum){
		this.orderNum = newOrderNum;
	}

	public void setCostPrice(double newCostPrice){
		this.costPrice = newCostPrice;
	}

	public void setStatus(boolean newStatus){
		this.status = newStatus;
	}

	// Getter Constructor
	public int getAssetID(){
		return assetID;
	}

	public String getDescription(){
		return description;
	}

	public String getPurcDate(){
		return purcDate;
	}

	public String getOrderNum(){
		return orderNum;
	}

	public double getCostPrice(){
		return costPrice;
	}

	public boolean getStatus(){
		return status;
	}

	// Equal Constructure
	public boolean equals(int assetID){
		if(this.assetID == assetID){
				return true;
			}else{
				return false;
			}
	}

	public String toString(){
		return "\nAssetID :"+assetID+"\nDescription :"+description+"\nPurchase Date :"+purcDate+"\nOrder No. :"+orderNum+"\nCost Price :"+costPrice+"\nStatus :"+status;
	}
}

class Appliance extends Asset{
			// Appliance
	private String appBrand;
	private String appModel;
	private int appSerial;
	private String appWarranty;
	private String appVendor;

	// Non Argument Constructer
	public Appliance(){
	}

	// Constructer with Argument
	public Appliance(int assetID, String description, String purcDate, String orderNum, double costPrice, boolean status,
						String appBrand, String appModel, int appSerial, String appWarranty, String appVendor){
		super(assetID, description, purcDate, orderNum, costPrice, status);
		this.appBrand = appBrand;
		this.appModel = appModel;
		this.appSerial = appSerial;
		this.appWarranty = appWarranty;
		this.appVendor = appVendor;
	}

	// Setter
	public void setAppBrand(String newAppBrand){
		this.appBrand = newAppBrand;
	}

	public void setAppModel(String newAppModel){
		this.appModel = newAppModel;
	}

	public void setAppSerial(int newAppSerial){
		this.appSerial = newAppSerial;
	}

	public void setAppWarranty(String newAppWarranty){
		this.appWarranty = newAppWarranty;
	}

	public void setAppVendor(String newAppVendor){
		this.appVendor = newAppVendor;
	}

	// Getter
	public String getAppBrand(){
		return appBrand;
	}

	public String getAppModel(){
		return appModel;
	}

	public int getAppSerial(){
		return appSerial;
	}

	public String getAppWarranty(){
		return appWarranty;
	}

	public String getAppVendor(){
		return appVendor;
	}	
		// Equal Constructure
	public boolean equals(int appSerial){
		if(this.appSerial == appSerial){
				return true;
			}else{
				return false;
			}
	}

	public String toString(){
		return super.toString()+"\nBrand :"+appBrand+"\nModel :"+appModel+"\nSerial :"+appSerial+"\nWarranty :"+appWarranty+"\nVendor :"+appVendor;
	}	
}

class Ict extends Asset{
			// ICT
	private String ictBrand;
	private String ictModel;
	private int ictSerialNo;
	private String ictWarranty;
	private String ictVendor;
	private String ictMaintenanceDate;

	// Non Argument Constructer
	public Ict(){
	}

	// Constructer With Argument
	public Ict(int assetID, String description, String purcDate, String orderNum, double costPrice, boolean status,
				String ictBrand, String ictModel, int ictSerialNo, String ictWarranty, String ictVendor, String ictMaintenanceDate){
		super(assetID, description, purcDate, orderNum, costPrice, status);
		this.ictBrand = ictBrand;
		this.ictModel = ictModel;
		this.ictSerialNo = ictSerialNo;
		this.ictWarranty = ictWarranty;
		this.ictVendor = ictVendor;
		this.ictMaintenanceDate = ictMaintenanceDate;
	}

	// Setter
	public void setIctBrand(String newIctBrand){
		this.ictBrand = newIctBrand;
	}

	public void setIctModel(String newIctModel){
		this.ictModel = newIctModel;
	}

	public void setIctSerialNo(int newIctSerialNo){
		this.ictSerialNo = newIctSerialNo;
	}

	public void setIctWarranty(String newIctWarranty){
		this.ictWarranty = newIctWarranty;
	}

	public void setIctVendor(String newIctVendor){
		this.ictVendor = newIctVendor;
	}

	public void setIctMaintenanceDate(String newIctMaintenanceDate){
		this.ictMaintenanceDate = newIctMaintenanceDate;
	}

	// Getter
	public String getIctBrand(){
		return ictBrand;
	}

	public String getIctModel(){
		return ictModel;
	}

	public int getIctSerialNo(){
		return ictSerialNo;
	}

	public String getIctWarranty(){
		return ictWarranty;
	}

	public String getIctVendor(){
		return ictVendor;
	}

	public String getIctMaintenanceDate(){
		return ictMaintenanceDate;
	}
	
		// Equal Constructure
	public boolean equals(int ictSerialNo){
		if(this.ictSerialNo == ictSerialNo){
				return true;
			}else{
				return false;
			}
	}

	public String toString(){
		return super.toString()+"\nBrand :"+ictBrand+"\nModel :"+ictModel+"\nSerial No. :"+ictSerialNo+"\nWarranty :"+ictWarranty+"\nVendor :"+ictVendor+"\nMaintenance :"+ictMaintenanceDate;
	}
}

class Vehicle extends Asset{
			// Vehichle
	private String vehMake;
	private String vehModel;
	private int vehEngineNo;
	private int vehChassisNo;
	private int vehRegistrationNo;
	private String vehWarranty;
	private String vehVendor;
	private String vehMaintenanceDate;

	// Non Argument Constructer
	public Vehicle(){
	}

	// Constructer with Argument
	public Vehicle(int assetID, String description, String purcDate, String orderNum, double costPrice, boolean status,
					String vehMake, String vehModel, int vehEngineNo, int vehChassisNo, int vehRegistrationNo, String vehWarranty, String vehVendor, String vehMaintenanceDate){
		super(assetID, description, purcDate, orderNum, costPrice, status);
		this.vehMake = vehMake;
		this.vehModel = vehModel;
		this.vehEngineNo = vehEngineNo;
		this.vehChassisNo = vehChassisNo;
		this.vehRegistrationNo = vehRegistrationNo;
		this.vehWarranty = vehWarranty;
		this.vehVendor = vehVendor;
		this.vehMaintenanceDate = vehMaintenanceDate;
	}

	// Setter
	public void setVehMake(String newVehMake){
		this.vehMake = newVehMake;
	}

	public void setVehModel(String newVehModel){
		this.vehModel = newVehModel;
	}

	public void setVehEngineNo(int newVehEngineNo){
		this.vehEngineNo = newVehEngineNo;
	}

	public void setVehChasisNo(int newVehChasisNo){
		this.vehChassisNo = newVehChasisNo;
	}

	public void setVehRegistrationNo(int newVehRegistrationNo){
		this.vehRegistrationNo = newVehRegistrationNo;
	}

	public void setVehWarranty(String newVehWarranty){
		this.vehWarranty = newVehWarranty;
	}

	public void setVehVendor(String newVehVendor){
		this.vehVendor = newVehVendor;
	}

	public void setVehMaintenanceDate(String newVehMaintanenceDate){
		this.vehMaintenanceDate = newVehMaintanenceDate;
	}

	// Getter
	public String getVehMake(){
		return vehMake;
	}

	public String getVehModel(){
		return vehModel;
	}

	public int getVehEngineNo(){
		return vehEngineNo;
	}

	public int getVehChasisNo(){
		return vehChassisNo;
	}

	public int getVehRegistrationNo(){
		return vehRegistrationNo;
	}

	public String getVehWarranty(){
		return vehWarranty;
	}

	public String getVehVendor(){
		return vehVendor;
	}

	public String getVehMaintenanceDate(){
		return vehMaintenanceDate;
	}
	
			// Equal Constructure
	public boolean vehEngineNo(int vehEngineNo){
		if(this.vehEngineNo == vehEngineNo){
				return true;
			}else{
				return false;
			}
	}

	public String toString(){
		return super.toString()+"\nMake :"+vehMake+"\nModel :"+vehModel+"\nEngine No. :"+vehEngineNo+"\nChasis No. :"+vehChassisNo+"\nRegistration No. :"
			+vehRegistrationNo+"\nWarranty :"+vehWarranty+"\nVendor :"+vehVendor+"\nMaintenance :"+vehMaintenanceDate;
	}
}


And this will be my half way done program
import javax.swing.*;  // Import to use JOptionPane
import java.lang.*;	   // Import to use String method
import java.util.*;	   // Import to use try catch 'Exception Types'

public class AppPro{
	public static void main(String [] args){
		java.util.Date date = new java.util.Date(); // Use To Display Current Time
		final int MAXINDEX = 100; // Maximum Asset = 100
		Asset[] list = new Asset[MAXINDEX]; // Array of Asset
		int choice = -1; // Choice at -1, due to 0 is use to exit menu
		int types = -1;
		int index = 0; // Starting index at 0

		JOptionPane.showMessageDialog(null, "SunShine Sdn Bhd System", "Welcome!", JOptionPane.INFORMATION_MESSAGE);

		do{
			try{
			// Selection Main Menu
			choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Please Make A Selection.\n" + "1. Add a new Asset.\n" +
				"2. Amend details of Asset.\n" + "3. Search for an Asset.\n" +
					"4. Write Off Status.\n" + "5. List Out Asset.\n" +
						"0. Exit.\n" + "Enter your choice:", "SunShine Sdn Bhd Main Menu", JOptionPane.INFORMATION_MESSAGE));

			switch(choice){
				// Create New Asset Function
				case 1:{
					if(index<MAXINDEX){
						types = Integer.parseInt(JOptionPane.showInputDialog(null, "Make A Selection\n" + "1.Appliance\n" + "2.ICT\n" + "3.Vehicle\n" + "0.Main Menu\n" + "Enter your choice:"
																				,"Selection Menu", JOptionPane.INFORMATION_MESSAGE));
						switch(types){
							case 1:{
								int assetID = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Asset ID:", "Asset ID Menu", JOptionPane.QUESTION_MESSAGE));
								String description = JOptionPane.showInputDialog(null, "Enter Short Description:", "Description Menu", JOptionPane.QUESTION_MESSAGE);
								String purcDate = JOptionPane.showInputDialog(null, date.toString() + "\nEnter Date(DD/MM/YY):", "Purchase Date Menu", JOptionPane.QUESTION_MESSAGE);
								String orderNum = JOptionPane.showInputDialog(null, "Enter Order No.:", "Order No. Menu", JOptionPane.QUESTION_MESSAGE);
								double costPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Cost Price:", "Cost Price Menu", JOptionPane.QUESTION_MESSAGE));
								String appBrand = JOptionPane.showInputDialog(null, "Brand:");
								String appModel = JOptionPane.showInputDialog(null, "Model:");
								int appSerial = Integer.parseInt(JOptionPane.showInputDialog(null, "Serial:"));
								String appWarranty = JOptionPane.showInputDialog(null, "Warranty:");
								String appVendor = JOptionPane.showInputDialog(null, "Vendor:");
								
								boolean isDuplicate = false;
								for(int i=0; i<index; i++){
									if(list[i].equals(assetID) && list[i].equals(appSerial)){
										isDuplicate = true;
									}
								}
								
								if(isDuplicate){
									JOptionPane.showMessageDialog(null, "Asset Existed", "Warning!", JOptionPane.WARNING_MESSAGE);
								}else{
									list[index] = new Appliance(assetID, description, purcDate, orderNum, costPrice, true, appBrand, appModel, appSerial, appWarranty, appVendor);
									index++;
								}
								break;
							}
							case 2:{
								int assetID = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Asset ID:", "Asset ID Menu", JOptionPane.QUESTION_MESSAGE));
								String description = JOptionPane.showInputDialog(null, "Enter Short Description:", "Description Menu", JOptionPane.QUESTION_MESSAGE);
								String purcDate = JOptionPane.showInputDialog(null, date.toString() + "\nEnter Date(DD/MM/YY):", "Purchase Date Menu", JOptionPane.QUESTION_MESSAGE);
								String orderNum = JOptionPane.showInputDialog(null, "Enter Order No.:", "Order No. Menu", JOptionPane.QUESTION_MESSAGE);
								double costPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Cost Price:", "Cost Price Menu", JOptionPane.QUESTION_MESSAGE));
								String ictBrand = JOptionPane.showInputDialog(null, "Brand:");
								String ictModel = JOptionPane.showInputDialog(null, "Model:");
								int ictSerialNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Serial:"));
								String ictWarranty = JOptionPane.showInputDialog(null, "Warranty:");
								String ictVendor = JOptionPane.showInputDialog(null, "Vendor:");
								String ictMaintenanceDate = JOptionPane.showInputDialog(null, "Date:");
								
								boolean isDuplicate = false;
								for(int i=0; i<index; i++){
									if(list[i].equals(assetID) && list[i].equals(ictSerialNo)){
										isDuplicate = true;
									}
								}
								
								if(isDuplicate){
									JOptionPane.showMessageDialog(null, "Asset Existed", "Warning!", JOptionPane.WARNING_MESSAGE);
								}else{
									list[index] = new Ict(assetID, description, purcDate, orderNum, costPrice, true, ictBrand, ictModel, ictSerialNo, ictWarranty, ictVendor,
															 ictMaintenanceDate);
									index++;
								}
								break;
							}
							case 3:{
								int assetID = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter Asset ID:", "Asset ID Menu", JOptionPane.QUESTION_MESSAGE));
								String description = JOptionPane.showInputDialog(null, "Enter Short Description:", "Description Menu", JOptionPane.QUESTION_MESSAGE);
								String purcDate = JOptionPane.showInputDialog(null, date.toString() + "\nEnter Date(DD/MM/YY):", "Purchase Date Menu", JOptionPane.QUESTION_MESSAGE);
								String orderNum = JOptionPane.showInputDialog(null, "Enter Order No.:", "Order No. Menu", JOptionPane.QUESTION_MESSAGE);
								double costPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Cost Price:", "Cost Price Menu", JOptionPane.QUESTION_MESSAGE));
								String vehMake = JOptionPane.showInputDialog(null, "Make:");
								String vehModel = JOptionPane.showInputDialog(null, "Model:");
								int vehEngineNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Engine:"));
								int vehChassisNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Chassis:"));
								int vehRegistrationNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Reg:"));
								String vehWarranty = JOptionPane.showInputDialog(null, "Warranty:");
								String vehVendor = JOptionPane.showInputDialog(null, "Vendor:");
								String vehMaintenanceDate = JOptionPane.showInputDialog(null, "Date:");
								
								boolean isDuplicate = false;
								for(int i=0; i<index; i++){
									if(list[i].equals(assetID) && list[i].equals(vehEngineNo)){
										isDuplicate = true;
									}
								}
								
								if(isDuplicate){
									JOptionPane.showMessageDialog(null, "Asset Existed", "Warning!", JOptionPane.WARNING_MESSAGE);
								}else{
									list[index] = new Vehicle(assetID, description, purcDate, orderNum, costPrice, true, vehMake, vehModel, vehEngineNo, vehChassisNo, vehRegistrationNo, 
															vehWarranty, vehVendor, vehMaintenanceDate);
									index++;
								}
								break;
							}
							case 0:{
								break;
							}
						}
					}else{
						JOptionPane.showMessageDialog(null, "Sorry, Full!", "Warning!", JOptionPane.WARNING_MESSAGE); // Error Message
					}

				break;
				}
				
				// Amend Asset Function
				case 2:{
					String num = "";

					int selection = Integer.parseInt(JOptionPane.showInputDialog(null, "Which Category To change?\n"+"1.Appliance\n"+"2.Vehicle\n"+"3.ICT",
														"Amend Function Menu", JOptionPane.QUESTION_MESSAGE));
					
					switch(selection){
						case 1:{						
							for(int i = 0; i < index; i++){
								num = num + (i + 1) + " - " + list[i].getAssetID() + "\n";
							}
							
							int appAmend = Integer.parseInt(JOptionPane.showInputDialog(null, "Which Asset To Change?\n" + num +
										"\nEnter choice, following the Index No.", "Amend Function Menu", JOptionPane.QUESTION_MESSAGE));
							
							if( (appAmend-1)  < index){
								String description = JOptionPane.showInputDialog(null, "Enter Short Description:", "Description Menu", JOptionPane.QUESTION_MESSAGE);		
								String purcDate = JOptionPane.showInputDialog(null, date.toString() + "\nEnter Date(DD/MM/YY):", "Purchase Date Menu", JOptionPane.QUESTION_MESSAGE);
								String orderNum = JOptionPane.showInputDialog(null, "Enter Order No.:", "Order No. Menu", JOptionPane.QUESTION_MESSAGE);
								double costPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter Cost Price:", "Cost Price Menu", JOptionPane.QUESTION_MESSAGE));
								String appBrand = JOptionPane.showInputDialog(null, "Brand:");
								String appModel = JOptionPane.showInputDialog(null, "Model:");
								int appSerial = Integer.parseInt(JOptionPane.showInputDialog(null, "Serial:"));
								String appWarranty = JOptionPane.showInputDialog(null, "Warranty:");
								String appVendor = JOptionPane.showInputDialog(null, "Vendor:");
								
								list[appAmend-1].setDescription(description);
								list[appAmend-1].setPurcDate(purcDate);
								list[appAmend-1].setOrderNum(orderNum);
								list[appAmend-1].setCostPrice(costPrice);
								list[appAmend-1].setAppBrand(appBrand);
								list[appAmend-1].setAppModel(appModel);
								list[appAmend-1].setAppSerial(appSerial);
								list[appAmend-1].setAppWarranty(appWarranty);
								list[appAmend-1].setAppVendor(appVendor);
							}else{
								JOptionPane.showMessageDialog(null, "Please Enter Available Index No.", "Error Message!", JOptionPane.WARNING_MESSAGE);
							}
							break;
					}
					case 2:{							
							for(int i = 0; i < index; i++){
								num = num + (i + 1) + " - " + list[i].getAssetID() + "\n";
							}
							
							int ictAmend = Integer.parseInt(JOptionPane.showInputDialog(null, "Which Asset To Change?\n" + num +
										"\nEnter choice, following the Index No.", "Amend Function Menu", JOptionPane.QUESTION_MESSAGE));
							
							if( (ictAmend-1)  < index){
								String description = JOptionPane.showInputDialog(null, "Enter Short Description:", "Description Menu", JOptionPane.QUESTION_MESSAGE);		
								String purcDate = JOptionPane.showInputDialog(null, date.toString() + "\nEnter Date(DD/MM/YY):", "Purchase Date Menu", JOptionPane.QUESTION_MESSAGE);
								String orderNum = JOptionPane.showInputDialog(null, "Enter Order No.:", "Order No. Menu", JOptionPane.QUESTION_MESSAGE);
								double costPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter Cost Price:", "Cost Price Menu", JOptionPane.QUESTION_MESSAGE));
								String ictBrand = JOptionPane.showInputDialog(null, "Brand:");
								String ictModel = JOptionPane.showInputDialog(null, "Model:");
								int ictSerialNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Serial:"));
								String ictWarranty = JOptionPane.showInputDialog(null, "Warranty:");
								String ictVendor = JOptionPane.showInputDialog(null, "Vendor:");
								String ictMaintenanceDate = JOptionPane.showInputDialog(null, "Date:");
								
								list[ictAmend-1].setDescription(description);
								list[ictAmend-1].setPurcDate(purcDate);
								list[ictAmend-1].setOrderNum(orderNum);
								list[ictAmend-1].setCostPrice(costPrice);													
								list[ictAmend-1].setIctBrand(ictBrand);
								list[ictAmend-1].setIctModel(ictModel);
								list[ictAmend-1].setIctSerialNo(ictSerialNo);
								list[ictAmend-1].setIctWarranty(ictWarranty);
								list[ictAmend-1].setIctVendor(ictVendor);
								list[ictAmend-1].setIctMaintenanceDate(ictMaintenanceDate);
							}else{
								JOptionPane.showMessageDialog(null, "Please Enter Available Index No.", "Error Message!", JOptionPane.WARNING_MESSAGE);
							}
							break;
					}
					case 3:{
							for(int i = 0; i < index; i++){
								num = num + (i + 1) + " - " + list[i].getAssetID() + "\n";
							}
							
							int vehAmend = Integer.parseInt(JOptionPane.showInputDialog(null, "Which Asset To Change?\n" + num +
										"\nEnter choice, following the Index No.", "Amend Function Menu", JOptionPane.QUESTION_MESSAGE));
							
							if( (vehAmend-1)  < index){
								String description = JOptionPane.showInputDialog(null, "Enter Short Description:", "Description Menu", JOptionPane.QUESTION_MESSAGE);		
								String purcDate = JOptionPane.showInputDialog(null, date.toString() + "\nEnter Date(DD/MM/YY):", "Purchase Date Menu", JOptionPane.QUESTION_MESSAGE);
								String orderNum = JOptionPane.showInputDialog(null, "Enter Order No.:", "Order No. Menu", JOptionPane.QUESTION_MESSAGE);
								double costPrice = Double.parseDouble(JOptionPane.showInputDialog(null, "Enter Cost Price:", "Cost Price Menu", JOptionPane.QUESTION_MESSAGE));
								String vehMake = JOptionPane.showInputDialog(null, "Make:");
								String vehModel = JOptionPane.showInputDialog(null, "Model:");
								int vehEngineNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Engine:"));
								int vehChassisNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Chassis:"));
								int vehRegistrationNo = Integer.parseInt(JOptionPane.showInputDialog(null, "Reg:"));
								String vehWarranty = JOptionPane.showInputDialog(null, "Warranty:");
								String vehVendor = JOptionPane.showInputDialog(null, "Vendor:");
								String vehMaintenanceDate = JOptionPane.showInputDialog(null, "Date:");
								
								list[vehAmend-1].setDescription(description);
								list[vehAmend-1].setPurcDate(purcDate);
								list[vehAmend-1].setOrderNum(orderNum);
								list[vehAmend-1].setCostPrice(costPrice);
								list[vehAmend-1].setVehMake(vehMake);
								list[vehAmend-1].setVehModel(vehModel);
								list[vehAmend-1].setVehEngineNo(vehEngineNo);
								list[vehAmend-1].setVehChassisNo(vehChassisNo);
								list[vehAmend-1].setVehRegistrationNo(vehRegistrationNo);
								list[vehAmend-1].setVehWarranty(vehWarranty);
								list[vehAmend-1].setVehVendor(vehVendor);
								list[vehAmend-1].setVehMaintenanceDate(vehMaintenanceDate);
							}else{
								JOptionPane.showMessageDialog(null, "Please Enter Available Index No.", "Error Message!", JOptionPane.WARNING_MESSAGE);
							}
							break;
					}
					case 0:{
						break;
					}		
					break;		
					}
				}
				// Search Asset Function
				case 3:{
					int key = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter An Asset ID", "Search Function Menu", JOptionPane.QUESTION_MESSAGE));
					// Check for same asset
					boolean isEquals = false;
					for(int i = 0; i<index; i++){
						if(key == list[i].getAssetID()){
							isEquals = true;
						}
					}
					// Display message if same asset found or not
					if(isEquals){
						JOptionPane.showMessageDialog(null, "Asset Available", "Confirm Message", JOptionPane.INFORMATION_MESSAGE);
					}else{
						JOptionPane.showMessageDialog(null, "Asset Not Available", "Error Message!", JOptionPane.ERROR_MESSAGE);
					}

				break;
				}
				// Write off Asset Function
				case 4:{
					int key = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter An Asset ID", "Asset Status Checking Menu", JOptionPane.QUESTION_MESSAGE));
					// Check for same Asset and to write off or not
					boolean isExist = false;
					for(int i=0; i<index; i++){
						if(key == list[i].getAssetID()){
							isExist = true; // Same asset found
							int mod = JOptionPane.showConfirmDialog(null, "Asset Status\nAsset ID:" + list[i].getAssetID() + "\nCondition:" + list[i].getStatus() +
								"\nWrite Off Status?", "Asset Status Menu", JOptionPane.YES_NO_OPTION);
								if(mod == JOptionPane.YES_OPTION){
									list[i].setStatus(false); // Write off the Asset status
									break;
								}else if(mod == JOptionPane.NO_OPTION){
										break;
								}else{
										JOptionPane.showMessageDialog(null, "Invalid Input", "Error Message!", JOptionPane.WARNING_MESSAGE);
								}
						}
					}
					if(isExist == false){
							JOptionPane.showMessageDialog(null, "Asset Not Exist", "Error Message", JOptionPane.WARNING_MESSAGE);
					}

				break;
				}
				// Display Asset Function
				case 5:{
					int assetList = 0;
					// Error Message if no Asset in array
					if(index == 0){
						JOptionPane.showMessageDialog(null, "No Asset!", "Error Message!", JOptionPane.WARNING_MESSAGE);
					}else{
						while(assetList < index){
							String message = "No   Asset ID\tDescription\tPurchase Date\tOrder No.\tCost Price\tStatus\n";
							for(int i = 1; i < 20; i++){
								if((assetList+i) <= index){
								message = message + (assetList+i) +"      "+ list[(assetList+i-1)].getAssetID() +"\t"+
									list[(assetList+i-1)].getDescription() +"\t"+ list[(assetList+i-1)].getPurcDate() +
										"\t"+ list[(assetList+i-1)].getOrderNum() +"\t"+ list[(assetList+i-1)].getCostPrice() +"\t"+
											list[(assetList+i-1)].getStatus() + "\n" ;
							}
						}

						JScrollPane jsp = new JScrollPane(new JTextArea(message));
						jsp.setPreferredSize(new java.awt.Dimension(500,100)); // define the frame size (width,height)
						JOptionPane.showMessageDialog(null, jsp, "Display Function Menu", JOptionPane.INFORMATION_MESSAGE, null);
						// Display maximum 20 asset per page
						assetList += 20;
					}
				}
			break;
			}

			case 0:{
				JOptionPane.showMessageDialog(null, "Thanks You & Bye", "Exit Message", JOptionPane.INFORMATION_MESSAGE); // Exiting
			break;
			}

			default:
				JOptionPane.showMessageDialog(null, "Please Key in 1 - 5 or 0 to exit", "Error Message!", JOptionPane.WARNING_MESSAGE); // Invalid digit input
			break;							
			}
				
			}catch(IllegalArgumentException ex){
				JOptionPane.showMessageDialog(null, "Invalid Input!", "Error Message!", JOptionPane.WARNING_MESSAGE); // Invalid input
			}
		}while(choice != 0); // End program with input 0 in main menu
	}
}


This part doesn't work. I wonder why??
From my main program, I get an error code of
"Cannot find symbol method setAppBrand(java.lang.String)" and so on for other at this part:
								list[appAmend-1].setAppBrand(appBrand);
								list[appAmend-1].setAppModel(appModel);
								list[appAmend-1].setAppSerial(appSerial);
								list[appAmend-1].setAppWarranty(appWarranty);
								list[appAmend-1].setAppVendor(appVendor);



following by others (ICT and Vehicle).

This post has been edited by dragon528: 03 August 2010 - 08:46 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Seek for help, setter not working

#2 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Seek for help, setter not working

Posted 03 August 2010 - 08:36 AM

So...like...where exactly is your problem...quite a long piece of code to go through from line 1 -.-

By the way, your constructor that is:
public Asset(Asset a)
{
  this.blah = blah;
  //....etc
}


looks kind of useless...even if you are trying to copy it...just use the existing constructor and provide the values like a.descroption, etc to the constructor.

Edit: Alright now I see what your problem is...

Your "list" array is of type Asset. Your Asset class is abstract...there goes your problem. When you try to call a method from the Appliance class on an Asset...that should cause the error. An Applicane IS-AN Asset BUT An Asset IS-NOT-AN Applicance.

2nd Edit: No offence, but extending Asset in several classes like Appliance, Vehicle, etc seems like a bad idea.

This post has been edited by bcranger: 03 August 2010 - 08:43 AM

Was This Post Helpful? 0
  • +
  • -

#3 dragon528  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-August 08

Re: Seek for help, setter not working

Posted 03 August 2010 - 08:41 AM

I also not sure, as my lecture say, need a copy constructor like that. So I did it.

From my main program, I get an error code of
"Cannot find symbol method setAppBrand(java.lang.String)" and so on for other at this part:
								list[appAmend-1].setAppBrand(appBrand);
								list[appAmend-1].setAppModel(appModel);
								list[appAmend-1].setAppSerial(appSerial);
								list[appAmend-1].setAppWarranty(appWarranty);
								list[appAmend-1].setAppVendor(appVendor);


Was This Post Helpful? 0
  • +
  • -

#4 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Seek for help, setter not working

Posted 03 August 2010 - 08:44 AM

Read edited post

^
^
^
^
Was This Post Helpful? 0
  • +
  • -

#5 dragon528  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-August 08

Re: Seek for help, setter not working

Posted 03 August 2010 - 08:47 AM

So, if the class Asset is not abstract. It still doesn't work too.

I'm not so sure should I extend so many from Asset class thou.
My assignment question didn't mention too.
Was This Post Helpful? 0
  • +
  • -

#6 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Seek for help, setter not working

Posted 03 August 2010 - 08:50 AM

No, you understood it wrong. By extending a class, you are using inheritance, btw.

As an array of Assets, "link" cannot have methods called on it from your Appliance class...because Assets do not have that method. However, you could call methods from the Assets class if the array were of type Appliance since it is extending it, if the class were not abstract, as abstract classes, you must override all methods. And I'm sure extending it is a bad idea.

Can you post your instructions?
Was This Post Helpful? 0
  • +
  • -

#7 dragon528  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-August 08

Re: Seek for help, setter not working

Posted 03 August 2010 - 08:53 AM

1. Develop a subclass from a superclass through inheritance.
2. Design and use abstract classes.
3. Design systems by identifying the classes and determining the relationships among the classes.
4. Implement the concept of polymorphism in programs.

Sunshine Sdn Bhd has requested that you enhance the application to enable the company to keep track of assets of various categories such as : appliance (e.g. TV, refrigerator, microwave etc), company-owned vehicle (e.g. van, car etc), and ICT (e.g. computer, LCD projector etc).

The information to be stored for the various categories of assets are as follows:
Appliance
o Brand (e.g. Toshiba, Sanyo etc)
o Model
o Serial number
o Warranty expiry date
o Vendor

Vehicle
o Make (e.g. Honda, Toyota etc )
o Model
o Engine number
o Chassis number
o Registration number
o Warranty expiry date
o Vendor
o Last maintenance date

ICT
o Brand (e.g. Compaq, IBM)
o Model
o Serial number
o Warranty expiry date
o Vendor
o Last maintenance date

Note:
Each asset must be categorized as an appliance, vehicle, or ICT.
The following details must be kept for a vendor : Company name and address.

Task 1
(a) Identify and design the necessary classes for the above scenario and determine the relationships among them.
Draw a UML diagram to depict the relationships.

(B) Define the classes that you identified in (a). Each class should have its own constructor(s), setter and getter methods, as well as a customized toString() method which displays all the data member values in a single line.

© Write test driver(s) to test the various operations of all your defined classes.

Sorry for so long.
Was This Post Helpful? 0
  • +
  • -

#8 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Seek for help, setter not working

Posted 03 August 2010 - 09:02 AM

View Postdragon528, on 03 August 2010 - 07:41 AM, said:

I also not sure, as my lecture say, need a copy constructor like that. So I did it.

From my main program, I get an error code of
"Cannot find symbol method setAppBrand(java.lang.String)" and so on for other at this part:
								list[appAmend-1].setAppBrand(appBrand);
								list[appAmend-1].setAppModel(appModel);
								list[appAmend-1].setAppSerial(appSerial);
								list[appAmend-1].setAppWarranty(appWarranty);
								list[appAmend-1].setAppVendor(appVendor);



setAppBrand() is method of Appliance, not Asset

edit:

bcranger already on it. :)

This post has been edited by n8wxs: 03 August 2010 - 09:03 AM

Was This Post Helpful? 0
  • +
  • -

#9 dragon528  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-August 08

Re: Seek for help, setter not working

Posted 03 August 2010 - 09:08 AM

I thought that after I extend Appliance from Asset,
the method can be called. But regardless it not working.
Still finding solution to solve it.
Was This Post Helpful? 0
  • +
  • -

#10 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Seek for help, setter not working

Posted 03 August 2010 - 09:16 AM

DOOD
YOU ARE TOTALLY MISSING THE POINT

Your "list" array is of type Assets. Although you can add objects that extend Assets to an Assets array, when you call a method on that array, it will look for the method in the Assets class!
Was This Post Helpful? 0
  • +
  • -

#11 dragon528  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 23-August 08

Re: Seek for help, setter not working

Posted 03 August 2010 - 10:30 AM

So what should I change in order to call other class method?

Use "implements" ?
Was This Post Helpful? 0
  • +
  • -

#12 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: Seek for help, setter not working

Posted 03 August 2010 - 10:36 AM

After reading the directions you posted, I think you do need to extend Assets, as an Appliance IS-AN Asset. You will need to use Polymorphism to overcome your problem in that case.

Implementing is for interfaces, not what you need here.
Was This Post Helpful? 0
  • +
  • -

#13 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Seek for help, setter not working

Posted 03 August 2010 - 10:38 AM

if you know that the Asset Object is initiated as an Appliance Object, you can cast it to Appliance Object, and then call the method.
like so:
//a here is an Asset Object in your list, i use it that way for demonstration
Asset a = new Appliance(/*parameters..*/);
Appliance p = (Appliance)a;
a.setAppBrand();


if you don't know what type that Asset Object is, you can check if an Asset Object is an Appliance Object by using the instanceof operator:
//a here is an Asset Object in your list, i use it that way for demonstration
if(a instanceof Appliance){
/*here goes the code from above:
cast a to Appliance and call the method*/
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1