0% found this document useful (0 votes)
147 views16 pages

Theresa Septiana Eka Putri - PBO - Practice1

The document is a report on a practice programming assignment in object-oriented programming. It provides details on modules completed, including getting started with Eclipse, object and driver classes, data types and operators, and strings. It includes vocabulary terms and examples of code assignments, such as writing a program to convert gallons to liters and creating student and person object classes with driver classes. Diagrams of sample code and outputs are provided.
Copyright
© © All Rights Reserved
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)
147 views16 pages

Theresa Septiana Eka Putri - PBO - Practice1

The document is a report on a practice programming assignment in object-oriented programming. It provides details on modules completed, including getting started with Eclipse, object and driver classes, data types and operators, and strings. It includes vocabulary terms and examples of code assignments, such as writing a program to convert gallons to liters and creating student and person object classes with driver classes. Diagrams of sample code and outputs are provided.
Copyright
© © All Rights Reserved
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/ 16

LAPORAN HASIL PRACTICE

PEMROGRAMAN BERBASIS OBJEK

NAMA : THERESA SEPTIANA EKA PUTRI


NIM : 213010503017
KELAS : A
MODUL : 4.1–4.4 (GETTING STARTED WITH ECLIPSE,
OBJECT AND DRIVER CLASSES, DATA TYPES AND
OPERATORS, AND STRINGS)

JURUSAN TEKNIK INFORMATIKA


FAKULTAS TEKNIK
UNIVERSITAS PALANGKA RAYA
KALIMANTAN TENGAH
2022
4.1 : Getting Started With Eclipse
Vocabulary :

Camel Case A naming convention to eliminate spaces in a name,


but to ease readability with
capitalization.
Switch Workspace To change the different physical location onto
which you will store and save your files.
Java Package Stored inside a project, a mechanism for organizing
Java classes into namespaces, or
containers.
Java Main Method The method inside a class that runs when the class
is compiled and ran.
Java Class A construct that is used as a blueprint to create
objects. Also a construct in which objects
are created.
Open Perspective An option to choose a combination of views and
editors.
Eclipse Edit and View Areas Areas within the Eclipse IDE that provide a way to
navigate a hierarchy of information and
allow modifications to elements.

Try It/Solve It :
1. Create a presentation to highlight five or more Views that may be of interest to a
programmer using Eclipse. Use the help system to learn about the Views available
in Eclipse. Work in teams of two to create and deliver the presentation. The
presentation should include the following :
a. A presentation introduction defining the presentation purpose and the learn
members.
b. A list of five or more Views in Eclipse that will be highlighted.
c. The reason your team selected the five Views to demonstrate.
d. The process your team went through to choose the five Views.
e. The actual demonstration and description of the components.
f. The presentation summary.

2. The pseudo code for converting gallons to liters was described in the lesson. Write
the code for the program. The program will convert a specific number of gallons to
liters and then display the output.

Gambar 1.1 Kode Program Konverter Galon

3. Modify the code written in step 2 to prompt a user for the number of gallons to
compute.

Gambar 1.2 Kode Program Konverter Galon Setelah Diubah


4. Describe three ways you can test the program thas converts gallons to liters.

Gambar 1.3 Output Program Konverter Galon Dengan Inputan Angka Negatif

Gambar 1.4 Output Program Konverter Galon Dengan Inputan Angka Besar

Gambar 1.5 Output Program Konverter Galon Dengan Inputan Angka Desimal

Gambar 1.6 Output Program Konverter Galon Dengan Inputan Huruf


4.2 Object And Driver Classes
Vocabulary :
Packages A group of related Java classes.
Code Block Sections of code that are enclosed inside a set of curly
braces. {}
Upper Camel Case First letter uppercase and the first letter of each internal word
capitalized. Example:
SavingsAccount
Constant A named value that does not change.
Lower Camel Case First letter lowercase and the first letter of each internal word
capitalized. Example:
studentFirstName
Driver Class A class that contains a main method.
Import Statement A code statement in a Java class file that includes java code
from another package or
class.
Programmer- A class that defines instances of objects to be used in another
created Object Class class.
Java Comments Code that is preceded by //. Comments are used to clarify
programming logic.
Comments are ignored by the compiler.
Java Keywords A word that has a special function in the Java language, and
cannot be used as names for
classes, methods, or variables.
Java API The library of Java classes available to import into a
programmer-created class.
Object Class The outline of an object, including class variables,
constructors, and methods.
Constructor A special kind of method that is a template for an object.
Parameters Values that are sent into a method or constructor to be used
in a calculation or substituted
with values from the class.
Variables Values, such as numbers, characters, or booleans. References
to objects, such as a
BankAccount object.
Access Modifiers Keywords used to specify the accessibility of a class (or
type) and its members. Ex:
public, private, protected, default
Methods A block of code inside a class that is used to change or
access information about the
class.

