Commit 7f3cc3eb authored by christopher.foster's avatar christopher.foster

Can purchase and return cars

parent 05ac3b73
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".orderDetails"></activity> <activity android:name=".returnCar"></activity>
<activity android:name=".orderDetails" />
<activity android:name=".carPurchase" /> <activity android:name=".carPurchase" />
<activity android:name=".Carlist" /> <activity android:name=".Carlist" />
<activity android:name=".login" /> <activity android:name=".login" />
......
...@@ -18,4 +18,9 @@ public class Carlist extends AppCompatActivity { ...@@ -18,4 +18,9 @@ public class Carlist extends AppCompatActivity {
Intent orderScreen = new Intent(this,carPurchase.class); Intent orderScreen = new Intent(this,carPurchase.class);
startActivity(orderScreen); startActivity(orderScreen);
} }
public void carReturn(View v)
{
Intent I = new Intent(this, returnCar.class);
startActivity(I);
}
} }
...@@ -6,15 +6,17 @@ import android.content.Intent; ...@@ -6,15 +6,17 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
public class carPurchase extends AppCompatActivity { public class carPurchase extends AppCompatActivity {
private boolean benz = false; public static boolean benz = false;
private boolean toyota = false; public static boolean toyota = false;
private boolean honda = false; public static boolean honda = false;
private boolean jaguar = false; public static boolean jaguar = false;
private boolean audi = false; public static boolean audi = false;
private boolean valid = false;
private String test = "not working"; private String test = "not working";
public static String choice = ""; public static String choice = "";
...@@ -24,48 +26,160 @@ public class carPurchase extends AppCompatActivity { ...@@ -24,48 +26,160 @@ public class carPurchase extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_car_purchase); setContentView(R.layout.activity_car_purchase);
Toast.makeText(getApplicationContext(), "working", Toast.LENGTH_LONG); Toast.makeText(getApplicationContext(), "working", Toast.LENGTH_LONG);
updateStatus();
} }
public void updateStatus()
{
TextView Benz = (TextView)findViewById(R.id.benzStat);
TextView Toy = (TextView)findViewById(R.id.toyStat);
TextView Hon = (TextView)findViewById(R.id.honStat);
TextView Jag = (TextView)findViewById(R.id.jagStat);
TextView Audi = (TextView)findViewById(R.id.audiStat);
if(benz == false)
{
Benz.setText("Available");
}
else if(benz == true)
{
Benz.setText("Unavailable");
}
if(toyota == false)
{
Toy.setText("Available");
}
else if(toyota == true)
{
Toy.setText("Unavailable");
}
if(honda == false)
{
Hon.setText("Available");
}
else if(honda == true)
{
Hon.setText("Unavailable");
}
if(jaguar == false)
{
Jag.setText("Available");
}
else if(jaguar == true)
{
Jag.setText("Unavailable");
}
if(audi == false)
{
Audi.setText("Available");
}
else if(audi == true)
{
Audi.setText("Unavailable");
}
}
public void carSelect(View v) public void carSelect(View v)
{ {
EditText car = (EditText) findViewById(R.id.carChoice); EditText car = (EditText) findViewById(R.id.carChoice);
String carName = car.getText().toString(); String carName = car.getText().toString();
TextView Benz = (TextView)findViewById(R.id.benzStat);
TextView Toy = (TextView)findViewById(R.id.toyStat);
TextView Hon = (TextView)findViewById(R.id.honStat);
TextView Jag = (TextView)findViewById(R.id.jagStat);
TextView Audi = (TextView)findViewById(R.id.audiStat);
if(carName.toLowerCase().equals("audi")) if(carName.toLowerCase().equals("audi"))
{ {
audi = true; if (audi == false) {
test = "working"; audi = true;
choice = "audi"; test = "working";
valid = true;
choice = "audi";
Audi.setText("unavailable");
}
else if (audi == true)
{
valid = false;
}
} }
else if(carName.toLowerCase().equals("toyota")) else if(carName.toLowerCase().equals("toyota"))
{ {
test = "working"; if(toyota == false) {
toyota = true; test = "working";
choice = "toyota"; toyota = true;
valid = true;
choice = "toyota";
Toy.setText("unavailable");
}
else if (toyota == true)
{
valid = false;
}
} }
else if (carName.toLowerCase().equals("honda")) else if (carName.toLowerCase().equals("honda"))
{ {
test = "working"; if (honda == false) {
honda = true; test = "working";
choice = "honda"; honda = true;
valid = true;
choice = "honda";
Hon.setText("unavailable");
}
else if (honda == true)
{
valid = false;
}
} }
else if (carName.toLowerCase().equals("jaguar")) else if (carName.toLowerCase().equals("jaguar"))
{ {
test = "working"; if(jaguar == false) {
jaguar = true;
choice = "jaguar"; test = "working";
jaguar = true;
valid = true;
choice = "jaguar";
Jag.setText("unavailable");
}
else if (jaguar == true)
{
valid = false;
}
} }
else if (carName.toLowerCase().equals("benz")) else if (carName.toLowerCase().equals("benz"))
{ {
test = "working"; if(benz == false) {
jaguar = true; test = "working";
choice = "benz"; benz = true;
valid = true;
choice = "benz";
Benz.setText("Unavailable");
}
else if (benz == true)
{
valid = false;
}
}
if (valid == true) {
Toast.makeText(getApplicationContext(), test, Toast.LENGTH_LONG).show();
Intent order = new Intent(this, orderDetails.class);
startActivity(order);
}
else if (valid == false)
{
Toast.makeText(getApplicationContext(), "Please enter a valid car", Toast.LENGTH_LONG).show();
} }
Toast.makeText(getApplicationContext(), test, Toast.LENGTH_LONG).show();
Intent order = new Intent(this, orderDetails.class);
startActivity(order);
} }
......
...@@ -2,6 +2,7 @@ package com.example.assignment; ...@@ -2,6 +2,7 @@ package com.example.assignment;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
...@@ -129,6 +130,8 @@ if (!“”.equals(temp)){ ...@@ -129,6 +130,8 @@ if (!“”.equals(temp)){
Toast.makeText(getApplicationContext(), "Cost" + cost, Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), "Cost" + cost, Toast.LENGTH_LONG).show();
Intent list = new Intent(this, Carlist.class);
startActivity(list);
} }
......
package com.example.assignment;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class returnCar extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_return_car);
if(carPurchase.audi == false && carPurchase.benz == false && carPurchase.honda == false && carPurchase.jaguar == false && carPurchase.toyota == false)
{
Toast.makeText(getApplicationContext(), "There are no cars to be returned at this point.", Toast.LENGTH_LONG).show();
}
}
public void successReturn()
{
Toast.makeText(getApplicationContext(), "Thank you for returning the car. Sending you back to the car list", Toast.LENGTH_LONG).show();
Intent list = new Intent(this, Carlist.class);
startActivity(list);
}
public void retCar(View v)
{
EditText car = (EditText)findViewById(R.id.carName);
String returnCar = car.getText().toString();
//(carName.toLowerCase().equals("benz")
if (returnCar.toLowerCase().equals("benz"))
{
if(carPurchase.benz == false)
{
Toast.makeText(getApplicationContext(), "This car is currently not in use", Toast.LENGTH_LONG).show();
}
else if(carPurchase.benz == true)
{
carPurchase.benz = false;
successReturn();
}
}
else if(returnCar.toLowerCase().equals("audi"))
{
if(carPurchase.audi == false)
{
Toast.makeText(getApplicationContext(), "This car is currently not in use", Toast.LENGTH_LONG).show();
}
else if(carPurchase.audi == true)
{
carPurchase.audi = false;
successReturn();
}
}
else if(returnCar.toLowerCase().equals("honda"))
{
if(carPurchase.honda == false)
{
Toast.makeText(getApplicationContext(), "This car is currently not in use", Toast.LENGTH_LONG).show();
}
else if(carPurchase.honda == true)
{
carPurchase.honda = false;
successReturn();
}
}
else if(returnCar.toLowerCase().equals("jaguar"))
{
if(carPurchase.jaguar == false)
{
Toast.makeText(getApplicationContext(), "This car is currently not in use", Toast.LENGTH_LONG).show();
}
else if(carPurchase.jaguar == true)
{
carPurchase.jaguar = false;
successReturn();
}
}
else if(returnCar.toLowerCase().equals("toyota"))
{
if(carPurchase.toyota == false)
{
Toast.makeText(getApplicationContext(), "This car is currently not in use", Toast.LENGTH_LONG).show();
}
else if(carPurchase.toyota == true)
{
carPurchase.toyota = false;
successReturn();
}
}
else
{
Toast.makeText(getApplicationContext(),"This is not a valid car", Toast.LENGTH_LONG).show();
}
}
}
...@@ -309,4 +309,16 @@ air conditioning, ABS brakes, 2 people " ...@@ -309,4 +309,16 @@ air conditioning, ABS brakes, 2 people "
android:text="Purchase!" android:text="Purchase!"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView17" /> app:layout_constraintTop_toBottomOf="@+id/textView17" />
<Button
android:id="@+id/returnCar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="150dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="10dp"
android:onClick="carReturn"
android:text="Return Car"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".returnCar">
<TextView
android:id="@+id/textView38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="110dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="30dp"
android:text="Return Car"
android:textColor="#000"
android:textSize="40sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="175dp"
android:layout_marginLeft="175dp"
android:layout_marginTop="80dp"
android:text="Car Name:"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView38" />
<EditText
android:id="@+id/carName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="60dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView39" />
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="160dp"
android:layout_marginLeft="160dp"
android:layout_marginTop="145dp"
android:onClick="retCar"
android:text="Submit"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/carName" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment