Can't figure out error in OOP

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2007
Posts: 47
Reputation: Dio1080 is an unknown quantity at this point 
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Can't figure out error in OOP

 
0
  #1
Apr 8th, 2008
I can't figure out why it is saying (Vehicle.java:174: cannot find symbol) but there is a symbol, what is going on?

  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Vehicle{
  5. protected int hp;
  6. protected int mileage;
  7. protected int year;
  8. public String make;
  9. public String model;
  10.  
  11. Vehicle(){
  12. hp = 0;
  13. mileage = 0;
  14. year = 0;
  15. }
  16.  
  17. public void Set(int inputhp, int inputmileage, int inputyear){
  18. hp = inputhp;
  19. mileage = inputmileage;
  20. year = inputyear;
  21. }
  22.  
  23. //public static void Print(int hp, int mileage, int year){
  24. /*
  25. public void Print(Vehicle carinfo){
  26.  
  27. System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
  28. "\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
  29. }
  30. */
  31.  
  32.  
  33.  
  34. public void Print(){
  35.  
  36. System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
  37. "\n Make: " + make + "\n Model: " + model);
  38. }
  39.  
  40. /*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){
  41.  
  42. int count = 0;
  43. for(i = 0; i < 1; i++){
  44.  
  45. if(yearcheck = carinfo[i].year){
  46. System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
  47. count++;
  48. }
  49. }
  50. if(count = 0){
  51. System.out.println("There were no matches of that year");
  52. }
  53. }
  54.  
  55. */
  56.  
  57.  
  58. public static void main(String[] args){
  59.  
  60. Scanner keyboard = new Scanner(System.in);
  61. int inputyear;
  62. int inputmileage;
  63. int inputhp;
  64. String makeinput;
  65. String modelinput;
  66. int capacitypassed;
  67. boolean isable;
  68. int numdoorsinput;
  69. //System.out.println("How many cars would you like to Enter the information for?");
  70.  
  71.  
  72. //int input1 = keyboard.next();
  73.  
  74. Vehicle carinfo = new Vehicle();
  75.  
  76.  
  77. System.out.println("Enter the horsepower of the car.");
  78. inputhp = keyboard.nextInt();
  79. //carinfo.hp.Set() = inputhp;
  80. System.out.println("Enter the mileage of the car.");
  81. inputmileage = keyboard.nextInt();
  82. //carinfo.mileage.set = inputmileage;
  83. System.out.println("Enter the year of the car.");
  84. inputyear = keyboard.nextInt();
  85.  
  86. carinfo.Set(inputhp, inputmileage, inputyear);
  87.  
  88. //carinfo.year.set = inputyear;
  89.  
  90.  
  91. System.out.println("Enter the make of the car.");
  92. makeinput = keyboard.next();
  93. carinfo.make = makeinput;
  94. System.out.println("Enter the model of the car.") ;
  95. modelinput = keyboard.next();
  96. carinfo.model = modelinput;
  97. carinfo.Print();
  98.  
  99.  
  100. Truck[] truckinfo = new Truck[2];
  101. for(int i = 0; i < truckinfo.length; i++){
  102. truckinfo[i] = new Truck();
  103. System.out.println("Enter the horsepower of truck number " + (i + 1));
  104. inputhp = keyboard.nextInt();
  105.  
  106. System.out.println("Enter the mileage of truck number " + (i + 1));
  107. inputmileage = keyboard.nextInt();
  108.  
  109. System.out.println("Enter the year of truck number " + (i + 1));
  110. inputyear = keyboard.nextInt();
  111.  
  112. truckinfo[i].Set(inputhp, inputmileage, inputyear);
  113.  
  114. System.out.println("Enter the make of truck number " + (i + 1));
  115. truckinfo[i].make = makeinput;
  116. System.out.println("Enter the model of truck number " + (i + 1));
  117. truckinfo[i].model = modelinput;
  118. System.out.println("Enter the number of doors for truck number " + (i + 1));
  119. numdoorsinput = keyboard.nextInt();
  120. System.out.println("Enter the towing capacity of truck number " + (i + 1));
  121. capacitypassed = keyboard.nextInt();
  122. truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);
  123.  
  124. }
  125. for(int i = 0; i < truckinfo.length; i++){
  126. truckinfo[i].Print2(i);
  127. }
  128.  
  129. System.out.println("How much weight are you trying to tow?");
  130. capacitypassed = keyboard.nextInt();
  131.  
  132. for(int i = 0; i < truckinfo.length; i++){
  133. isable = truckinfo[i].tow_check(capacitypassed, i);
  134. if(isable = true){
  135. System.out.println("We have a truck that can tow the desired weight");
  136. }else System.out.println("We don't have a truck that can tow that much weight.");
  137. }
  138.  
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. }
  147. class Truck extends Vehicle{
  148. private int numdoors;
  149. private int towingcap;
  150.  
  151.  
  152. Truck(){
  153. numdoors = 0;
  154. towingcap = 0;
  155. }
  156.  
  157.  
  158.  
  159. public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
  160. towingcap = capacitypassed;
  161. numdoors = numdoorsinput;
  162. }
  163. public void Print2(int i){
  164.  
  165.  
  166. System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
  167. "\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors +
  168. "\n Towing Capacity: " + towingcap);
  169.  
  170. }
  171.  
  172. public boolean tow_check(int capacitypassed, int i){
  173.  
  174. if(capacitypassed > truckinfo[i].towingcap){
  175. return false;
  176. }else
  177. return true;
  178. }
  179.  
  180.  
  181. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,515
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Can't figure out error in OOP

 
0
  #2
