Commit 05ac3b73 authored by christopher.foster's avatar christopher.foster

Works out cost including discount, refreshment and number of hours

parent 6567de36
...@@ -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=".carPurchase"></activity> <activity android:name=".orderDetails"></activity>
<activity android:name=".carPurchase" />
<activity android:name=".Carlist" /> <activity android:name=".Carlist" />
<activity android:name=".login" /> <activity android:name=".login" />
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
......
...@@ -2,13 +2,71 @@ package com.example.assignment; ...@@ -2,13 +2,71 @@ 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.widget.EditText;
import android.widget.Toast;
public class carPurchase extends AppCompatActivity { public class carPurchase extends AppCompatActivity {
private boolean benz = false;
private boolean toyota = false;
private boolean honda = false;
private boolean jaguar = false;
private boolean audi = false;
private String test = "not working";
public static String choice = "";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
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);
} }
public void carSelect(View v)
{
EditText car = (EditText) findViewById(R.id.carChoice);
String carName = car.getText().toString();
if(carName.toLowerCase().equals("audi"))
{
audi = true;
test = "working";
choice = "audi";
}
else if(carName.toLowerCase().equals("toyota"))
{
test = "working";
toyota = true;
choice = "toyota";
}
else if (carName.toLowerCase().equals("honda"))
{
test = "working";
honda = true;
choice = "honda";
}
else if (carName.toLowerCase().equals("jaguar"))
{
test = "working";
jaguar = true;
choice = "jaguar";
}
else if (carName.toLowerCase().equals("benz"))
{
test = "working";
jaguar = true;
choice = "benz";
}
Toast.makeText(getApplicationContext(), test, Toast.LENGTH_LONG).show();
Intent order = new Intent(this, orderDetails.class);
startActivity(order);
}
} }
package com.example.assignment;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Random;
public class orderDetails extends AppCompatActivity {
public double refreshment = 0;
public String refresh = "";
private boolean disc = false;
public int discount = 0;
private int hours = 0;
private int refreshNo = 0;
public double total = 0;
public String cost = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_details);
}
public void cake (View v)
{
refreshment = 1;
refresh = "cake";
}
public void biscuit (View v)
{
refreshment = 1.2;
refresh = "biscuit";
}
public void sandwich (View v)
{
refreshment = 2;
refresh = "sandwich";
}
public void sweet (View v)
{
refreshment = 0.5;
refresh = "sweet";
}
public void choc (View v)
{
refreshment = 0.5;
refresh = "chocolate";
}
public void water (View v)
{
refreshment = 0.5;
refresh = "water";
}
public void juice (View v)
{
refreshment = 1;
refresh = "juice";
}
public void discount (View v)
{
disc = true;
}
public void calculateCost (View v)
{
//EditText car = (EditText) findViewById(R.id.carChoice);
/*
EditText editText=findViewById(R.id.editText);
String temp=editText.getText().toString();
int value=0;
if (!“”.equals(temp)){
value=Integer.parseInt(temp);
}
*/
EditText hour = (EditText) findViewById(R.id.hours);
String temp = hour.getText().toString();
if(!"".equals(temp))
{
hours = Integer.parseInt(temp);
}
EditText ref = (EditText) findViewById(R.id.refreshNo);
String tempRef = ref.getText().toString();
if(!"".equals(tempRef))
{
refreshNo = Integer.parseInt(tempRef);
}
if(disc == true)
{
Random rand = new Random();
discount = rand.nextInt(51);
}
else{
discount = 0;
}
switch (carPurchase.choice)
{
case "audi":
total = (8 * hours);
break;
case "benz":
total = (11 * hours);
break;
case "toyota":
total = (7 * hours);
break;
case "honda":
total = (9 * hours);
break;
case "jaguar":
total = (10 * hours);
break;
}
total = total + (refreshment * refreshNo);
total = total -((total / 100)*discount);
cost = Double.toString(total);
Toast.makeText(getApplicationContext(), "Cost" + cost, Toast.LENGTH_LONG).show();
}
}
...@@ -183,6 +183,7 @@ ...@@ -183,6 +183,7 @@
android:layout_marginTop="14dp" android:layout_marginTop="14dp"
android:layout_marginEnd="174dp" android:layout_marginEnd="174dp"
android:layout_marginRight="174dp" android:layout_marginRight="174dp"
android:onClick="carSelect"
android:text="Select" android:text="Select"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/carChoice" /> app:layout_constraintTop_toBottomOf="@+id/carChoice" />
......
<?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=".orderDetails">
<TextView
android:id="@+id/textView32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginLeft="120dp"
android:layout_marginTop="19dp"
android:text="Order Details"
android:textColor="#000"
android:textSize="30sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="150dp"
android:layout_marginLeft="150dp"
android:layout_marginTop="20dp"
android:text="Refreshments"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView32" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="147dp"
android:layout_height="224dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="220dp"
android:layout_marginRight="220dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView33">
<RadioButton
android:id="@+id/cake"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:text="Cake £1"
android:onClick="cake"/>
<RadioButton
android:id="@+id/biscuit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Biscuit £1.20"
android:onClick="biscuit"/>
<RadioButton
android:id="@+id/sandwich"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sandwich £2"
android:onClick="sandwich"/>
<RadioButton
android:id="@+id/sweet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sweet £0.50"
android:onClick="sweet"/>
<RadioButton
android:id="@+id/chocolate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chocolate £0.50"
android:onClick="choc"/>
<RadioButton
android:id="@+id/water"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Water £0.50"
android:onClick="water"/>
<RadioButton
android:id="@+id/juice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Juice £1"
android:onClick="juice"/>
</RadioGroup>
<EditText
android:id="@+id/refreshNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginEnd="3dp"
android:layout_marginRight="3dp"
android:ems="10"
android:inputType="number"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView34" />
<TextView
android:id="@+id/textView34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:layout_marginEnd="86dp"
android:layout_marginRight="86dp"
android:text="Number:"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView32" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="45dp"
android:layout_marginLeft="45dp"
android:layout_marginTop="15dp"
android:text="@android:string/yes"
android:onClick="discount"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView35" />
<TextView
android:id="@+id/textView35"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="45dp"
android:layout_marginLeft="45dp"
android:layout_marginTop="25dp"
android:text="Discount Raffle?"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />
<TextView
android:id="@+id/textView36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="44dp"
android:layout_marginLeft="44dp"
android:layout_marginTop="34dp"
android:text="Number of Hours car is needed:"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
<EditText
android:id="@+id/hours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="37dp"
android:layout_marginLeft="37dp"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView36" />
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:layout_marginEnd="175dp"
android:layout_marginRight="175dp"
android:onClick="calculateCost"
android:text="Next"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/hours" />
</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