SPIRAL NUMBER
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Agintageniusa
*/
public class Spiral {
public static void main(String[] args) {
String input;
input = JOptionPane.showInputDialog("Input");
int n;
try {
n = Integer.parseInt(input);
if (n<3||n>10){
JOptionPane.showMessageDialog(null, "Input only from 3 to 10", "WARNING", JOptionPane.WARNING_MESSAGE);
return;
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, " ----Cannot Presume---- ", "ERROR", JOptionPane.ERROR_MESSAGE);
return;
}
int i = 1, border = n, x = border -1, y = 0;
int cubicon [][] = new int [n][n];
while(i<=n*n){
//kiri-kanan
for(int j = 0; j < border; j++){
System.out.println("Line 1 " + x + " " + y + " " + i);
cubicon [x][y++] = i++;
}
//bawah-atas
x--;
y--;
for(int j = 0; j < border - 1; j++){
System.out.println("Line 2 " + x + " " + y + " " + i);
cubicon [x--][y] = i++;
}
//kanan-kiri
x++;
y--;
for(int j = 0; j < border - 1; j++){
System.out.println("Line 3 " + x + " " + y + " " + i);
cubicon [x][y--] = i++;
}
//atas-bawah
x++;
y++;
for(int j = 0; j < border - 2; j++){
System.out.println("Line 4 " + x + " " + y + " " + i);
cubicon [x++][y] = i++;
}
y++;
x--;
border = border - 2;
}
System.out.println("Output : ");
for(i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if (cubicon[i][j]<10){
System.out.print(" " + cubicon[i][j] + " ");
}
else {
System.out.print(cubicon[i][j] + " ");
}
}
System.out.println("");
}
}
}
------------------------------------------------------------------------------------------------------------
NUMERO CONVERTER
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* konversi.java
*/
/**
*
*/
public class konversi extends javax.swing.JFrame {
private static Object varString;
public static String conversion(int x) throws Exception {
if (x == 0) {
return "Zero";
}
if (x == 1) {
return "One";
}
if (x == 2) {
return "Two";
}
if (x == 3) {
return "Three";
}
if (x == 4) {
return "Four";
}
if (x == 5) {
return "Five";
}
if (x == 6) {
return "Six";
}
if (x == 7) {
return "Seven";
}
if (x == 8) {
return "Eight";
}
if (x == 9) {
return "Nine";
}
if (x == 10) {
return "Ten";
}
if (x == 11) {
return "Eleven";
}
if (x == 12) {
return "Twelve";
}
if (x == 13) {
return "Thirteen";
}
if (x == 15) {
return "fifteen";
}
if (x == 18) {
return "Eighteen";
}
if (x == 20) {
return "Twenty";
}
if (x == 30) {
return "Thirty";
}
if (x < 20) {
return conversion(x - 10) + "teen";
}
if (x > 20 && x < 30) {
return " Twenty " + conversion(x % 10);
}
if (x > 30 && x < 40) {
return " Thirty " + conversion(x % 10);
}
if (x > 50 && x < 60) {
return " Fifty " + conversion(x % 10);
}
if (x > 80 && x < 90) {
return " Eighty " + conversion(x % 10);
}
if (x < 100) {
if (x % 10 > 0) {
return conversion(x / 10) + "ty " + conversion(x % 10);
} else {
return conversion(x / 10) + "ty";
}
}
if (x == 100) {
return "One Hundred";
}
if (x < 200) {
return "One Hundred " + conversion(x - 100);
}
if (x < 1000) {
if (x % 100 > 0) {
return conversion(x / 100) + " Hundred " + conversion(x % 100);
} else {
return conversion(x / 100) + " Hundred";
}
}
throw new Exception();
}
/** Creates new form konversi */
public konversi() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
Input = new javax.swing.JTextField();
Output = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Number to Word");
setBackground(java.awt.Color.orange);
Input.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
InputActionPerformed(evt);
}
});
Output.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
Output.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OutputActionPerformed(evt);
}
});
jButton1.setText("Convert");
jButton1.setToolTipText("Convert Number To Text");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 11)); // NOI18N
jLabel1.setForeground(new java.awt.Color(0, 0, 204));
jLabel1.setText("INPUT NUMBER");
jLabel1.setToolTipText("Input");
jLabel2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 12)); // NOI18N
jLabel2.setText("OUTPUT to WORD");
jLabel2.setToolTipText("Output");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Output, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Input, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(319, Short.MAX_VALUE)
.addComponent(jButton1)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(77, 77, 77)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Input, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(Output, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(43, 43, 43)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void InputActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int x;
try {
x = Integer.parseInt(this.Input.getText());
if (x < 0 || x > 999) {
JOptionPane.showMessageDialog(null, "Input only from 0 to 999", "WARNING", JOptionPane.WARNING_MESSAGE);
return;
}
this.Output.setText(konversi.conversion(x));
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "warning error", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
private void OutputActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new konversi().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Input;
private javax.swing.JTextField Output;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}
************ NO'ONE PERFECT - IF ONE CONFESS AS PERFECTO & rules like little god *** HE/SHE will DIE in FLAW-
No comments:
Post a Comment