Student Mohammed from USA
Assigned & Due: 10/7/15
1. (10 points) Java Inheritance.
You are to develop and test the following in Java: 1 interface, 4 abstract classes, 3 other classes and 4 objects. The interface is named cs398Live. The abstract classes are named cs398Thing(baseclass) and Rock, Plant, and Animal (derivedclasses),asparentandchildren,respectively. The Cat and Dog classes, in turn, are subclasses of Animal. You must provide a constructor for each of the classes.
cs398Thinghas2privateintattributes,idandweight;andpublicintmethod, getWeight, which has a single int parameter, id. The interface cs398Live has 1 int method, grow, which has a single int parameter, change. Rock, Plant, and Animal extendcs398Thing;PlantandAnimalimplement cs398Live.
ObjectsNinjaandFelixareinstantiationsoftheCatclass;FidoandRoverofthe Dog class. Develop a public static void main method in the LitterTest class that demonstrates the proper operation of your code. Each kitten and puppy is born with a weight = 1 (pound); in the ensuing 5-month simulation (e.g., loop): each month they grow at the following rates:
Ninja, 1; Felix, 2; Fido, 3; Rover, 4.
Develop the classes and interface as discussed, providing a means to display the simulated growth of your babies as they grow. Your submission must include the code you’ve developed and screen shots of the outputs generated to the user screen.
2. (10 points) Android App Demonstration: DC Cab Fare App
Create an app that estimates the cost for cab fare in Washington, DC. The app calculates the cost of the trip and requests a reservation for a smart car, sedan or minivan.
Your app should employ the following algorithms:
a) The app requests the distance in milesw for the cab ride and your preference for the requested cab type (above). Cab fare is $3.25 for the first 1/8 mile and is $0.27 for each additional 1/8 miles.
b) The app displays the name and logo of a choice of 3 local DC cab companies, the requested type of cab vehicle, the estimated cost of the fare and a recommended tip.
Conditions: use a theme, Spinner prompt, string array, and hint property. Display mileage in tenths of a mile (e.g., 12.3 miles).
Include code and emulator test screen shots in your .zip file submission
public abstract class Animal extends cs398Thing implements cs398Live{
public Animal(int w) {
super(w);
// TODO Auto-generated constructor stub
}
}
packagecom.dccabfar.dccabfar;
importandroid.annotation.SuppressLint;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.Menu;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemSelectedListener;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.LinearLayout;
importandroid.widget.Spinner;
importandroid.widget.TextView;
public class MainActivity extends Activity {
EditTextetDistence;
TextViewtvcabname,tvTip,tvestimatedcoast;
Spinner spCabType;
Button bookCab;
String cabName,mainmiles;
LinearLayoutlayerCabType,layerCoast,layerTip;
double fc = 0.125,FM,SM,t1,FP,SP,TP;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etDistence=(EditText) findViewById(R.id.etDistence);
spCabType=(Spinner) findViewById(R.id.spcabtype);
bookCab=(Button) findViewById(R.id.btnBookCab);
tvcabname=(TextView) findViewById(R.id.tvcabname);
tvTip=(TextView) findViewById(R.id.tvTip);
tvestimatedcoast=(TextView) findViewById(R.id.tvestimatedcoast);
layerCabType=(LinearLayout) findViewById(R.id.layerCabType);
layerCoast=(LinearLayout) findViewById(R.id.layerCoast);
layerTip=(LinearLayout) findViewById(R.id.layerTip);
bookCab.setOnClickListener(new OnClickListener() {
@SuppressLint(“NewApi”) public void onClick(View v) {
mainmiles=etDistence.getText().toString();
System.out.println(“main miles”+ mainmiles);
if(mainmiles.isEmpty())
{
etDistence.setError(“Enter Distance…!!!”);
}else
{
FM = (Double.parseDouble(mainmiles))/8;
System.out.println(“First miles”+ FM);
SM=(Double.parseDouble(mainmiles))-FM;
System.out.println(“Second Mile”+ SM);
FP=(FM)*3.25;
System.out.println(“FP”+ FP);
SP=SM*0.27;
System.out.println(“SP”+ SP);
TP=FP+SP;
String tp=String.valueOf(TP);
System.out.println(“TP”+ TP);
layerCabType.setVisibility(View.VISIBLE);
layerCoast.setVisibility(View.VISIBLE);
layerTip.setVisibility(View.VISIBLE);
etDistence.setText(“”);
tvcabname.setText(cabName);
tvestimatedcoast.setText(tp);
tvTip.setText(“Thanks For Booking”);
}
}
});
spCabType.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long arg3) {
cabName =spCabType.getItemAtPosition(position).toString();
System.out.println(“price ” + cabName);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
@Override
publicbooleanonCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}