java - Computer Assistance Program -
the question states this: "the use of computers in education referred computer ¬assisted instruction (cai). write program elementary school student learn multiplication. use random object produce 2 positive 1-digit integers. program prompt user question, such “how 6 times 7?”
the student inputs answer. next, program checks student’s answer. if correct, display message “very good!” , ask multiple question. if answer wrong, display message “no. please try again.” , let student try same question repeatedly until student gets right. separate method used generate each new question. method called once when application begins execution , each time user answers question correctly."
here have far.
/* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package programmingassignment5.pkg35; /** * * @author jeremy */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public abstract class programmingassignment535 extends japplet implements actionlistener{ jtextfield question, input; jlabel prompt; int answer, guess; string questionstring; /** * @param args command line arguments */ public void init(){ // set guess flag value indicating no user input 17 guess = -999; // create text fields , label 20 question = new jtextfield( 20 ); question.seteditable( false ); prompt = new jlabel( "enter answer: " ); input = new jtextfield( 4 ); input.addactionlistener( ); // add components applet 29 container container = getcontentpane(); container.setlayout( new flowlayout() ); container.add( question ); container.add( prompt ); container.add( input ); // generate question 36 createquestion(); } public void paint( graphics g ){ super.paint( g ); // determine whether response correct 44 // if guess isn't flag value 45 if (guess != -999){ if (guess != answer) g.drawstring( "no. please try again.", 20, 70 ); else { g.drawstring( "very good!", 20, 70 ); createquestion(); } guess = -999; } } // verify entered response public void actionperformed( actionevent e ){ guess = integer.parseint( input.gettext() ); // clear text field input.settext( "" ); // display correct response repaint(); } // create new question , corresponding answer public void createquestion(){// 2 random numbers between 0 , 9 73 int digit1 = ( int ) ( math.random() * 10 ); int digit2 = ( int ) ( math.random() * 10 ); answer = digit1 * digit2; questionstring = "how " + digit1 + " times " + digit2 + " ?"; // add applet 81 question.settext( questionstring ); } } // end class
the error giving me program missing main class. easy fix cannot figure out how implement here without breaking suggestions?
it sounds need basic "hello world" kind of swing. have here.
there many issues code (why class abstract? why overriding paint?). swing tutorials. main method problem, try this:
public static void main( string[] args ) { swingutilities.invokelater( new runnable() { public void run() { programmingassignment535 myapplet = new programmingassignment535(); myapplet.init(); myapplet.setvisible( true ); } } ); }
you have make class not abstract.