Try It/Solve It :
1. Name the components that comprise a java file. List the components in the order
that you would expect to see them in a Java program.
-Package
-Import
-Class
-Variable (atau field)
-Constuctor
-Method

2. Describe the difference between upper camel case and lower camel case and
provide an example of when you would them.
Perbedaan antara upper camel case dan lower camel case adalah upper camel
case digunakan untuk nama kelas dan dimulai dengan huruf besar,
sedangkan lower camel case digunakan untuk nama variabel dan dimulai
dengan huruf kecil.

3. What syntax is used to import the entire Java utilities package? And if you import
an entire package do you also need to import additional classes in the same
package separately?
Syntax :
Import java.util.*;
Tidak, karena tidak perlu mengimport kelas tambahan dari package yang
sama.

4. Write the syntax for a simple Java object class named Student with the following
format :
Student Name: Lisa Palombo
Student ID: 123456789
Student Status: Active

The student information will be stored in the following variables :


fName, lName, stuId, stuStatus.

import java.lang;
public class student {
public String fName;
public String lName;
public int stuID;
public student() {
}
public getName() {
return fName;
}

{
5. Write the code for a Driver Class that will create a Student Object and print the
information about the object to the screen.
public class studentTester
public static void main(String[] args) {
student s1 = new student();

System.out.printIn(“Student Name : “fName+” “+lName);
System.out.printIn(“Student ID : “+stuID);
System.out.printIn(“Student Status : “+stuStatus);
}
}

6. From this lesson, list 10 Java keywords.


-Package : Kelompok kelas pada Java yang saling terkait.
-Import : Pernyataan kode dalam kelas Java yang menyertakan kode Java
dari paket atau kelas lain.
-Public : Kode akses yang bersifat umum untuk data maupun method agar
dapat diakses oleh semua bagian didalam program.
-Class : Sebuah konstruksi yang digunakan sebagai cetak biru untuk
membuat objek juga sebuah konstruksi dimana objek diciptakan.
-Int : Tipe data primitif yang dapat menyimpan nilai integer.
-Void : Method yang tidak memiliki nilai kembali/return.
-Main : Metode didalam kelas yang berjalan saat kelas dikompilasi dan
dijalankan.
-Return : Mengembalikan nilai yang tersimpan didalam variabel luas.
-Static : Perintah khusus yang memungkinkan sebuah property atau
method diakses langsung tanpa melalui objek, cukup menulis
nama class saja.
-If, Else, dan For
7. Completed the programmer-created object class below. Read the comments for
instructions.

Gambar 2.1 Kode Program Person

8. Use the following driver class to test your results from above.

Gambar 2.2 Kode Program Managing People

Gambar 2.3 Output Program


Gambar 2.4 Ouput Program

Gambar 2.5 Output Program


4.3 Data Types And Operators
Vocabulary :
Variables Named primitive or object storage mechanisms defined in a
program. The assigned value may or may not (constants)
change.
Arithmetic Operators Symbols are used to do addition, subtraction,
multiplication, division, and modular arithmetic in math
expressions and formulas.
Primitives Data Types The group of Java data types that do not use the keyword
new when declared or initialized. Primitive Data Types
store the value in the same place in memory as the variable
name.
Byte The smallest java primitive type (1 byte) that can hold an
integer value.
Long This data type (8 bytes) is the largest integer type.
Conventions The formatting and naming standards that most
programmers follow.
Int This Java primitive data type (4 bytes) can hold integer
values
Double This Java primitive data type (8 bytes) is the largest
primitive that can hold a decimal value.
Initialization When a variable is assigned a value for the first time.
Float This Java primitive data type (4 bytes) can be initialized
with a decimal number preceding letter f. Example: float x
= 3.5f;
Literal Can be any number, text, or other information that
represents a value; used to initialize a primitive type.
Declaration A Java statement when a variable is defined but not
necessarily assigned a value. Example: int x;
Order Of Operations This word describes the mathematical precedence that a
variable has in a Java program.
Char A java primitive data type (2 bytes) that can hold single
character values. Example: “a”, “#”, or “X”
Scope Used to describe the block of code where a variable exists
in a program. A block of code is denoted by {}.
Type Casting The process of explicitly modifying one data type to
become a different data type.
Truncation A concept where a number is always rounded down to the
nearest integer.
Assigment Operator The equals sign “=” used in a Java statement to assign a
value to a variable.
Type Conversion The process of modifying one data type to become a
different data type, this may be implicit or explicit.
Short A Java primitive data type (2 bytes) that holds integer
numbers within a shorter range than an int.
Boolean A one-bit java primitive type that can hold the value true or
false.

Try It/Solve It :
1. Write a program that will take in the base and height of a triangle and calculate and
display the area of the triangle using the formula below.
System.out.printIn(“Enter the base : “); 𝐴𝐴 = ½ 𝑏ℎ
int b = in.nextInt();
System.out.printIn(“Enter the height : “);
int h = in.nextInt();
Area = (b*h)/2;
System.out.printIn(area);
2. Write the following math formulas in Java. You will need to use methods from the
Math class as well as nesting of methods and parantheses to force the order of
operations to correclu calculate the answer. Assume that all the variables in the
formulas have already been declared and initialized.
a. aa = √xx5−6/4 (√x^5 – 6)/4
b. 𝑏𝑏 = 𝑥𝑥𝑦𝑦 – 6xx x * x^(y*y) – 6^(x*x)
c. 𝑐𝑐 = 4cos (/5) – 𝑧𝑧 ccssssxx2
d. 𝑑𝑑 x^4 - √(6x-y^3) x^4 - √(6x-y^3)
e. ee = 1/1 yy - / xx-2yy
f. 𝑓𝑓 7(cos√5 - sin√3x – 4)) 7*(cos√(5-sin√(3*x-4)))

