d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Does This Look Right? Don't Have A Compiler With > Me, Want Another Eye At It..
Add Reply New Topic New Poll
Member
Posts: 2,020
Joined: Apr 30 2011
Gold: 143.00
Sep 5 2012 07:05pm
Code

package package1;

import javax.swing.JOptionPane;

public class Class1
{
public static void main(String[] args)
{
 System.out.println("Exercise P1.1:");
 System.out.println("+------+");
 System.out.println("| Evan |");         // Name in Box
 System.out.println("+------+");
 System.out.println("");
 
 System.out.println("Exercise P1.2:");
 System.out.println("  ///// ");
 System.out.println(" | o o |");
 System.out.println("(|  ^  |)");         // :)
 System.out.println(" | [_] |");
 System.out.println("  ----- ");
 
 System.out.println("Exercise P1.3:");
 System.out.println("+---+---+---+");
 System.out.println("|   |   |   |");
 System.out.println("+---+---+---+");
 System.out.println("|   |   |   |");      // boxes
 System.out.println("+---+---+---+");
 System.out.println("|   |   |   |");  
 System.out.println("+---+---+---+");
 
 System.out.println("Exercise P1.4:");
 System.out.println("            +---+");
 System.out.println("            |   |");
 System.out.println("        +---+---+");
 System.out.println("        |   |   |");
 System.out.println("    +---+---+---+");
 System.out.println("    |   |   |   |");  // stairs
 System.out.println("+---+---+---+---+");
 System.out.println("|   |   |   |   |");
 System.out.println("+---+---+---+---+");

 System.out.println("Exercise P1.5:");
 System.out.println(1+2+3+4+5+6+7+8+9+10); // Sum of first positive 10 integers
 
 System.out.println("Exercise P1.6");
 System.out.println(1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10); // We'll explore these phenomenons in chapter 4
 System.out.println(1.0+2.0+3.0+4.0+5.0+6.0+7.0+8.0+9.0+10.0); // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
 // Comment either P1.7 off or P1.8, depending which one you want to use.
 System.out.println("Exercise P1.7");
 JOptionPane.showMessageDialog(null, "Hello World");
 System.exit(0);
 
 System.out.println("Exercise P1.8");
 String name = JOptionPane.showInputDialog("What is your name?");
 System.out.println("Hello, " + name);
 System.exit(0);
 
}
}



Code

package package1;
import javax.swing.JOptionPane;
public class Calculator
{
public static void main(String[] args)
{
 String numberOne = JOptionPane.showInputDialog("What is the first number you want to add?");
 String numberTwo = JOptionPane.showInputDialog("What is the second number you want to add?");
 int x = Integer.parseInt(numberOne);
 int y = Integer.parseInt(numberTwo);
 int answer = x + y;
 System.out.println(x + " + " + y + " = " + answer);
 JOptionPane.showMessageDialog(null, x + " + " + y + " = " + answer);
}
}

Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 5 2012 07:50pm
Considering that you have import statements, I doubt you just wrote that in notepad. So you prolly don't want us to look for compile time errors, but rather you want us to test the logic?

Class1 makes no sense at all. You're writing everything to sysout as though it's a console app, but then you use a swing dialog box, then you call System.exit then you put up another dialog box?

Get a compiler and do it right.

This post was edited by carteblanche on Sep 5 2012 07:55pm
Member
Posts: 2,020
Joined: Apr 30 2011
Gold: 143.00
Sep 5 2012 09:28pm
didn't have eclipse downloaded, had this homework assignment, so, from what i remember before wrote it down.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll