Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sammy Samkough
- // Joes Used Cars
- // Spec: Joe is interested in maintaining information for each of his cars in his fleet. The information he wants are:
- // Make, model, mileage, year, cylinders, price, and manual/automatic.
- public class Car implements Comparable
- {
- private String make, model;
- private int mileage, year, cylinders, price;
- private boolean isManual; // this is for the transmission
- public Car()
- {
- make = ""; // 1
- model = ""; // 2
- mileage = 0; // 3
- year = 0; // 4
- cylinders = 0; // 5
- price = 0; // 6
- isManual = false; // 7
- }
- public Car(String ma, String mo, int mi, int y, int c, int p, boolean im)
- {
- make = ma;
- model = mo;
- mileage = mi;
- year = y;
- cylinders = c;
- price = p;
- isManual = im;
- }
- // gets and sets
- /*-----------------------------------------------------------------------------------------------------------------------*/
- /*
- public Car getCar()
- {
- }
- */
- public void setCar(String ma, String mo, int mi, int y, int c, int p, boolean im)
- {
- make = ma;
- model = mo;
- mileage = mi;
- year = y;
- cylinders = c;
- price = p;
- isManual = im;
- }
- public String getMake()
- {
- return make;
- }
- public void setMake(String s)
- {
- make = s;
- }
- public String getModel()
- {
- return model;
- }
- public void setModel(String s)
- {
- model = s;
- }
- public int getMileage()
- {
- return mileage;
- }
- public void setMileage(int m)
- {
- mileage = m;
- }
- public int getYear()
- {
- return year;
- }
- public void setYear(int y)
- {
- year = y;
- }
- public int getCylinder()
- {
- return cylinders;
- }
- public void setCylinder(int c)
- {
- cylinders = c;
- }
- public int getPrice()
- {
- return price;
- }
- public void setPrice(int p)
- {
- price = p;
- }
- public boolean getIsManual()
- {
- return isManual;
- }
- public void setIsManual(boolean m)
- {
- isManual = m;
- }
- /*-----------------------------------------------------------------------------------------------------------------------*/
- // Car Class implements Comparable
- public int compareTo(Object obj)
- {
- Car other = (Car)obj;
- if(price > other.price)
- {
- return 1;
- }
- else if(price < other.price)
- {
- return -1;
- }
- else
- {
- return 0;
- }
- }
- public String toString()
- {
- String result = "";
- result += "The make for the car is " + make + ".\n";
- result += "The model for the car is " + model + ".\n";
- result += "The mileage for the car is " + mileage + ".\n";
- result += "The year for the car is " + year + ".\n";
- result += "The amount of cylinders the car has is " + cylinders + ".\n";
- result += "The price for the car is " + price + ".\n";
- if (isManual == true)
- {
- result += "The transmission for the car is manual.\n";
- }
- else
- {
- result += "The transmission for the car is automatic.\n";
- }
- return result;
- }
- }
- -------------------------------------------------------------------------------------------------------------------------------
- // Sammy Samkough
- // Joes Used Cars
- // Spec: Joe is interested in maintaing information for each of his cars in his fleet.
- // Make, model, mileage, year, cylinders, price, and manual/automatic.
- public class CarRunner
- {
- public static void main (String args[])
- {
- Car test = new Car("Mercedes", "Benz C-Class", 25000, 2015, 4, 40000, false);
- System.out.println(test);
- test = new Car("Honda", "Pilot", 60000, 2006, 4, 25000, false);
- }
- }
- /*
- */
- /*
- 1) Add a Car // adds a car to end of list
- 2) Insert // adds a car at a given position
- 3) Remove // remove a car from the lot
- 4) Number of Cars on Lot // size
- 5) Value of Cars on Lot // calculate total on the lot
- 6) View a Car // use get method for ArrayList
- 7) Sort by Price // Car class implements Comparable
- 8) View the Lot // iterate thru the ArrayList
- */
- -------------------------------------------------------------------------------------------------------------------------------
- // Sammy Samkough
- // Joes Used Cars
- // Spec: Joe is interested in maintaing information for each of his cars in his fleet.
- // Make, model, mileage, year, cylinders, price, and manual/automatic.
- import java.util.Scanner;
- import java.util.List;
- import java.util.ArrayList;
- import java.util.Collections;
- public class CarLot
- {
- private ArrayList<Car> ray = new ArrayList<Car>();
- public CarLot()
- {
- ray = new ArrayList<Car>();
- }
- // adds a car to the end of the list
- public void add(String ma, String mo, int mi, int y, int c, int p, boolean im)
- {
- ray.add(new Car(ma, mo, mi, y, c, p, im));
- }
- // adds a car at a given position
- public void insert(int pos, String ma, String mo, int mi, int y, int c, int p, boolean im)
- {
- ray.set(pos, new Car(ma, mo, mi, y, c, p, im));
- }
- // removes a car from the lot
- public void remove(int pos)
- {
- ray.remove(pos);
- }
- // the size
- public int numberOfCarsInLot()
- {
- int size = ray.size();
- return size;
- }
- // calculate the total on the lot
- public int valueOfCarsInLot()
- {
- int total = 0;
- for (int i = 0; i < ray.size(); i++)
- {
- total += ray.get(i).getPrice();
- }
- return total;
- }
- // use get method for ArrayList
- public Car viewOfCar(int i)
- {
- return ray.get(i);
- }
- // Car class implements Comparable
- public void sortCarByPrice()
- {
- List<Car> list = new ArrayList<Car>();
- Collections.sort(list);
- }
- // iterate though the ArrayList
- public void viewTheLot()
- {
- for (int i = 0; i < ray.size(); i++)
- {
- System.out.println(ray.get(i));
- }
- }
- public String toString()
- {
- return "" + ray;
- }
- }
- /*
- */
- -------------------------------------------------------------------------------------------------------------------------------
- // Sammy Samkough
- // Joes Used Cars
- // Spec: Joe is interested in maintaing information for each of his cars in his fleet.
- // Make, model, mileage, year, cylinders, price, and manual/automatic.
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.Collections;
- public class CarLotRunner
- {
- public static void main (String args[])
- {
- CarLot fleet = new CarLot();
- fleet.add("Chevy", "Avalanche", 20000, 2013, 4, 26000, false);
- System.out.println("WE ADD A CHEVY AVALANCE: \n" + fleet); // 1
- System.out.println("--------------------------------------------------------------------------------");
- fleet.add("Audi", "R8", 20000, 2014, 8, 50000, false); // 1
- System.out.println("WE ADD AN AUDI R8 TO THE END OF THE LINE: \n" + fleet);
- System.out.println("--------------------------------------------------------------------------------");
- fleet.add("Mercedes", "Benz C-Class", 25000, 2015, 4, 40000, false); // 1
- System.out.println("WE ADD A MERCEDES BENZ C-CLASS TO THE END OF THE LINE: \n" + fleet);
- System.out.println("--------------------------------------------------------------------------------");
- fleet.insert(0, "Honda", "Pilot", 15000, 2006, 4, 25000, false); // 2
- System.out.println("WE INSERT A HONDA PILOT IN THE 1ST SPOT TO REMOVE THE CHEVY AVALANCE: \n" + fleet);
- System.out.println("--------------------------------------------------------------------------------");
- fleet.remove(1); // 3
- System.out.println("WE REMOVE THE AUDI R8 WHICH BRINGS ALL THE CARS DOWN ONE: \n" + fleet);
- System.out.println("--------------------------------------------------------------------------------");
- System.out.print("THERE ARE ");
- System.out.print(fleet.numberOfCarsInLot()); // 4
- System.out.println(" CARS IN THE LOT.");
- System.out.println("--------------------------------------------------------------------------------");
- System.out.print("THE VALUE OF THE CARS ARE $");
- System.out.print(fleet.valueOfCarsInLot()); // 5
- System.out.println(".");
- System.out.println("--------------------------------------------------------------------------------");
- System.out.println("HERE'S THE VIEW OF CAR #2: ");
- System.out.print(fleet.viewOfCar(1)); // 6
- System.out.println("--------------------------------------------------------------------------------");
- fleet.sortCarByPrice(); // 7
- System.out.println("WE ARE GOING TO SORT THE CARS BY PRICE NOW, HERE'S HOW THE FLEET LOOKS LIKE: \n" + fleet);
- System.out.println("--------------------------------------------------------------------------------");
- System.out.println("HERE'S THE VIEW OF THE LOT: ");
- fleet.viewTheLot(); // 8
- System.out.println("--------------------------------------------------------------------------------");
- System.out.println("HERE'S THE FINAL LOOK AT THE FLEET: \n" + fleet);
- }
- }
- /*
- WE ADD A CHEVY AVALANCE:
- [The make for the car is Chevy.
- The model for the car is Avalanche.
- The mileage for the car is 20000.
- The year for the car is 2013.
- The amount of cylinders the car has is 4.
- The price for the car is 26000.
- The transmission for the car is automatic.
- ]
- --------------------------------------------------------------------------------
- WE ADD AN AUDI R8 TO THE END OF THE LINE:
- [The make for the car is Chevy.
- The model for the car is Avalanche.
- The mileage for the car is 20000.
- The year for the car is 2013.
- The amount of cylinders the car has is 4.
- The price for the car is 26000.
- The transmission for the car is automatic.
- , The make for the car is Audi.
- The model for the car is R8.
- The mileage for the car is 20000.
- The year for the car is 2014.
- The amount of cylinders the car has is 8.
- The price for the car is 50000.
- The transmission for the car is automatic.
- ]
- --------------------------------------------------------------------------------
- WE ADD A MERCEDES BENZ C-CLASS TO THE END OF THE LINE:
- [The make for the car is Chevy.
- The model for the car is Avalanche.
- The mileage for the car is 20000.
- The year for the car is 2013.
- The amount of cylinders the car has is 4.
- The price for the car is 26000.
- The transmission for the car is automatic.
- , The make for the car is Audi.
- The model for the car is R8.
- The mileage for the car is 20000.
- The year for the car is 2014.
- The amount of cylinders the car has is 8.
- The price for the car is 50000.
- The transmission for the car is automatic.
- , The make for the car is Mercedes.
- The model for the car is Benz C-Class.
- The mileage for the car is 25000.
- The year for the car is 2015.
- The amount of cylinders the car has is 4.
- The price for the car is 40000.
- The transmission for the car is automatic.
- ]
- --------------------------------------------------------------------------------
- WE INSERT A HONDA PILOT IN THE 1ST SPOT TO REMOVE THE CHEVY AVALANCE:
- [The make for the car is Honda.
- The model for the car is Pilot.
- The mileage for the car is 15000.
- The year for the car is 2006.
- The amount of cylinders the car has is 4.
- The price for the car is 25000.
- The transmission for the car is automatic.
- , The make for the car is Audi.
- The model for the car is R8.
- The mileage for the car is 20000.
- The year for the car is 2014.
- The amount of cylinders the car has is 8.
- The price for the car is 50000.
- The transmission for the car is automatic.
- , The make for the car is Mercedes.
- The model for the car is Benz C-Class.
- The mileage for the car is 25000.
- The year for the car is 2015.
- The amount of cylinders the car has is 4.
- The price for the car is 40000.
- The transmission for the car is automatic.
- ]
- --------------------------------------------------------------------------------
- WE REMOVE THE AUDI R8 WHICH BRINGS ALL THE CARS DOWN ONE:
- [The make for the car is Honda.
- The model for the car is Pilot.
- The mileage for the car is 15000.
- The year for the car is 2006.
- The amount of cylinders the car has is 4.
- The price for the car is 25000.
- The transmission for the car is automatic.
- , The make for the car is Mercedes.
- The model for the car is Benz C-Class.
- The mileage for the car is 25000.
- The year for the car is 2015.
- The amount of cylinders the car has is 4.
- The price for the car is 40000.
- The transmission for the car is automatic.
- ]
- --------------------------------------------------------------------------------
- THERE ARE 2 CARS IN THE LOT.
- --------------------------------------------------------------------------------
- THE VALUE OF THE CARS ARE $65000.
- --------------------------------------------------------------------------------
- HERE'S THE VIEW OF CAR #2:
- The make for the car is Mercedes.
- The model for the car is Benz C-Class.
- The mileage for the car is 25000.
- The year for the car is 2015.
- The amount of cylinders the car has is 4.
- The price for the car is 40000.
- The transmission for the car is automatic.
- --------------------------------------------------------------------------------
- WE ARE GOING TO SORT THE CARS BY PRICE NOW, HERE'S HOW THE FLEET LOOKS LIKE:
- [The make for the car is Honda.
- The model for the car is Pilot.
- The mileage for the car is 15000.
- The year for the car is 2006.
- The amount of cylinders the car has is 4.
- The price for the car is 25000.
- The transmission for the car is automatic.
- , The make for the car is Mercedes.
- The model for the car is Benz C-Class.
- The mileage for the car is 25000.
- The year for the car is 2015.
- The amount of cylinders the car has is 4.
- The price for the car is 40000.
- The transmission for the car is automatic.
- ]
- --------------------------------------------------------------------------------
- HERE'S THE VIEW OF THE LOT:
- The make for the car is Honda.
- The model for the car is Pilot.
- The mileage for the car is 15000.
- The year for the car is 2006.
- The amount of cylinders the car has is 4.
- The price for the car is 25000.
- The transmission for the car is automatic.
- The make for the car is Mercedes.
- The model for the car is Benz C-Class.
- The mileage for the car is 25000.
- The year for the car is 2015.
- The amount of cylinders the car has is 4.
- The price for the car is 40000.
- The transmission for the car is automatic.
- --------------------------------------------------------------------------------
- HERE'S THE FINAL LOOK AT THE FLEET:
- [The make for the car is Honda.
- The model for the car is Pilot.
- The mileage for the car is 15000.
- The year for the car is 2006.
- The amount of cylinders the car has is 4.
- The price for the car is 25000.
- The transmission for the car is automatic.
- , The make for the car is Mercedes.
- The model for the car is Benz C-Class.
- The mileage for the car is 25000.
- The year for the car is 2015.
- The amount of cylinders the car has is 4.
- The price for the car is 40000.
- The transmission for the car is automatic.
- ]
- Press any key to continue . . .
- */
- /*
- 1) Add a Car // adds a car to end of list
- 2) Insert // adds a car at a given position
- 3) Remove // remove a car from the lot
- 4) Number of Cars on Lot // size
- 5) Value of Cars on Lot // calculate total on the lot
- 6) View a Car // use get method for ArrayList
- 7) Sort by Price // Car class implements Comparable
- 8) View the Lot // iterate thru the ArrayList
- */
- -------------------------------------------------------------------------------------------------------------------------------
- // Sammy Samkough
- // Joes Used Cars
- // Spec: Joe is interested in maintaing information for each of his cars in his fleet.
- // Make, model, mileage, year, cylinders, price, and manual/automatic.
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.Collections;
- public class CarLotRunnerSwitch
- {
- public static void main (String args[])
- {
- CarLot fleet = new CarLot();
- Scanner sc = new Scanner(System.in);
- int choice = 0;
- String input = "";
- int point = 0;
- boolean running = true;
- System.out.println("Hello and welcome to Joe's Used Cars! Type a number from 1-9 to choose what you wanna explore here!");
- while (running)
- {
- System.out.println("Here's the option list from what you can choose from:");
- System.out.println("1: Add a car");
- System.out.println("2: Insert a car");
- System.out.println("3: Remove a car");
- System.out.println("4: Number of cars in lot");
- System.out.println("5: Value of cars in lot");
- System.out.println("6: View of car");
- System.out.println("7: Sorting cars by price");
- System.out.println("8: Viewing the lot");
- System.out.println("9: Exit");
- System.out.println("Now please, choose one of them:");
- choice = sc.nextInt();
- switch (choice)
- {
- case 1: // add
- System.out.println("You chose the add a car option!");
- System.out.println("Type in your make, model, mileage, year, cylinders, price, and transmission(manual or automatic) for the car, in that order! Press enter after your done inputting the information for each spec.");
- fleet.add(sc.nextLine(), sc.nextLine(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextBoolean());
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 2: // insert
- System.out.println("You chose the insert a car option!");
- System.out.println("Please type in for me your point for the car you'd like to place it in, make, model, mileage, year, cylinders, and price for the car, in that order! Press enter after your done inputting the information for each spec.");
- fleet.insert(sc.nextInt(), sc.nextLine(), sc.nextLine(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextBoolean());
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 3: // remove
- System.out.println("You chose the remove a car option!");
- System.out.println("What's the point of the car that you'd like to remove?");
- point = sc.nextInt();
- fleet.remove(point);
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 4: // number of cars in lot
- System.out.println("You chose the number of cars in lot option!");
- System.out.print("The number of cars in lot are: ");
- System.out.println(fleet.numberOfCarsInLot());
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 5: // value of cars in lot
- System.out.println("You chose the value of cars in lot option!");
- System.out.print("The value of all of the cars combined in the car lot is: ");
- System.out.println(fleet.valueOfCarsInLot());
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 6: // view a car
- System.out.println("You chose the view a car option!");
- System.out.print("Which car would you like to view?");
- int c = 0;
- c = sc.nextInt();
- System.out.print("The car is: ");
- System.out.println(fleet.viewOfCar(c));
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 7: // sort by price
- System.out.println("You chose the sort by price option!");
- fleet.sortCarByPrice();
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 8: // view the lot
- System.out.println("You chose the view the lot option!");
- System.out.println(fleet.viewTheLot());
- System.out.println("--------------------------------------------------------------------------------------");
- break;
- case 9 : // exit
- System.out.println("You chose the exit option!");
- System.out.println("Would you like to exit (enter yes or no)?");
- input = sc.nextLine();
- if (input.equalsIgnoreCase("yes"))
- {
- System.out.println("Ba-bye then!");
- running = false;
- }
- else
- {
- // continues
- }
- break;
- default:
- System.out.println("Please input something we asked of you, not anything else.");
- }
- }
- }
- }
- /*
- */
- /*
- 1) Add a Car // adds a car to end of list
- 2) Insert // adds a car at a given position
- 3) Remove // remove a car from the lot
- 4) Number of Cars on Lot // size
- 5) Value of Cars on Lot // calculate total on the lot
- 6) View a Car // use get method for ArrayList
- 7) Sort by Price // Car class implements Comparable
- 8) View the Lot // iterate thru the ArrayList
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement