Last active
August 29, 2015 14:00
-
-
Save JorgeOlvera/7c471ba4718c4c3fd715 to your computer and use it in GitHub Desktop.
Car class + Car App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class carClass{ | |
public class Car{ | |
private String brand; | |
private double pricePerDay; | |
private int availablity; | |
public Car(String brand, double pricePerDay int availablity){ | |
this.availablity = availablity; | |
this.pricePerDay = pricePerDay; | |
this.brand = brand; | |
} | |
public String getBrand(){ | |
return this.brand; | |
} | |
public void setBrand(String brand){ | |
this.brand = brand; | |
} | |
public double getpricePerDay(){ | |
return this.pricePerDay; | |
} | |
public void setPricePerDay(double pricePerDay){ | |
this.pricePerDay = pricePerDay; | |
} | |
public int getavailablity(){ | |
return this.availablity; | |
} | |
public void setAvailability(int availablity){ | |
this.availablity = availablity; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import.java.util.Scanner; | |
import.java.io.*; | |
public class carApp; | |
public static void main(String[] args) { | |
Random rndm = new Random(); | |
String datbrand = " "; | |
double datPrice = 0; | |
int datAvailability = 0; | |
Car[] vehicles = new Car[100]; | |
String[] brands = {"Ford", "Land Rover", "Audi", "Mercedes", "BMW", "Maserati", "Tesla", "Mitsubishi", "Acura", "Citröen"}; | |
double[] price = {4, 23, 7, 96, 666, 420, 808, 333}; | |
int[] availability = {0, 1, 2, 3, 4, 5, 6, 7}; | |
for(int a=0; a<100; a++){ | |
datbrand = brands[number.nextInt(10)]; | |
datPrice = price[number.nextInt(10)]; | |
datAvailability = availability[number.nextInt(10)]; | |
Car carro = new Car(thebrand, theprice, theavailability); | |
vehicles[a] = automobile; | |
int carnmbr = findCar(vehicles); | |
rentCar(vehicles, carnmbr); | |
} | |
//method 2.1 | |
public boolean findCar(){ | |
Scanner input = new Scanner(System.in); | |
//search cars for first available | |
boolean bateado; | |
char acceptOrReject; | |
for (int i=0; i<99; i++){ | |
if (cars[i]=0){ | |
System.out.println("Car" + i + "is available for rent. Do you wish to rent it (Type 'y' or 'n'?"); | |
acceptOrReject = input.nextln() | |
if (acceptOrReject.charAt(0) = n){ | |
bateado = true; | |
i += i; | |
} | |
else if (acceptOrReject.charAt(0) = n){ | |
bateado = false; | |
} | |
else break; | |
return bateado; | |
} | |
} | |
} | |
//method 2.2 | |
public static rentCar(Cars[] vehic, int carnmbr){ | |
Scanner input = new Scanner(System.in); | |
System.out.println("For how many days do you want to rent the car?"); | |
int rent = input.nextInt(); | |
vehicles[carnmbr].setAvailability(rent); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static readAndWrite{ | |
File inputFile = new File(carApp); | |
byte[] data = new byte[inputFile.length()]; | |
FileInputStream fis = new FileInputStream(inputFile); | |
fis.read(data, 0, data.length); | |
fis.close(); | |
FileOutputStream fos = new FileOutputStream | |
fos.write(data, 0, data.length); | |
fos.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment