STRUKTUR PROGRAM JAVA: //Daftar paket yang digunakan dalam program import namapaket;

Similar documents
Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

AN IMPROTANT COLLECTION OF JAVA IO RELATED PROGRAMS

1 Looping Constructs (4 minutes, 2 points)

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

MIT AITI Swing Event Model Lecture 17

FIFO PAGE REPLACEMENT : import java.io.*; public class FIFO {

protected void printserial() { System.out.println("> NO." + this.serialno); this.serialno++; }

CMP 326 Midterm Fall 2015

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

JAC444 - Lecture 4. Segment 1 - Exception. Jordan Anastasiade Java Programming Language Course

Java for Interfaces and Networks (DT3010, HT10)

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

encompass a group of features for building Graphical User Interfaces (GUI).

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

SINGLE EVENT HANDLING

Assignment2013 Please use this document only for verifying if your programs are right. Do not blindly copy paste and waste your time.

Programmierpraktikum

Adding Buttons to StyleOptions.java

Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*;

H212 Introduction to Software Systems Honors

Case Study: Savings Account Interest

Recitation: Loop Jul 7, 2008

Introduction. Introduction

Introduction This assignment will ask that you write a simple graphical user interface (GUI).

CSPP : Introduction to Object-Oriented Programming

IT101. File Input and Output

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

Chapter 11: Exceptions Lab Exercises

Networking Code CSCI 201 Principles of Software Development

State Application Using MVC

Assignment #3 (Due 4/4/2017)

Byte and Character Streams. Reading and Writing Console input and output

A sample print out is: is is -11 key entered was: w

// autor igre Ivan Programerska sekcija package mine;

RAIK 183H Examination 2 Solution. November 11, 2013

public static void main(string[] args) throws IOException { sock = new Socket(args[0], Integer.parseInt(args[1]));

e) Implicit and Explicit Type Conversion Pg 328 j) Types of errors Pg 371

COMPSCI 230. Software Design and Construction. Swing

Darshan Institute of Engineering & Technology for Diploma Studies

The Java Series IO, Serialization and Persistence. The Java Series. IO, Serialization and Persistence Raul RAMOS / CERN-IT User Support Slide 1

1005ICT Object Oriented Programming Lecture Notes

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

4. Finding & Displaying Record of Salesman with minimum net income. 5. Finding & Displaying Record of Salesman with maximum net income.

Points Missed on Page page 1 of 8

Graphic User Interfaces. - GUI concepts - Swing - AWT

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

RAIK 183H Examination 2 Solution. November 10, 2014

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

CPSC 319. Week 2 Java Basics. Xiaoyang Liu & Sorting Algorithms

Recursive Problem Solving

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

import java.io.*; class OutputExample { public static void main(string[] args) { try{ PrintWriter pw = new PrintWriter

CMP-326 Exam 2 Spring 2018 Total 120 Points Version 1

Introduction to the JAVA UI classes Advanced HCI IAT351

CMPS12A Practice Final Fall 2017

CS Week 11. Jim Williams, PhD

CS180. Exam 1 Review

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

Java for Interfaces and Networks (DT3010, HT10)

Part I: Learn Common Graphics Components

Midterm assessment - MAKEUP Fall 2010

Any serious Java programmers should use the APIs to develop Java programs Best practices of using APIs

Java code(assembler) ******************************************************************* package A1;

User interfaces and Swing

Lecture 4: Exceptions. I/O

Recursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples

Final Examination Semester 2 / Year 2010

CMPS 12A Fall 2017 Final (A)

First Name: AITI 2004: Exam 2 July 19, 2004

Graphical User Interfaces

Programming Languages and Techniques (CIS120e)

Special Exercise Unit: Introduction to Java

Lesson 3: Accepting User Input and Using Different Methods for Output

CS 117 Fall Compound boolean expressions. Control Statements, Part 2. Using boolean operators. Boolean operators

DM503 Programming B. Peter Schneider-Kamp.

Java. GUI building with the AWT

URL Kullanımı Get URL

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

Project 1. LibraryTest.java. Yuji Shimojo CMSC 335

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Example: CharCheck. That s It??! What do you imagine happens after main() finishes?

CSC 1214: Object-Oriented Programming

6 COMPUTER PROGRAMMING

Programming Languages and Techniques (CIS120)

Chapter 13 Lab Advanced GUI Applications

AP CS Unit 11: Graphics and Events

ICSE Class 10 Computer Applications ( Java ) 2012 Solved Question...

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

First Name: AITI 2004: Exam 2 July 19, 2004

) / Java ( )

Packages: Putting Classes Together

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

CS 180 Final Exam Review 12/(11, 12)/08

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Transcription:

STRUKTUR PROGRAM JAVA: //Daftar paket yang digunakan dalam program import namapaket; //Membuat Kelas public class namakelas //Metode Utama public static void main(string[] args) perintah-perintah;... LATIHAN Listing pertama.java class pertama //perintah untuk mencetak System.out.println("Apa Kabar"); Listing variabel.java class variabel int a = 10; String b = "Java"; System.out.println(a); System.out.println(b); Listing kif.java class kif

int angka1 = 1; int angka2 = 2; if(angka1 > angka2) System.out.println("Angka1 lebih besar dari angka2"); else System.out.println("Angka2 lebih besar dari angka1"); Listing kswitch.java class kswitch int kode = 1; switch(kode) case 1: System.out.println("Bemo"); break; case 2: System.out.println("Becak"); break; default: System.out.println("Mlampah"); break; Listing pfor.java class pfor int i; for (i=1; i<5; i++) System.out.println(i);

Listing pdo.java class pdo int i = 0; do System.out.println(i); i++; while (i<5); Listing pwhile.java class pwhile int i = 0; while (i<5) System.out.println(i); i++; Listing larray.java class larray int i; String[] nama = new String[3]; int[] nilai = 90, 75; nama[0] = "Indah"; nama[1] = "Wijayanti"; for (i=0;i<=1;i++) System.out.println("Nama : " + nama[i]); System.out.println("Nilai : " + nilai[i]);

System.out.println(); Listing input1.java class input1 public static void main(string[] args) throws IOException String str; BufferedReader br; br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Masukkan Nama Anda : "); str= br.readline(); System.out.println("Hello "+ str); Listing input2.java class input2 public static void main(string[] args) throws IOException int angka1, angka2; BufferedReader br; br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Masukkan Angka1 : "); angka1 = Integer.parseInt(br.readLine()); System.out.print("Masukkan Angka2 : "); angka2 = Integer.parseInt(br.readLine()); System.out.println("Angka1 Anda : "+ angka1); System.out.println("Angka2 Anda : "+ angka2);

Listing readfile.java import java.util.*; class readfile public static void main (String [] args) throws IOException BufferedReader f = new BufferedReader(new FileReader("data.txt")); int a = Integer.parseInt(f.readLine()); int b = Integer.parseInt(f.readLine()); System.out.println(a); System.out.println(b); File data.txt 10 50 Listing writefile.java import java.util.*; class writefile public static void main (String [] args) throws IOException PrintWriter out; out = new PrintWriter(new BufferedWriter(new FileWriter("dataout.txt"))); int a = 10; int b = 20; out.write(a + "\n"); out.write(b + "\n"); out.close();

Listing pbomhsw.java class mhsw String nama; double nfor, nsum, nakh; void inputdata() throws IOException BufferedReader br; br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Input Data"); System.out.println("=========="); System.out.print("Nama : "); nama = br.readline(); System.out.print("N Form : "); nfor = Double.parseDouble(br.readLine()); System.out.print("N Sum : "); nsum = Double.parseDouble(br.readLine()); void proses() nakh = 0.5 * ( nfor + nsum ); void hasil() System.out.println("N Akhir : " + nakh); class pbomhsw throws IOException mhsw mymhsw = new mhsw(); mymhsw.inputdata(); mymhsw.proses(); mymhsw.hasil();

Listing swinglabel.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class swinglabel public static void main (String arg[]) JFrame frame = new JFrame ("Latihan Pembuatan Label"); frame.setsize(300,200); frame.setdefaultcloseoperation (JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel ("Hello World", JLabel.CENTER); label.setforeground(color.blue); label.setfont( new Font ("Arial",Font.PLAIN,20)); JButton button = new JButton ("Keluar"); button.addactionlistener(new ActionListener() public void actionperformed (ActionEvent e) System.exit(0); ); frame.getcontentpane().setlayout( new FlowLayout()); frame.getcontentpane().add(label); frame.getcontentpane().add(button); frame.setvisible(true); frame.pack();