You are on page 1of 7

ACT1

package com.example.marah.supexe1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class act1 extends AppCompatActivity implements


View.OnClickListener{

EditText tt1,tt2,tt3,tt4,tt5;
TextView ll1;
Button bb1,bb2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_act1);

tt1=(EditText)findViewById (R.id.t1);
tt2=(EditText)findViewById (R.id.t2);
tt3=(EditText)findViewById (R.id.t3);
tt4=(EditText)findViewById (R.id.t4);
tt5=(EditText)findViewById (R.id.t5);
ll1=(TextView)findViewById (R.id.l1);
bb1=(Button)findViewById (R.id.b1);
bb1.setOnClickListener (this);
bb2=(Button)findViewById (R.id.b2);
bb2.setOnClickListener (this);

public void onClick(View x)


{
switch(x.getId ()) {

case R.id.b1:
float aloc = 0;
float cal = 0;
int mat = 0;
String no = null;
float sb = 0;
float pr = 0;
int nbre = 0;

try {
mat = Integer.parseInt (tt1.getText ().toString ());
} catch (Exception e) {
Toast.makeText (this, "err:taper un nbre entier mat",
Toast.LENGTH_LONG).show ();

tt1.requestFocus ();
}
try {
no = tt2.getText ().toString ();
} catch (Exception e) {
Toast.makeText (this, "err:taper une c.c",
Toast.LENGTH_LONG).show ();

tt2.requestFocus ();
}

try {
nbre = Integer.parseInt (tt3.getText ().toString ());
} catch (Exception e) {
Toast.makeText (this, "err:taper un nbre entier
enfant", Toast.LENGTH_LONG).show ();

tt3.requestFocus ();
}

try {
sb = Float.valueOf (tt4.getText ().toString ());
} catch (Exception e) {
Toast.makeText (this, "err:taper un nbre reel sb",
Toast.LENGTH_LONG).show ();

tt4.requestFocus ();
}

try {
pr = Float.valueOf (tt5.getText ().toString ());
} catch (Exception e) {
Toast.makeText (this, "err:taper un nbre reel prime",
Toast.LENGTH_LONG).show ();

tt5.requestFocus ();
}

if (nbre > 4) {
nbre = 3;
}

cal = (sb + pr) + (nbre * 150);

ll1.setText ("le net est :" + cal);


break;
case R.id.b2:

Intent i = new Intent (this,act2.class);


startActivity (i);
break;

}
}
}
Act2

package com.example.marah.supexe1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class act2 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_act2);
}
}

xml act1

<?xml version="1.0" encoding="utf-8"?>


<android.support.constraint.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="com.example.marah.supexe1.act1">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Matricule" />
<EditText
android:id="@+id/t1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Nom" />

<EditText
android:id="@+id/t2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="N.enfant" />

<EditText
android:id="@+id/t3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/S.base"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Matricule" />

<EditText
android:id="@+id/t4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Prime" />

<EditText
android:id="@+id/t5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/l1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Net" />

<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="suivante" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>

xml de act2

<?xml version="1.0" encoding="utf-8"?>


<android.support.constraint.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="com.example.marah.supexe1.act2">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/pic4"
app:srcCompat="@android:color/background_light" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="precedente" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>

You might also like