Tugas Array dan Inheritance Kelompok 09


KELOMPOK 9 KELAS SI4003

IRENE IRAWATY (1202160043)

STEFI MUTIA SARI (1202160051)

KARINA TARIGAN (1202164188)

NO 1.

a. Soal No 11 Hlm 559

Suppose that we are selling boxes of candy for a fund-raiser. We have five kinds of candy to sell: Mints, Chocolates with Nuts, Chewy Chocolates, Dark Chocolate Creams, and Sugar-Free Suckers. We will record a customer’s order as an array of five integers, representing the number of boxes of each kind of candy. Write a static method combineOrder that takes two orders as its arguments and returns an array that represents the combined orders. For example, if order1 contains 0, 0, 3, 4, and 7, and order2 contains 0, 4, 0, 1, and 2, the method should return an array containing 0, 4, 3, 5, and 9.

b. Penjelasan Soal

Ada 5 macam jenis permen yang akan di jual, banyaknya pesanan dari pembeli akan dicatat dalam bentuk bilangan bulat array. Orderan ke 1 dan Orderan ke 2 nantinya akan di jumlah menjadi Total Orderan.

c. Script kode

package candy;

import java.util.Scanner;

/**

*

* @author Asus

*/

public class Candy {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner input= new Scanner (System.in);

int A[]=new int[5];

int B[]=new int[5];

int C[]=new int[5];

System.out.println( " Kode Orderan \n");

System.out.println(" 1. Mints \n ");

System.out.println(" 2. Chocolate \n ");

System.out.println(" 3. Chewy \n ");

System.out.println(" 4. Dark \n ");

System.out.println(" 5. Sugar \n ");

System.out.println("");

System.out.println( "Orderan Pertama" );

for(int i=0;i<5;i++){

System.out.print( " Silahkan Masukan Jumlah Orderan " +(i+1) + " : ");

A[i]=input.nextInt();

}

System.out.println("");

System.out.println("");

System.out.println( "Orderan Kedua" );

for(int k=0;k<5;k++){

System.out.print("Silahkan Masukan Jumlah Orderan " +(k+1) +" : ");

B[k]=input.nextInt();

}

System.out.println("");

System.out.println("");

System.out.print("Jumlah Orderan Pertama :");

for(int i=0;i<5;i++){

System.out.print( " "+(A[i])+ "\t");

}

System.out.println("");

System.out.print("Jumlah Orderan Kedua : " );

for(int k=0;k<5;k++){

System.out.print( " "+(B[k])+ "\t");

}

System.out.println("");

System.out.println("");

System.out.println("");

for(int x=0;x<5;x++){

C[x]=A[x]+B[x];

}

System.out.print("Jumlah Orderan Anda Adalah : \t");

for(int x=0;x<5;x++){

System.out.print( " " +(C[x])+ " \t ");

}

System.out.println("");

System.out.println("");

System.out.println("Silahkan Tunjukan Jumlah Orderan Anda!");

}

}

d. Outputnya


Leave a Reply