⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compstore.java

📁 The assessment of JAVA in the Western Insititute Technology.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// Author:  Zhang He(Zak)
// student ID:2003002399
// Title: CompStore
// Update: 2005/04/05
// BIS6.223--Assessment 1 

import java.io.*;


public class CompStore{
	
public static void main(String args[]){	
     //Initialization
    Computer comp1 = new Computer();
    Computer comp2 = new Computer();        
    Computer comp3 = new Computer();
    Computer current; //use to select one of three above (just a reference) 
    Computer [] comps = {comp1, comp2, comp3};    
    //set of system blocks
    SysBlock sb1 = new SysBlock("Intel Pentium 4", 800.00);
    SysBlock sb2 = new SysBlock("AMD Athlon XP", 700.00);
    SysBlock sb3 = new SysBlock("Intel Celeron", 600.00); 
        
    SysBlock [] sbArray = {sb1, sb2, sb3};
        
    //set of monitors
    Monitor mn1 = new Monitor("Samsung SyncMaster 19\"", 250.00); 
    Monitor mn2 = new Monitor("ViewSonic 17IN LCD", 500.00);        
    Monitor mn3 = new Monitor("ViewSonic 21IN CRT", 400.00);
        
    Monitor [] mnArray = {mn1, mn2, mn3};
        
    //set of mice
    Mouse ms1 = new Mouse("Logitech Cordless Optical Mouse", 60.00);
    Mouse ms2 = new Mouse("Logitech Corded Optical Mouse", 30.00);                
    Mouse ms3 = new Mouse("Logitech 3Btn LABTEC Mouse", 30.00);   
        
    Mouse [] msArray = {ms1, ms2, ms3};
        
    //set of keyboards
    Keyboard kb1 = new Keyboard("Logitech Cordless MX DUO", 70.00);
    Keyboard kb2 = new Keyboard("Microsoft NATURAL KB Elite PS", 50.00);
    Keyboard kb3 = new Keyboard("Keytronic 104-KEY PS2", 20.00);  
        
    Keyboard [] kbArray  = {kb1, kb2, kb3};         
          
	InputStreamReader isr = new InputStreamReader ( System.in );
	    BufferedReader br = new BufferedReader ( isr );
        String s = null;
        
        
        
        int mainmenuchoice=0;
        int submenuchoice=0;
        int choicesb=0;
        int choicemn=0;
        int choicems=0;
        int choicekb=0;
        int compchoice= 0;
        
     while(!(mainmenuchoice == 4)){

	 		System.out.println("***** MAIN MENU *****");
	 		System.out.println("1. Assemle Computer"); 
	 		System.out.println("2. Change Configuratrue");
	 		System.out.println("3. View Configuratrue");
	 		System.out.println("4. Exit");
	 		System.out.print("Please enter your choice  -- > :");
	 		

	 		
	 		// get input
	             
	        try {
	            s = br.readLine (); //read input string
	            mainmenuchoice = Integer.parseInt(s);
	        }
	        catch ( IOException ioe ) {
	                  System.out.println(ioe.toString());
	        }       
	 		// check what the input is
	 		catch(ArrayIndexOutOfBoundsException aoe){
	 			
	 		  	System.out.println("Please enter a right number from 1 to 4 !");
	 		  }
	 		  
	 		 catch(NumberFormatException nfe){
	 		  	
	 		     	System.out.println("Please enter a right number from menu!");
	 		  }
	 	;
	 	
	  if (mainmenuchoice==1){	 	
	 	    System.out.println("************Select one of three systems (1,2 or 3) **********************\n");
	 		System.out.print("Please enter your choice  --->  :\t");
	 		
	 		try {
	            s = br.readLine (); //read input string
	            compchoice = Integer.parseInt(s);
	            
	        }
	        catch ( IOException ioe ) {
	                  System.out.println(ioe.toString());
	        }       
	 		// check what the input is
	 		catch(ArrayIndexOutOfBoundsException aoe){
	 			
	 		  	System.out.println("Please enter a right number from 1 to 4 !");
	 		  }
	 		  
	 		 catch(NumberFormatException nfe){
	 		  	
	 		     	System.out.println("Please enter a right number from menu!");
	 		  }
	
	
	  if(compchoice==1){ 
    
			System.out.println("\n##--Select SystemBlock--##"); 
			
			  System.out.println("--components availble:--\n");

	 
        for (int i = 0; i < sbArray.length; i++) {
       	
       	if(!sbArray[i].getUsed()){
       	
          System.out.println((i + 1) + ". " + "Processor:   " + sbArray[i].getDescription()+"      "  + sbArray[i].getPrice());
          System.out.println(); 
   
    }
         }
         
         System.out.print("\nPlease enter your choice-->  :\t");
         
         
         		
		 try {
		            s = br.readLine (); //read input string
		            choicesb = Integer.parseInt(s);
//		            comps[compchoice -1].setSysBlock(sbArray[choicesb-1]);
//		            sbArray[choicesb-1].setUsed(true);
		          
		        }
		        catch ( IOException ioe ) {
		                  System.out.println(ioe.toString());
		        }
		        	// check what the input is
		        	  catch(ArrayIndexOutOfBoundsException aoe){
	 		  	System.out.println("Please enter a right number !");
	 		  }
	 		  
	 		  catch(NumberFormatException nfe){
	 		  	
	 		     System.out.println("Please enter a right number from menu!");
	 		  }	
	 		  
	 		  
//	  if (choicesb == 1) {
//        if (sb1.getUsed() == true) {
//          System.out.println("SystemBlock is set\n");
//    
//      
//        }
//        sb1.setUsed(true);
//        sb2.setUsed(false);
//        sb3.setUsed(false);
//       
//       
//		}
//	 	else if(choicesb==2){
//	 		if (sb2.getUsed() == true) {
//          System.out.println("SystemBlock is set\n");
//          
//        }
//        sb1.setUsed(false);
//        sb2.setUsed(true);
//        sb3.setUsed(false);
//       
//	 	}	
//	 	else if(choicesb==3){
//	 	 if (sb3.getUsed() == true) {
//          System.out.println("SystemBlock is set\n");
//          
//        }
//        sb1.setUsed(false);
//        sb2.setUsed(false);
//        sb3.setUsed(true);
//     
//	    }  
	    
	    
	    
	    	System.out.println("##--Select System Monitor--##");
	 			    System.out.println("--components availble:--\n");

      for (int i = 0; i < mnArray.length; i++) {
      	
      	
      		if(!mnArray[i].getUsed()){
     
        System.out.println((i + 1) + ". " + "Monitor:   " + mnArray[i].getDescription()+"    "  + mnArray[i].getPrice());
        System.out.println(); 
        
       }
       
      }
      
      System.out.print("\nPlease enter your choice-->  :\t");
      
          try {
		                s = br.readLine (); //read input string
		                 choicemn = Integer.parseInt(s);
		        }
		        catch ( IOException ioe ) {
		                  System.out.println(ioe.toString());
		        }
		        
		        
		      catch(ArrayIndexOutOfBoundsException aoe){
		         	System.out.println("Please enter a right number !");
	 		  }
	 		  
	 		  catch(NumberFormatException nfe){
	 		  	
	 		     System.out.println("Please enter a right number from menu!");
	 		  }

	        
	 
	 		
	 	 System.out.println("##--Select System Mouse--##");
         System.out.println("--components availble:--\n");	
	 		
	 		
            for (int i = 0; i < msArray.length; i++) {
    	
    		if(!msArray[i].getUsed()){
     
       System.out.println((i + 1) + ". " + "Mouse:   " + msArray[i].getDescription()+"      "  + msArray[i].getPrice());
        System.out.println(); 
        
       }
       
      }
      
      System.out.print("\nPlease enter your choice-->  :\t");

      try {
		                s = br.readLine (); //read input string
		                 choicems = Integer.parseInt(s);
		        }
		        catch ( IOException ioe ) {
		                  System.out.println(ioe.toString());
		                  
		        }
		        
		        
		     catch(ArrayIndexOutOfBoundsException aoe){
		        
                   	System.out.println("Please enter a right number !");
	 		  }
	 		  
	 		  catch(NumberFormatException nfe){
	 		  	
	 		     System.out.println("Please enter a right number from menu!");
	 		  }

	             
		        	// check what the input is	  
	 	
	 		System.out.println("##--Select System Keyboard--##");
	 		System.out.println("--components availble:--\n");
	 		
	 	 for (int z = 0; z < kbArray.length; z++) {
           	
           if(!kbArray[z].getUsed()){
     
                System.out.println((z + 1) + ". " + "Keyboard:   " + kbArray[z].getDescription()+"      "  + kbArray[z].getPrice());
                System.out.println();    
       
              }  
       }
        		   
	         System.out.print("\nPlease enter your choice-->  :\t");
	         
	         
	         	try {
		                s = br.readLine (); //read input string
		                 choicekb= Integer.parseInt(s);
		        }
		        catch ( IOException ioe ) {
		                  System.out.println(ioe.toString());
		        }
		        
		        
		     catch(ArrayIndexOutOfBoundsException aoe){
		        
		         	System.out.println("Please enter a right number !");
	 		  }
	 		  
	 		  catch(NumberFormatException nfe){
	 		  	
	 		     System.out.println("Please enter a right number from menu!");
	 		  }

	
        System.out.println("CONFIGURATION:\n--------------");
	 	
	 	comps[compchoice-1].setSysBlock(sbArray[choicesb-1]);
	 	sbArray[choicesb-1].setUsed(true);
	 	comps[compchoice-1].setMonitor(mnArray[choicemn-1]);
	 	mnArray[choicemn-1].setUsed(true);
	 	comps[compchoice-1].setMouse(msArray[choicems-1]);
	 	msArray[choicems-1].setUsed(true);
	 	comps[compchoice-1].setKeyboard(kbArray[choicekb-1]);
        kbArray[choicekb-1].setUsed(true);
        
        
	 	System.out.println("Processor:\t"+comps[compchoice-1].getSysBlock().getDescription());
	 	System.out.println("Monitor: \t"+comps[compchoice-1].getMonitor().getDescription());
	 	System.out.println("Mouse: \t"+comps[compchoice-1].getMouse().getDescription());
	 	System.out.println("Keyboard: \t"+comps[compchoice-1].getKeyboard().getDescription());
	 	 	
	double totalprice = comps[compchoice-1].getSysBlock().getPrice() +comps[compchoice-1].getMonitor().getPrice() +comps[compchoice-1].getMouse().getPrice()+  comps[compchoice-1].getKeyboard().getPrice();
    		
	 	System.out.println("\ntotal price:--"+totalprice);
	 	
	 	}
	 	
	 	
	 	if(compchoice==2){
	 		
	 	
	System.out.println("\n##--Select SystemBlock--##"); 
			
			  System.out.println("--components availble:--\n");

	 
        for (int i = 0; i < sbArray.length; i++) {
       	
       	if(!sbArray[i].getUsed()){
       	
          System.out.println((i + 1) + ". " + "Processor:   " + sbArray[i].getDescription()+"      "  + sbArray[i].getPrice());
          System.out.println(); 
   
    }
         }
         
         System.out.print("\nPlease enter your choice-->  :\t");
         
         
         		
		 try {
		            s = br.readLine (); //read input string
		            choicesb = Integer.parseInt(s);
//		            comps[compchoice -1].setSysBlock(sbArray[choicesb-1]);
//		            sbArray[choicesb-1].setUsed(true);
		          
		        }
		        catch ( IOException ioe ) {
		                  System.out.println(ioe.toString());
		        }
		        	// check what the input is
		        	  catch(ArrayIndexOutOfBoundsException aoe){
	 		  	System.out.println("Please enter a right number !");
	 		  }
	 		  
	 		  catch(NumberFormatException nfe){
	 		  	
	 		     System.out.println("Please enter a right number from menu!");
	 		  }	
	 		  
	 		  
//	  if (choicesb == 1) {
//        if (sb1.getUsed() == true) {
//          System.out.println("SystemBlock is set\n");
//    
//      
//        }
//        sb1.setUsed(true);
//        sb2.setUsed(false);
//        sb3.setUsed(false);
//       
//       
//		}
//	 	else if(choicesb==2){
//	 		if (sb2.getUsed() == true) {
//          System.out.println("SystemBlock is set\n");
//          
//        }
//        sb1.setUsed(false);
//        sb2.setUsed(true);
//        sb3.setUsed(false);
//       
//	 	}	
//	 	else if(choicesb==3){
//	 	 if (sb3.getUsed() == true) {
//          System.out.println("SystemBlock is set\n");
//          
//        }
//        sb1.setUsed(false);
//        sb2.setUsed(false);
//        sb3.setUsed(true);
//     
//	    }  
	    
	    
	    
	    	System.out.println("##--Select System Monitor--##");
	 			    System.out.println("--components availble:--\n");

      for (int i = 0; i < mnArray.length; i++) {
      	
      	
      		if(!mnArray[i].getUsed()){
     
        System.out.println((i + 1) + ". " + "Monitor:   " + mnArray[i].getDescription()+"    "  + mnArray[i].getPrice());
        System.out.println(); 
        
       }
       
      }
      
      System.out.print("\nPlease enter your choice-->  :\t");
      
          try {
		                s = br.readLine (); //read input string
		                 choicemn = Integer.parseInt(s);
		        }
		        catch ( IOException ioe ) {
		                  System.out.println(ioe.toString());
		        }
		        
		        
		      catch(ArrayIndexOutOfBoundsException aoe){
		         	System.out.println("Please enter a right number !");
	 		  }
	 		  
	 		  catch(NumberFormatException nfe){
	 		  	
	 		     System.out.println("Please enter a right number from menu!");
	 		  }

	        
	 
	 		
	 	 System.out.println("##--Select System Mouse--##");
         System.out.println("--components availble:--\n");	
	 		
	 		
            for (int i = 0; i < msArray.length; i++) {
    	
    		if(!msArray[i].getUsed()){
     
       System.out.println((i + 1) + ". " + "Mouse:   " + msArray[i].getDescription()+"      "  + msArray[i].getPrice());
        System.out.println(); 
        
       }
       
      }
      
      System.out.print("\nPlease enter your choice-->  :\t");

      try {
		                s = br.readLine (); //read input string
		                 choicems = Integer.parseInt(s);
		        }
		        catch ( IOException ioe ) {
		                  System.out.println(ioe.toString());
		                  
		        }
		        
		        
		     catch(ArrayIndexOutOfBoundsException aoe){
		        
                   	System.out.println("Please enter a right number !");
	 		  }
	 		  
	 		  catch(NumberFormatException nfe){
	 		  	
	 		     System.out.println("Please enter a right number from menu!");
	 		  }

	             
		        	// check what the input is	  
	 	
	 		System.out.println("##--Select System Keyboard--##");
	 		System.out.println("--components availble:--\n");
	 		
	 	 for (int z = 0; z < kbArray.length; z++) {
           	
           if(!kbArray[z].getUsed()){
     
                System.out.println((z + 1) + ". " + "Keyboard:   " + kbArray[z].getDescription()+"      "  + kbArray[z].getPrice());
                System.out.println();    
       
              }  
       }
        		   
	         System.out.print("\nPlease enter your choice-->  :\t");
	         
	         
	         	try {
		                s = br.readLine (); //read input string
		                 choicekb= Integer.parseInt(s);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -