A little problem whit java code


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: A little problem whit java code

  1. #1
    Join Date
    Oct 2004
    Posts
    11

    A little problem whit java code

    Hi again!
    Please help me. My program is working but I have problem whit
    class car: regNr=Input.readString();
    after running of the program I can not put in the string value.
    if I change it to int the program is working otherwise the program jump form
    regNr=Input.readString(); to next input:maxLoad=Input.readInt();
    why I have this problem.
    please test the program.

    Code:
     
     public class MyTest  
    {
       public static void main(String[] arg) 
      {
       
        Truck Tr = new Truck("Alex",2000, "dfg 122", 5000);
        Tr.print();
        
        Tr.newWoner();
        Tr.print();
        
        
        Tr.newMotor();
        Tr.print();
       
        Tr.newRegNbr();
        Tr.print(); 
          
        Tr.newMaxLoad();
        Tr.print();
    
      }
    }
    
    
     class vehicle
    {
       protected String woner;
       protected vehicle(String newWoner)
      {
         woner=newWoner;
      }
       public void print()
      {
       	 System.out.println("-woner : "+woner );
      }
       public String newWoner()
      {
         System.out.print("write new  woner (String):  ");
       	  woner=Input.readString();
       	  return woner; 
      }
    }
    	
      class Motor extends vehicle
     {
         protected int power;
         protected Motor(String newWoner, int pow)
        {
           super(newWoner);
           power=pow;
        }
         public int newMotor()
        {
         	System.out.print("write new  power(int):  ");
            power=Input.readInt();
            return power;
        }
         public void print()
        {
         	super.print();
      	   	System.out.println(" power is: "+power);
      
      	}
     }
    
      class Car extends Motor
     {
      	protected String regNr;
      	
      	protected Car(String newWoner, int pow, String reg)
       {
      		super(newWoner, pow);
      		regNr=reg;
       }
      	
      	public String newRegNbr()
       {
      	  System.out.println("write new registerNbr:(String) ");
      	  
       	  regNr=Input.readString();
       	  return regNr; 
       }
     	public void print()
       {
      	   super.print();
      	   System.out.println("Register Nr: " + regNr);
        
      	} 
    }   
    
     class Truck extends Car
    {
     	private int maxLoad;
     	public Truck(String newWoner, int pow, String reg, int maxL )
       {
     	   super (newWoner, pow, reg);
     	   maxLoad=maxL;
       } 
     	public int newMaxLoad()
       {
     	  System.out.print("write new max Load:(int) ");
      	  maxLoad=Input.readInt();
      	  return maxLoad;
       }
         public void print()
       {
      	   super.print();
      	   System.out.println("MaxLoad: "+maxLoad);
      	   System.out.println();
      	
          
        }
    }

  2. #2
    Join Date
    Nov 2004
    Location
    Minnesota
    Posts
    99
    Might help if you posted the code for the Input class...Pasting what you have into eclipse shows compile errors (missing Input code)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center