Skip to content
Permalink
Browse files
week 3 done
  • Loading branch information
Jianhua Yang committed Oct 18, 2017
1 parent e262153 commit 1487899a10fa2733af6747936cbf226acc3adc8c
Show file tree
Hide file tree
Showing 230 changed files with 359 additions and 2,623 deletions.
File renamed without changes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.

Some generated files are not rendered by default. Learn more.

File renamed without changes.
File renamed without changes.
@@ -4,7 +4,7 @@ android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.jianhuayang.mycar"
applicationId 'com.example.jianhuayang.myxml'
minSdkVersion 15
targetSdkVersion 26
versionCode 1
@@ -17,10 +17,12 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
@@ -1,20 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jianhuayang.myxml">
package="com.example.jianhuayang.myxml">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity android:name="com.example.jianhuayang.myxml.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
@@ -1,20 +1,20 @@
package com.example.jianhuayang.myxml;

/**
* Created by jianhuayang on 09/10/2016.
* Created by jianhuayang on 10/10/2017.
*/

class Car extends Vehicle {
private String color;
class Car extends Vehicle{

private String color;
public Car(String make, int year, String color, int price, double engine){
super(make, year, price, engine);
this.color = color;
setMessage(getMessage() + " I like your shining " + color + " color.");
}
}

class Diesel extends Vehicle implements Vehicle.Controllable {
class Diesel extends Vehicle implements Vehicle.Controllable{

private String type;

@@ -33,4 +33,4 @@ class Diesel extends Vehicle implements Vehicle.Controllable {
control();
return super.getMessage();
}
}
}
@@ -1,7 +1,7 @@
package com.example.jianhuayang.myxml;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
@@ -15,25 +15,26 @@ import android.widget.Toast;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MyXmlActivity";
private static Double depreciation;
private EditText editTextMake;
private EditText editTextYear;
private EditText editTextColor;
private EditText editTextPrice;
private EditText editTextEngine;
private TextView textViewBlock;
private Vehicle vehicle;
// the diamond syntax: because the empty angle brackets have the shape of a diamond, "core java for the impatient" C. Horstmann
private ArrayList<Vehicle> vehicleList = new ArrayList<>();
// the diamond syntax: because the empty angle brackets have the shape of a diamond, "core java for the impatient" C. Horstmann
private StringBuilder outputs;
private static Double depreciation;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(myToolbar);

editTextMake = (EditText) findViewById(R.id.inputMake);
editTextYear = (EditText) findViewById(R.id.inputYear);
@@ -45,35 +46,7 @@ public class MainActivity extends AppCompatActivity {
depreciation = getResources().getInteger(R.integer.depreciation) / 100.00;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

switch (id) {
case R.id.menu_add:
addVehicle();
return true;
case R.id.menu_clear:
return clearVehicleList();
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}

public void onButtonClick(View view) {

String make = editTextMake.getText().toString();
String strYear = editTextYear.getText().toString();
int intYear = Integer.parseInt(strYear);
@@ -107,6 +80,30 @@ public class MainActivity extends AppCompatActivity {
Log.d(TAG, "User message is \"" + vehicle + "\".");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();

switch (id) {
case R.id.menu_add:
addVehicle();
return true;
case R.id.menu_clear:
return clearVehicleList();
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}

private void addVehicle() {
vehicleList.add(vehicle);
resetOutputs();
@@ -140,6 +137,6 @@ public class MainActivity extends AppCompatActivity {
}

private double depreciateEngine(double engine) {
return (double) Math.round(engine * depreciation * 100) / 100;
return (double) Math.round(engine * depreciation * 100) / 100 ;
}
}
@@ -1,27 +1,40 @@
package com.example.jianhuayang.myxml;

/**
* Created by jianhuayang on 08/10/2016.
* Created by jianhuayang on 09/10/2017.
*/

public class Vehicle {

public static int counter = 0;
private String make;
private int year;
private String message;
private int price;
private double engine;

public int getPrice() {
return price;
}

public double getEngine() {
return engine;
}

// the default constructor
public Vehicle() {
this.make = "Volvo";
this.year = 2012;
this.message = "This is the default message.";
}

public String getMake() {
return make;
}

/*
* This constructor takes four parameters
* */
* This constructor takes four parameters.
*/
public Vehicle(String make, int year, int price, double engine) {
this.make = make;
this.year = year;
@@ -32,9 +45,7 @@ public class Vehicle {
}

/**
* The constructor that takes only the make of the car
*
* @param make the make of the car
* @param make the make of your car
*/
public Vehicle(String make) {
this();
@@ -43,30 +54,6 @@ public class Vehicle {
count();
}

public String getMake() {
return make;
}

public void setMake(String make) {
this.make = make;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public double getEngine() {
return engine;
}

public void setEngine(double engine) {
this.engine = engine;
}

public String getMessage() {
return message;
}
@@ -88,3 +75,5 @@ public class Vehicle {
void control();
}
}


0 comments on commit 1487899

Please sign in to comment.