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 java_11_09;

import java.util.Scanner;

public class Java_11_09 {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

String itemI[] = new String[5];

int orderA[] = new int[5];

int orderB[]=new int[5];

int orderTot[] = new int[5];

itemI[0]=”Mints”;

itemI[1]=”Chocolate_With_Nuts”;

itemI[2]=”Chewy_Chocolates”;

itemI[3]=”Dark_Chocolate_Creams”;

itemI[4]=”Sugar_Free_Suckers”;

System.out.println(“Order 1 = 2\t 1\t 3\t 4\t 1\t”);

System.out.println(“Order 2 = 1\t 4\t 6\t 1\t 5\t”);

orderA[0] = 2;

orderA[1] = 1;

orderA[2] = 3;

orderA[3] = 4;

orderA[4] = 1;

orderB[0] = 1;

orderB[1] = 4;

orderB[2] = 6;

orderB[3] = 1;

orderB[4] = 5;

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

orderTot[i] = orderA[i] + orderB[i];

}

System.out.print(“Total = “);

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

System.out.print(orderTot[i] + “\t “);

}

System.out.println(“”);

}

}

d. Outputnya


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *