|
New Coder.. Help with my code
I already have to programs that I have made. Very simple some of the first things i've ever written. Now I am trying to combine the two.
The first Code is.............
import java.util.Scanner;
public class FirstProject {
public static void main(String[] args) {
System.out.println("Hello out there.");
System.out.println("I will add two numbers for you.");
System.out.println("Enter two whole numbers on a line");
int n1, n2;
Scanner keyboard = new Scanner(System.in);
n1 = keyboard.nextInt();
n2 = keyboard.nextInt();
System.out.println("The sum of those two numbers is");
System.out.println(n1 + n2);
}
}
.................... I taught myself about simple input and output.
The second code.....................
import javax.swing.JApplet;
import java.awt.Graphics;
public class HappyFace extends JApplet
{
public void init() {
setSize(1000,1000);
}
public void paint (Graphics canvas)
{
// Draw outline
canvas.drawOval (100, 50, 200, 200);
// Draw eyes
canvas.fillOval (155, 100, 10, 20);
canvas.fillOval (230, 100, 10, 20);
// Draw mouth
canvas.drawArc (150, 160, 100, 50, 180, 180);
}
}
.................... is the first time I used a Java applet
Now Im trying to combine the two Programs to greet you with the promt. Then give your imput presents you with a choice of two applets. Im starting to get overwhelmed and I need help. I dont know how to write this thing.
So far I have.........
import javax.swing.JApplet;
import java.awt.Graphics;
import java.util.Scanner;
public class HappyWild extends JApplet {
public void init() {
setSize(500, 500);
}
public void paint(Graphics canvas) {
System.out.println("Are you feeling Happy or Wild?");
...............
I dont know how to read an answer that is a string not an interger.
String answer = keyboard.......
System.out.println(answer);
I dont understand about branching and I need help writing my code from here on. Thank You for your help guys
|