0% found this document useful (0 votes)
16 views

Problem As Parcial

The document contains three programming problems involving arrays. Problem 1 sorts an array around a pivot point. Problem 2 calculates payroll for four employees based on hours worked. Problem 3 merges two sorted arrays into a single sorted array.

Uploaded by

pipiropo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Problem As Parcial

The document contains three programming problems involving arrays. Problem 1 sorts an array around a pivot point. Problem 2 calculates payroll for four employees based on hours worked. Problem 3 merges two sorted arrays into a single sorted array.

Uploaded by

pipiropo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PROGRAMACION

DIGITAL

TRABAJO
EXAMEN
PARCIAL

ALUMNOS:
Rocha Mamani Antony Steve

20120097F

Toma Jiga Eduardo Akira

20120067J

Vasquez Cairo Freddy Romario

20122032I

Villanueva Oscanoa Yvan

20111084B

2013

PROBLEMA 1
1 package problema1;
2 public class Problema1
3 {
4
int A[]={84,12,53,67,13,56,23,78,34,82,3};
5
int n=A.length,piv=53;
6
public static void main(String[] args)
7
{
8
Problema1 obj=new Problema1();
9
obj.imprimir1();
10
obj.ordenar();
11
obj.imprimir2();
12
}
13
void imprimir1()
14
{
15
System.out.print("El arreglo A es:");
16
for(int i=0;i<n;i++)
17
{
18
System.out.print(" "+A[i]);
19
}
20
System.out.println();
21
}
22
23
void ordenar()
24
{
25
int i=0,j=n-1;
26
while(i<j)
27
{
28
while(A[i]<piv)
29
{
30
i++;
31
}
32
while(A[j]>piv)
33
{
34
j--;
35
}
36
int aux=A[i];
37
A[i]=A[j];
38
A[j]=aux;
39
}
40
}
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

void imprimir2()
{
System.out.print("El nuevo arreglo A es:");
for(int i=0;i<n;i++)
{
System.out.print(" "+A[i]);
}
System.out.println();
System.out.println("El Pivot escogido es: "+piv);
}
}
run:
El arreglo A es: 84 12 53 67 13 56 23 78 34 82 3
El nuevo arreglo A es: 3 12 34 23 13 53 56 78 67 82 84
El Pivot escogido es: 53
BUILD SUCCESSFUL (total time: 0 seconds)

PROBLEMA 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

package problema2;
import java.util.Scanner;
public class Problema2
{
int horas[]= new int[4];
String nom[]= new String[4];
double bruto[]=new double[4];
double neto[]=new double[4];
int i;
void leer()
{
for(i=0;i<4;i++)
{
Scanner leer=new Scanner(System.in);
System.out.println("Ingrese el nombre del trabajador "+(i+1)+": ");
nom[i]=leer.next();
}
for(i=0;i<4;i++)
{
System.out.println("Ingrese las horas de trabajo del trabajador "+nom[i]+":

21 ");
22
Scanner leer=new Scanner(System.in);
23
horas[i]=leer.nextInt();
24
}
25
}
26
27
void calculo()
28
{
29
for(i=0;i<4;i++)
30
{
31
if(horas[i]>=140)
32
{
33
bruto[i]=140*20+(horas[i]-140)*1.5*20;
34
if(bruto[i]<=2000)
35
{
36
neto[i]=bruto[i]*0.9;
37
}
38
else
39
{
40
neto[i]=bruto[i]*0.85 +2000*0.005;

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

}
}
else
{
bruto[i]=horas[i]*20;
if(bruto[i]<=2000)
{
neto[i]=bruto[i]*0.9;
}
else
{
neto[i]=bruto[i]*0.85 +2000*0.005;
}
}
}
}
void imprimir()
{
for(i=0;i<4;i++)
{
if(horas[i]>=140)
{
System.out.println("El sueldo neto del trabajador "+nom[i]+" es: "+neto[i]);
System.out.println("El impuesto del trabajador "+nom[i]+" es: "+(bruto[i]neto[i]));
}
else
{
System.out.println("El sueldo neto del trabajador "+nom[i]+" es: "+neto[i]);
System.out.println("El impuesto del trabajador "+nom[i]+" es: "+(bruto[i]neto[i]));
}
}
}
public static void main(String[] args)
{
Problema2 ob=new Problema2();
ob.leer();
ob.calculo();
ob.imprimir();
}

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

}
run:
Ingrese el nombre del trabajador 1:
Jose
Ingrese el nombre del trabajador 2:
Yvan
Ingrese el nombre del trabajador 3:
Freddy
Ingrese el nombre del trabajador 4:
Steve
Ingrese las horas de trabajo del trabajador Jose:
200
Ingrese las horas de trabajo del trabajador Yvan:
180
Ingrese las horas de trabajo del trabajador Freddy:
410
Ingrese las horas de trabajo del trabajador Steve:
310
El sueldo neto del trabajador Jose es: 3920.0
El impuesto del trabajador Jose es: 680.0
El sueldo neto del trabajador Yvan es: 3410.0
El impuesto del trabajador Yvan es: 590.0
El sueldo neto del trabajador Freddy es: 9275.0
El impuesto del trabajador Freddy es: 1625.0
El sueldo neto del trabajador Steve es: 6725.0
El impuesto del trabajador Steve es: 1175.0
BUILD SUCCESSFUL (total time: 28 seconds)

PROBLEMA 3
1 package problema3;
2 public class Problema3
3 {
4
int A[]={2,4,6,8,12,20};
5
int B[]={3,5,9,11,15};
6
int m=A.length,n=B.length;
7
int C[]=new int[m+n];
8
public static void main(String[] args)
9
{
10
Problema3 obj=new Problema3();
11
obj.ordenar();
12
obj.imprimir();
13
}
14
void ordenar()
15
{
16
int i=0,j=0,k=0;
17
while(i<m && j<n)
18
{
19
if(A[i]<B[j])
20
{
21
C[k]=A[i];
22
i++;k++;
23
}
24
else
25
{
26
C[k]=B[j];
27
k++;j++;
28
}
29
}
30
31
if(m>n)
32
{
33
while(i<m)
34
{
35
C[k]=A[i];
36
i++;k++;
37
}
38
}
39
else
40
{
41
while(j<n)

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

{
C[k]=B[j];
j++;k++;
}
}
}
void imprimir()
{
System.out.println("El arreglo A es");
for(int q=0;q<m;q++)
{
System.out.print(A[q]+" ");
}
System.out.println();
System.out.println("El arreglo B es");
for(int q=0;q<n;q++)
{
System.out.print(B[q]+" ");
}
System.out.println();
System.out.println("El arreglo C es");
for(int q=0;q<m+n;q++)
{
System.out.print(C[q]+" ");
}
System.out.println();
}
}
run:
El arreglo A es
2 4 6 8 12 20
El arreglo B es
3 5 9 11 15
El arreglo C es
2 3 4 5 6 8 9 11 12 15 20
BUILD SUCCESSFUL (total time: 0 seconds)

You might also like