Apr 8th, 2008
It would help a lot if you either used [code=java], which would place line numbers in the listing or highlighted the line number in your code, since most can't just quickly pick out line 174. Here is that code with line numbers:
Originally Posted by Dio1080 View Post
I can't figure out why it is saying (Vehicle.java:174: cannot find symbol) but there is a symbol, what is going on?

  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Vehicle{
  5. protected int hp;
  6. protected int mileage;
  7. protected int year;
  8. public String make;
  9. public String model;
  10.  
  11. Vehicle(){
  12. hp = 0;
  13. mileage = 0;
  14. year = 0;
  15. }
  16.  
  17. public void Set(int inputhp, int inputmileage, int inputyear){
  18. hp = inputhp;
  19. mileage = inputmileage;
  20. year = inputyear;
  21. }
  22.  
  23. //public static void Print(int hp, int mileage, int year){
  24. /*
  25. public void Print(Vehicle carinfo){
  26.  
  27. System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
  28. "\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
  29. }
  30. */
  31.  
  32.  
  33.  
  34. public void Print(){
  35.  
  36. System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
  37. "\n Make: " + make + "\n Model: " + model);
  38. }
  39.  
  40. /*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){
  41.  
  42. int count = 0;
  43. for(i = 0; i < 1; i++){
  44.  
  45. if(yearcheck = carinfo[i].year){
  46. System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
  47. count++;
  48. }
  49. }
  50. if(count = 0){
  51. System.out.println("There were no matches of that year");
  52. }
  53. }
  54.  
  55. */
  56.  
  57.  
  58. public static void main(String[] args){
  59.  
  60. Scanner keyboard = new Scanner(System.in);
  61. int inputyear;
  62. int inputmileage;
  63. int inputhp;
  64. String makeinput;
  65. String modelinput;
  66. int capacitypassed;
  67. boolean isable;
  68. int numdoorsinput;
  69. //System.out.println("How many cars would you like to Enter the information for?");
  70.  
  71.  
  72. //int input1 = keyboard.next();
  73.  
  74. Vehicle carinfo = new Vehicle();
  75.  
  76.  
  77. System.out.println("Enter the horsepower of the car.");
  78. inputhp = keyboard.nextInt();
  79. //carinfo.hp.Set() = inputhp;
  80. System.out.println("Enter the mileage of the car.");
  81. inputmileage = keyboard.nextInt();
  82. //carinfo.mileage.set = inputmileage;
  83. System.out.println("Enter the year of the car.");
  84. inputyear = keyboard.nextInt();
  85.  
  86. carinfo.Set(inputhp, inputmileage, inputyear);
  87.  
  88. //carinfo.year.set = inputyear;
  89.  
  90.  
  91. System.out.println("Enter the make of the car.");
  92. makeinput = keyboard.next();
  93. carinfo.make = makeinput;
  94. System.out.println("Enter the model of the car.") ;
  95. modelinput = keyboard.next();
  96. carinfo.model = modelinput;
  97. carinfo.Print();
  98.  
  99.  
  100. Truck[] truckinfo = new Truck[2];
  101. for(int i = 0; i < truckinfo.length; i++){
  102. truckinfo[i] = new Truck();
  103. System.out.println("Enter the horsepower of truck number " + (i + 1));
  104. inputhp = keyboard.nextInt();
  105.  
  106. System.out.println("Enter the mileage of truck number " + (i + 1));
  107. inputmileage = keyboard.nextInt();
  108.  
  109. System.out.println("Enter the year of truck number " + (i + 1));
  110. inputyear = keyboard.nextInt();
  111.  
  112. truckinfo[i].Set(inputhp, inputmileage, inputyear);
  113.  
  114. System.out.println("Enter the make of truck number " + (i + 1));
  115. truckinfo[i].make = makeinput;
  116. System.out.println("Enter the model of truck number " + (i + 1));
  117. truckinfo[i].model = modelinput;
  118. System.out.println("Enter the number of doors for truck number " + (i + 1));
  119. numdoorsinput = keyboard.nextInt();
  120. System.out.println("Enter the towing capacity of truck number " + (i + 1));
  121. capacitypassed = keyboard.nextInt();
  122. truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);
  123.  
  124. }
  125. for(int i = 0; i < truckinfo.length; i++){
  126. truckinfo[i].Print2(i);
  127. }
  128.  
  129. System.out.println("How much weight are you trying to tow?");
  130. capacitypassed = keyboard.nextInt();
  131.  
  132. for(int i = 0; i < truckinfo.length; i++){
  133. isable = truckinfo[i].tow_check(capacitypassed, i);
  134. if(isable = true){
  135. System.out.println("We have a truck that can tow the desired weight");
  136. }else System.out.println("We don't have a truck that can tow that much weight.");
  137. }
  138.  
  139. }
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. }
  147. class Truck extends Vehicle{
  148. private int numdoors;
  149. private int towingcap;
  150.  
  151.  
  152. Truck(){
  153. numdoors = 0;
  154. towingcap = 0;
  155. }
  156.  
  157.  
  158.  
  159. public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
  160. towingcap = capacitypassed;
  161. numdoors = numdoorsinput;
  162. }
  163. public void Print2(int i){
  164.  
  165.  
  166. System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
  167. "\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors +
  168. "\n Towing Capacity: " + towingcap);
  169.  
  170. }
  171.  
  172. public boolean tow_check(int capacitypassed, int i){
  173.  
  174. if(capacitypassed > truckinfo[i].towingcap){
  175. return false;
  176. }else
  177. return true;
  178. }
  179.  
  180.  
  181. }
