Hi I need help creating a program in JAVA. This is material from chapter 9 Objects and Classes from the Intro to JAVA textbook.
Mrs. Quackenbush's Rent-A-Wreck car rental ..... Mrs. Q asked you to create a program that can help her track her growing fleet of junkers. Of course she expects you to use your best programming skills, including:
1. Plan and design what attributes/actions an automobile in a rental fleet should have (example. Track number of Trucks, SUVs, and Cars. Each category of vechicles could come in one of three colors: White, Silver, and Black.)
2. The construction of a class or classes that will make the code:
reusable
encapsulated
easy to change (all code will change eventually?)
free from duplicate code
use constructors, attributes and methods to simulate real-life entities
have the ability to inherit from other classes (Have instructor discuss)
use conventions common to the language and your current class
----------------------------Vehicle.java-------------------------
class Vehicle
{
// store the track number of vehicle
public String trackNumber;
//store the type like Trucks, SUVs, and Cars
public String type;
// true if rented by someone
// false if not rented by anyone
public boolean ifRented;
public String color;
// store the name of person who rented the car
public String rentedBy;
// called when not rented by anyone
Vehicle(String trackNumber, String type, boolean ifRented, String color)
{
this.trackNumber = trackNumber;
this.type = type;
this.ifRented = ifRented;
this.color = color;
this.rentedBy = "";
}
// called when rented by someone
Vehicle(String trackNumber, String type, boolean ifRented, String color, String rentedBy)
{
this.trackNumber = trackNumber;
this.type = type;
this.ifRented = ifRented;
this.color = color;
this.rentedBy = rentedBy;
}
// setter method
public void setTrackNumber(String trackNumber)
{
this.trackNumber = trackNumber;
}
public void setType(String type)
{
this.type = type;
}
public void setColor(String color)
{
this.color = color;
}
// getter method
public String getTrackNumber()
{
return this.trackNumber;
}
public String getType()
{
return this.type;
}
public String getColor()
{
return this.color;
}
// return true if rented by someone
// return false if not rented by anyone
public boolean isRented()
{
return this.ifRented;
}
// get the name of the person who rented the car
public String getRentedBy()
{
return this.rentedBy;
}
// rent the car
public void rent(String rentedBy)
{
if(this.ifRented == true)
System.out.println("The car with tracking number " + this.trackNumber + " is already rented by " + this.rentedBy + "\n");
else
{
this.ifRented = true;
this.rentedBy = rentedBy;
}
}
}
------------------------------Rental.java-----------------------------
import java.util.*;
public class Rental
{
// store the list of vehicles
public ArrayList<Vehicle> veh;
// default constructor
Rental()
{
System.out.print("Hi1");
veh = new ArrayList<Vehicle>();
}
// default constructor
Rental(ArrayList<Vehicle> ob)
{
veh = new ArrayList<Vehicle>();
int i;
for( i = 0 ; i < ob.size() ; i++ )
{
// store the track number of vehicle
String trackNumber = ob.get(i).getTrackNumber();
//store the type like Trucks, SUVs, and Cars
String type = ob.get(i).getType();
// true if rented by someone
// false if not rented by anyone
boolean ifRented = ob.get(i).isRented();
String color = ob.get(i).getColor();
// store the name of person who rented the car
String rentedBy = ob.get(i).getRentedBy();
// add a new vehicle object to arraylist
veh.add( new Vehicle( trackNumber , type , ifRented , color , rentedBy ) );
}
}
// track the vehicle by track number
public void trackVehicle( String trackNumber )
{
int i;
for( i = 0 ; i < veh.size() ; i++ )
{
// if the current vehicle is the required vehicle
if( veh.get(i).getTrackNumber().equals(trackNumber) )
{
// if the vehicle is rented by someone
if( veh.get(i).isRented() == true )
{
System.out.println("Tracking Number : " + veh.get(i).getTrackNumber());
System.out.println("Type : " + veh.get(i).getType());
System.out.println("Color : " + veh.get(i).getColor());
System.out.println("Rented By : " + veh.get(i).getRentedBy() + "\n");
return;
}
// if the vehicle is not rented by anyone
else
{
System.out.println("The vehicle is not currently rented by anyone.");
return;
}
}
}
System.out.println("no such car.\n");
}
// rent the car with given track number
public void RentCar(String trackNumber, String name)
{
int i;
for( i = 0 ; i < veh.size() ; i++ )
{
// if the current vehicle is the required vehicle
if( veh.get(i).getTrackNumber().equals(trackNumber) )
{
// rent the vehicle
veh.get(i).rent(name);
}
}
}
}
---------------------------Test.java---------------------------
import java.util.*;
public class Test
{
public static void main(String[] args)
{
ArrayList<Vehicle> veh= new ArrayList<Vehicle>();
veh.add( new Vehicle( "ABCD 101" , "Truck" , true , "White" , "Chandler Bing" ) );
veh.add( new Vehicle( "ABCD 102" , "SUV" , false , "Black" ) );
veh.add( new Vehicle( "ABCD 103" , "Truck" , true , "White" , "Ross geller" ) );
veh.add( new Vehicle( "ABCD 104" , "Car" , false , "Black" ) );
veh.add( new Vehicle( "ABCD 105" , "Car" , false , "Black") );
veh.add( new Vehicle( "ABCD 106" , "SUV" , false , "Silver") );
// create a new Rental object
Rental ob = new Rental(veh);
ob.trackVehicle("ABCD 102");
System.out.println();
ob.trackVehicle("ABCD 103");
ob.RentCar("ABCD 106" , "Phoebe Buffay");
ob.trackVehicle("ABCD 106");
ob.RentCar("ABCD 102" , "John cena");
}
}
Sample Output
Hi I need help creating a program in JAVA. This is material from chapter 9 Objects...
Use Java and please try and show how to do each section. You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of...
code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation class with the following: ticket price (double type) and mumber of stops (int type). A CityBus is a PublicTransportation that in addition has the following: an route number (long type), an begin operation year (int type), a line name (String type), and driver(smame (String type) -A Tram is a CityBus that in addition has the following: maximum speed (int type), which indicates the maximum...
If your program does not compile, you will not receive any points! You will write a program to keep up with a Jewelry store and some of the Inventory (rings/necklaces/earrings) purchased there (The Jewelry store can be real or not) using Object-Oriented Programming (OOP). The important aspect of object-oriented programming is modular development and testing of reusable software modules. You love selling rings, necklaces, and earrings as well as programming and have decided to open a Jewelry store. To save...
(In Java) you will be creating a GUI for your calculator that evaluates the postfix expression. I have already created the postfix class that converts the expression from infix to postfix. Here's the postFix class and its stack class (https://paste.ofcode.org/bkwPyCMEBASXQL4pR2ym43) ---> PostFix class (https://paste.ofcode.org/WsEHHugXB38aziWRrp829n)--------> Stack class Your calculator should have: Text field for the postfix expression Text field for the result Two buttons: Evaluate and Clear You can start with the code written below and improvise to work with this...
need help with java In this program you will use a Stack to implement backtracking to solve Sudoku puzzles. Part I. Implement the stack class. Created a generic, singly-linked implementation of a Stack with a topPtr as the only instance variable. Implement the following methods only: public MyStack() //the constructor should simply set the topPtr to null public void push(E e) public E pop() Test your class thoroughly before using it within the soduku program Part II. Create...
Hi, I was wondering if I could get some help on a java program that I am supposed to be writing. The code that I have can be found below. Thanks in advance. Here are the requirements of the code 1) Create 3 cube objects. The size of each of the cubes should be input from the keyboard (hint: study the code below) 2) Print the Side length, Surface area and Volume to the users screen (console) for each of...
Need help with this Java question in 1 hour please JAVA Using the files from the in-class assignment add two additional animals of your choice. For each animal add two additional methods appropriate to your particular animal. As the majority of the code for this program exists you will not need an algorithm. Use the 3 java classes below. Thank you //Animal.java public class Animal { public Animal() { System.out.println("A new animal has been created!"); } ...
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
My Java code from last assignment: Previous Java code: public static void main(String args[]) { // While loop set-up boolean flag = true; while (flag) { Scanner sc = new Scanner(System.in); // Ask user to enter employee number System.out.print("Enter employee number: "); int employee_number = sc.nextInt(); // Ask user to enter last name System.out.print("Enter employee last name: "); String last_name = sc.next(); // Ask user to enter number of hours worked System.out.print("Enter number of hours worked: "); int hours_worked =...
Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in interesting ways. Now you’ll get a chance to use more of what objects offer, implementing inheritance and polymorphism and seeing them in action. You’ll also get a chance to create and use abstract classes (and, perhaps, methods). After this project, you will have gotten a good survey of object-oriented programming and its potential. This project won’t have a complete UI but will have a...