3. A bus holds 45 people. The school will only use a bus if they can fill it completely.
The rest of the people will ride in vans. Write a program that will take in the
number of people that are signed up to go on a field trip. Have the program print
the number of busses necessary and then total number of people that will need to
ride in vans.
System.out.printIn(“Masukkan Nomor Siswa : “);
int siswa = in.nextInt();
bus = siswa %45;
System.out.printIn(bus);

4. Write true or false on the blanks in the program below to show the value of the
boolean variable true_false as the program executes.
int i=5;
int j=6;
boolean true_false;
true_false=(j<5); false
true_false=(j>3); true
true_false=(j<i); false
true_false=(i<5); false
true_false=(j<=5); false
true_false=(6<6); false
true_false=(i!=j); true
true_false=(i==j || i<50); true
true_false=(i==j && i<50); false
true_false=(i>j || true_false && j>=4); true
true_false=(!(i<2 && j==5)); true
true_false=!true_false false

5. Explain why each of the declarations in the second list are wrong.
boolean gameOver = false; nt 2beOrNot2be; 1. Menggunakan angka
int students=50,classes=3; float price index; 2. Menggunakan spasi
double sales_tax; double lastYear'sPrice;3. Menggunakan simbol

6. Explain why each of the declarations in the second list do not follow conventions
for variable names.
int cadence=3, speed=55, int c=3,s=55,g=4; final

gear=4; double salesTax=.06;

final double SALES_TAX=.06; double

double gearRatio=.5; gearratio=.05,Gear=4; int

int currentGear=5; current_gear;


4.4 Strings
Vocabulary :
Concatenation Joining multiple String objects together.
Escape Sequences Specific characters that are preceded by a \ character. When
evaluated, the special character is evaluated as a special
function, such as tabs, newlines, etc
Instantiate Assigning a value to a String object reference.
Object Reference A data type that references the location in memory where an
object is stored rather than a single, specific value.
String Methods Code available in the Java API to manipulate or return strings.
String Object An Object type that stores sentences, words, or multiple
characters.

Try It/Solve It :
1. Write three different ways to declare and instantiate a String object called
“myString” and containing “abc”.
1). String myString = “abc”;
2). String myString = new String(‘abc”);

2. Given the three String objects below, what will each of the following return?
String s1 = “ABC”;
String s2 = new String (“DEF”);
String s3 = “AB” + “C”;
a. s1.compareTo(s2); -4
b. s2.equals(s3); false
c. s3 == s1; true
d. s2.compareTo(s3); 0
e. s3.equals(s1); true
3. Declare and instantiate two separate String objects, and then concatenate them
together and assign them to a third arbitrary String object.
String s1 = “Hi”;
String s2 = “Goodbye”;
String s3 = s1 + s2;

You might also like