Which points to this line
  1. if(capacitypassed > truckinfo[i].towingcap){
The rest of the compiler message should have told you which symbol was not found - which in this case is "truckinfo" because there is no "truckinfo" in that method or in the class.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 47
Reputation: Dio1080 is an unknown quantity at this point 
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Re: Can't figure out error in OOP

 
0
  #3
Apr 8th, 2008
ok, i fixed that, and it compiles but after i enter in a few things, it says, Exception in thread "main" java.lang.NullPointerException at Vehicle.main(Vehicle.java:112) but it worked for the vehicle class, but not the truck class, just compile and you'll see what I'm taking about.

  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Vehicle{
  5. protected int hp;
  6. protected int mileage;
  7. protected int year;
  8. public String make;
  9. public String model;
  10.  
  11. Vehicle(){
  12. hp = 0;
  13. mileage = 0;
  14. year = 0;
  15. }
  16.  
  17. public void Set(int inputhp, int inputmileage, int inputyear){
  18. hp = inputhp;
  19. mileage = inputmileage;
  20. year = inputyear;
  21. }
  22.  
  23. //public static void Print(int hp, int mileage, int year){
  24. /*
  25.   public void Print(Vehicle carinfo){
  26.  
  27.   System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
  28.   "\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
  29.   }
  30.   */
  31.  
  32.  
  33.  
  34. public void Print(){
  35.  
  36. System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
  37. "\n Make: " + make + "\n Model: " + model);
  38. }
  39.  
  40. /*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){
  41.  
  42.   int count = 0;
  43.   for(i = 0; i < 1; i++){
  44.  
  45.   if(yearcheck = carinfo[i].year){
  46.   System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
  47.   count++;
  48.   }
  49.   }
  50.   if(count = 0){
  51.   System.out.println("There were no matches of that year");
  52.   }
  53.   }
  54.  
  55.   */
  56.  
  57.  
  58. public static void main(String[] args )throws Exception {
  59.  
  60. Scanner keyboard = new Scanner(System.in);
  61. int inputyear;
  62. int inputmileage;
  63. int inputhp;
  64. String makeinput;
  65. String modelinput;
  66. int capacitypassed;
  67. boolean isable;
  68. int numdoorsinput;
  69. //System.out.println("How many cars would you like to Enter the information for?");
  70.  
  71.  
  72. //int input1 = keyboard.next();
  73.  
  74. Vehicle carinfo = new Vehicle();
  75.  
  76.  
  77. System.out.println("Enter the horsepower of the car.");
  78. inputhp = keyboard.nextInt();
  79. //carinfo.hp.Set() = inputhp;
  80. System.out.println("Enter the mileage of the car.");
  81. inputmileage = keyboard.nextInt();
  82. //carinfo.mileage.set = inputmileage;
  83. System.out.println("Enter the year of the car.");
  84. inputyear = keyboard.nextInt();
  85.  
  86. carinfo.Set(inputhp, inputmileage, inputyear);
  87.  
  88. //carinfo.year.set = inputyear;
  89.  
  90.  
  91. System.out.println("Enter the make of the car.");
  92. makeinput = keyboard.next();
  93. carinfo.make = makeinput;
  94. System.out.println("Enter the model of the car.") ;
  95. modelinput = keyboard.next();
  96. carinfo.model = modelinput;
  97. carinfo.Print();
  98.  
  99.  
  100. Truck[] truckinfo = new Truck[2];
  101. for(int i = 0; i < truckinfo.length; i++){
  102. //truckinfo[i] = new Truck();
  103. System.out.println("Enter the horsepower of truck number " + (i + 1));
  104. inputhp = keyboard.nextInt();
  105.  
  106. System.out.println("Enter the mileage of truck number " + (i + 1));
  107. inputmileage = keyboard.nextInt();
  108.  
  109. System.out.println("Enter the year of truck number " + (i + 1));
  110. inputyear = keyboard.nextInt();
  111.  
  112. truckinfo[i].Set(inputhp, inputmileage, inputyear);
  113.  
  114. System.out.println("Enter the make of truck number " + (i + 1));
  115. truckinfo[i].make = makeinput;
  116. System.out.println("Enter the model of truck number " + (i + 1));
  117. truckinfo[i].model = modelinput;
  118. System.out.println("Enter the number of doors for truck number " + (i + 1));
  119. numdoorsinput = keyboard.nextInt();
  120. System.out.println("Enter the towing capacity of truck number " + (i + 1));
  121. capacitypassed = keyboard.nextInt();
  122. truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);
  123.  
  124. }
  125. for(int i = 0; i < truckinfo.length; i++){
  126. truckinfo[i].Print2(i);
  127. }
  128.  
  129. System.out.println("How much weight are you trying to tow?");
  130. capacitypassed = keyboard.nextInt();
  131.  
  132. /*for(int i = 0; i < truckinfo.length; i++){
  133.   isable = truckinfo[i].tow_check(capacitypassed, i);
  134.   if(isable = true){
  135.   System.out.println("We have a truck that can tow the desired weight");
  136.   }else System.out.println("We don't have a truck that can tow that much weight.");
  137.   }
  138.  
  139.   }*/
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. }
  147. class Truck extends Vehicle{
  148. private int numdoors;
  149. private int towingcap;
  150.  
  151.  
  152. Truck(){
  153. numdoors = 0;
  154. towingcap = 0;
  155. }
  156.  
  157.  
  158.  
  159. public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
  160. towingcap = capacitypassed;
  161. numdoors = numdoorsinput;
  162. }
  163. public void Print2(int i){
  164.  
  165.  
  166. System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
  167. "\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors +
  168. "\n Towing Capacity: " + towingcap);
  169.  
  170. }
  171.  
  172. public boolean tow_check(int capacitypassed, int i,Truck []truckinfo){
  173.  
  174. if(capacitypassed > truckinfo[i].towingcap){
  175. return false;
  176. }
  177. else
  178. return true;
  179. }
  180.  
  181.  
  182. }
  183. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 31
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: Can't figure out error in OOP

 
0
  #4
