here is the instructiions I am to use
Ask the user to input the number of effective cars in the shop (this number should be between 1 and 100, inclusively). In a loop, controlled by the inputted number of effective cars, ask the user to input each car data (i.e. make, model, year and price). You can assume that all input data is correct and no data validation is necessary. As soon as all input data for a car is entered, build a Car object by the constructor with parameters and then save the Car object in the array.
Here is what i have so far:
/* UMUC - CMIS 141 - Project 4
* File: Car.java
* Author: Annie Ideus-Balboa
* Date: May 13th, 2007
* Complete: May 17th, 2007
* Modified for Project 4: May 29th, 2007
* Use indications: Run the program from a command window
*/
import java.util.*;
import java.net.*;
import java.lang.*;
public class Car{
public static String make;
public static String model;
public static int year;
public static int price;
//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor
// return make of car (make accessor)
public String getMake() {
return make;
}//end method
//return model of car (model accessor)
public String getModel() {
return model;
}//end method
//return year of car (year accessor)
public int getYear() {
return year;
}//end method
//return price of car (price accessor)
public int getPrice() {
return price;
}//end method
//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}
that is Car.java file used to create new Cars
/* UMUC - CMIS 141 - Project 4
* File: CarDealerApp.ja va
* Author: Annie Ideus-Balboa
* Date: May 29thth, 2007
* Use indications: Run the program from a command window
*/
import java.util.*;
import java.net.*;
import java.lang.*;
public class CarDealerApp{
public static void main(String[] args) {
//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];
Scanner stdin = new Scanner(System. in);
//self intro
System.out.prin tln();
System.out.prin tln(" CMIS 141 Project 3");
System.out.prin tln(" File: Car.java");
System.out.prin tln(" Created by: Annie (ALI) Ideus-Balboa");
System.out.prin tln(" Due: June 3rd, 2007");
System.out.prin tln();
System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;
for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln();
System.out.prin tln("Your Car (Car c3):");
System.out.prin t("What is the make of your car? ");
String m = stdin.nextLine( );
System.out.prin t("What is the model of your car? ");
String d = stdin.nextLine( );
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop[i] = C;
}
for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln(carShop[i]);
}
}
}
now when I run this the print comes out as
Car@14318bb
Car@ca0b6
Can anyone help me with this? Thanks in Advance ALI :P
Ask the user to input the number of effective cars in the shop (this number should be between 1 and 100, inclusively). In a loop, controlled by the inputted number of effective cars, ask the user to input each car data (i.e. make, model, year and price). You can assume that all input data is correct and no data validation is necessary. As soon as all input data for a car is entered, build a Car object by the constructor with parameters and then save the Car object in the array.
Here is what i have so far:
/* UMUC - CMIS 141 - Project 4
* File: Car.java
* Author: Annie Ideus-Balboa
* Date: May 13th, 2007
* Complete: May 17th, 2007
* Modified for Project 4: May 29th, 2007
* Use indications: Run the program from a command window
*/
import java.util.*;
import java.net.*;
import java.lang.*;
public class Car{
public static String make;
public static String model;
public static int year;
public static int price;
//Car(); constructor with parameters
public Car(String m, String d, int y, int p) {
make = m;
model = d;
year = y;
price = p;
}//end constructor
// return make of car (make accessor)
public String getMake() {
return make;
}//end method
//return model of car (model accessor)
public String getModel() {
return model;
}//end method
//return year of car (year accessor)
public int getYear() {
return year;
}//end method
//return price of car (price accessor)
public int getPrice() {
return price;
}//end method
//print method
public void print() {
System.out.prin tln("Make = " + getMake() + "," + " Model = " + getModel() + "," + " Year = " + getYear() + "," + " Price = $" + getPrice());
}//end method
}
that is Car.java file used to create new Cars
/* UMUC - CMIS 141 - Project 4
* File: CarDealerApp.ja va
* Author: Annie Ideus-Balboa
* Date: May 29thth, 2007
* Use indications: Run the program from a command window
*/
import java.util.*;
import java.net.*;
import java.lang.*;
public class CarDealerApp{
public static void main(String[] args) {
//declare array of Car objects. Array name is carShop
final int MAX_SIZE = 100;
Car carShop[] = new Car[MAX_SIZE];
Scanner stdin = new Scanner(System. in);
//self intro
System.out.prin tln();
System.out.prin tln(" CMIS 141 Project 3");
System.out.prin tln(" File: Car.java");
System.out.prin tln(" Created by: Annie (ALI) Ideus-Balboa");
System.out.prin tln(" Due: June 3rd, 2007");
System.out.prin tln();
System.out.prin t("Please input the number of effective cars currently in the shop?: ");
int numberOfCars = stdin.nextInt() ;
for(int i = 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln();
System.out.prin tln("Your Car (Car c3):");
System.out.prin t("What is the make of your car? ");
String m = stdin.nextLine( );
System.out.prin t("What is the model of your car? ");
String d = stdin.nextLine( );
System.out.prin t("What is the Year of your car? ");
int y = stdin.nextInt() ;
System.out.prin t("What is the Price of your car? $");
int p = stdin.nextInt() ;
Car C = new Car(m, d, y, p);
carShop[i] = C;
}
for (int i= 0; (i < numberOfCars) && (i < MAX_SIZE); ++i) {
System.out.prin tln(carShop[i]);
}
}
}
now when I run this the print comes out as
Car@14318bb
Car@ca0b6
Can anyone help me with this? Thanks in Advance ALI :P
Comment