Apr 8th, 2008
so lets look at line 112:
  1. truckinfo[i].Set(inputhp, inputmileage, inputyear);

The two references that you dereference in that line are "truckinfo" and "truckinfo[i]". "truckinfo" isn't null because you initialized it to a new array before the loop.

As for "truckinfo[i]", no elements of the array have ever been set to anything in your code. "truckinfo" is an array of references, so all the elements are initialized to null by default.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 47
Reputation: Dio1080 is an unknown quantity at this point 
Solved Threads: 0
Dio1080's Avatar
Dio1080 Dio1080 is offline Offline
Light Poster

Re: Can't figure out error in OOP

 
0
  #5
Apr 8th, 2008
ok, i uncommented out what I had commented, now I'm getting this error, truckinfo[i] = new Truck(); Vehicle.java:103: non-static variable this cannot be referenced from a static context, i tried looking this up by googleing but no luck, changing the non statics to statics does no good, any way to fix this error?

  1. import java.util.Scanner;
  2.  
  3.  
  4. public class Vehicle{
  5. protected int hp;
  6. protected int mileage;
  7. protected int year;
  8. public String make;
  9. public String model;
  10.  
  11. Vehicle(){
  12. hp = 0;
  13. mileage = 0;
  14. year = 0;
  15. }
  16.  
  17. public void Set(int inputhp, int inputmileage, int inputyear){
  18. hp = inputhp;
  19. mileage = inputmileage;
  20. year = inputyear;
  21. }
  22.  
  23. //public static void Print(int hp, int mileage, int year){
  24. /*
  25.   public void Print(Vehicle carinfo){
  26.  
  27.   System.out.println("Horsepower: " + carinfo.hp + "\n Mileage: " + carinfo.mileage + "\n Year: " + carinfo.year +
  28.   "\n Make: " + carinfo.make + "\n Model: " + carinfo.model);
  29.   }
  30.   */
  31.  
  32.  
  33.  
  34. public void Print(){
  35.  
  36. System.out.println("Horsepower: " + hp + "\n Mileage: " + mileage + "\n Year: " + year +
  37. "\n Make: " + make + "\n Model: " + model);
  38. }
  39.  
  40. /*public static void CheckYear(int year, Vehicle carinfo, int i, int yearcheck){
  41.  
  42.   int count = 0;
  43.   for(i = 0; i < 1; i++){
  44.  
  45.   if(yearcheck = carinfo[i].year){
  46.   System.out.println("The year inputed matches a " + carinfo.year + " " + carinfo.make + " " + carinfo.model + " in our database.");
  47.   count++;
  48.   }
  49.   }
  50.   if(count = 0){
  51.   System.out.println("There were no matches of that year");
  52.   }
  53.   }
  54.  
  55.   */
  56.  
  57.  
  58. public static void main(String[] args )throws Exception {
  59.  
  60. Scanner keyboard = new Scanner(System.in);
  61. int inputyear;
  62. int inputmileage;
  63. int inputhp;
  64. String makeinput;
  65. String modelinput;
  66. int capacitypassed;
  67. boolean isable;
  68. int numdoorsinput;
  69. //System.out.println("How many cars would you like to Enter the information for?");
  70.  
  71.  
  72. //int input1 = keyboard.next();
  73.  
  74. Vehicle carinfo = new Vehicle();
  75.  
  76.  
  77. System.out.println("Enter the horsepower of the car.");
  78. inputhp = keyboard.nextInt();
  79. //carinfo.hp.Set() = inputhp;
  80. System.out.println("Enter the mileage of the car.");
  81. inputmileage = keyboard.nextInt();
  82. //carinfo.mileage.set = inputmileage;
  83. System.out.println("Enter the year of the car.");
  84. inputyear = keyboard.nextInt();
  85.  
  86. carinfo.Set(inputhp, inputmileage, inputyear);
  87.  
  88. //carinfo.year.set = inputyear;
  89.  
  90.  
  91. System.out.println("Enter the make of the car.");
  92. makeinput = keyboard.next();
  93. carinfo.make = makeinput;
  94. System.out.println("Enter the model of the car.") ;
  95. modelinput = keyboard.next();
  96. carinfo.model = modelinput;
  97. carinfo.Print();
  98.  
  99.  
  100. Truck[] truckinfo = new Truck[2];
  101.  
  102. for(int i = 0; i < truckinfo.length; i++){
  103. truckinfo[i] = new Truck();
  104. System.out.println("Enter the horsepower of truck number " + (i + 1));
  105. inputhp = keyboard.nextInt();
  106.  
  107. System.out.println("Enter the mileage of truck number " + (i + 1));
  108. inputmileage = keyboard.nextInt();
  109.  
  110. System.out.println("Enter the year of truck number " + (i + 1));
  111. inputyear = keyboard.nextInt();
  112.  
  113. truckinfo[i].Set(inputhp, inputmileage, inputyear);
  114.  
  115. System.out.println("Enter the make of truck number " + (i + 1));
  116. truckinfo[i].make = makeinput;
  117. System.out.println("Enter the model of truck number " + (i + 1));
  118. truckinfo[i].model = modelinput;
  119. System.out.println("Enter the number of doors for truck number " + (i + 1));
  120. numdoorsinput = keyboard.nextInt();
  121. System.out.println("Enter the towing capacity of truck number " + (i + 1));
  122. capacitypassed = keyboard.nextInt();
  123. truckinfo[i].TruckSet(numdoorsinput, capacitypassed, truckinfo);
  124.  
  125. }
  126. for(int i = 0; i < truckinfo.length; i++){
  127. truckinfo[i].Print2(i);
  128. }
  129.  
  130. System.out.println("How much weight are you trying to tow?");
  131. capacitypassed = keyboard.nextInt();
  132.  
  133. /*for(int i = 0; i < truckinfo.length; i++){
  134.   isable = truckinfo[i].tow_check(capacitypassed, i);
  135.   if(isable = true){
  136.   System.out.println("We have a truck that can tow the desired weight");
  137.   }else System.out.println("We don't have a truck that can tow that much weight.");
  138.   }
  139.  
  140.   }*/
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147. }
  148. class Truck extends Vehicle{
  149. private int numdoors;
  150. private int towingcap;
  151.  
  152.  
  153. Truck(){
  154. numdoors = 0;
  155. towingcap = 0;
  156. }
  157.  
  158.  
  159.  
  160. public void TruckSet(int numdoorsinput, int capacitypassed, Truck[] truckinfo){
  161. towingcap = capacitypassed;
  162. numdoors = numdoorsinput;
  163. }
  164. public void Print2(int i){
  165.  
  166.  
  167. System.out.println("Horsepower: " +hp + "\n Mileage: " + mileage + "\n Year: " +year +
  168. "\n Make: " + make + "\n Model: " + model + "\n Number of doors: " + numdoors +
  169. "\n Towing Capacity: " + towingcap);
  170.  
  171. }
  172.  
  173. public boolean tow_check(int capacitypassed, int i,Truck []truckinfo){
  174.  
  175. if(capacitypassed > truckinfo[i].towingcap){
  176. return false;
  177. }
  178. else
  179. return true;
  180. }
  181.  
  182.  
  183. }
  184. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 489 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC