The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Form error
scorks
post Feb 2 2015, 10:25 PM
Post #1





Group: Members
Posts: 7
Joined: 16-January 15
Member No.: 22,040



Hi everyone,

I'm working on forms, and I'm having trouble with my counter program. I'm getting the error:

CODE

compile:
    [javac] Compiling 1 source file to /Users/Desktop/3715-A2/exer7/classes
    [javac] /Users/Desktop/3715-A2/exer7/src/exer7.java:31: error: '.class' expected
    [javac]                     int i = c.read();
    [javac]                         ^
    [javac] 1 error



In correlation with:

CODE

import static spark.Spark.get;
import static spark.Spark.post;
import static spark.Spark.port;
import java.io.IOException;
import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;


public class exer7 {    

    private static String FORM_PAGE =
        "<html>\n" +
        "<body>\n" +
        "<form action='/counter' method='POST'>\n" +
        "<label><input type='text' name='countNum'></label>\n" +
        "<input type='submit' name='count' value='Increase'>\n" +
        "<input type='submit' name='count' value='Decrease'>\n" +
        "</form>\n" +
                "The current count is: %d" +
        "</body>\n" +
                "</html>";

    

        public static void main(String[] args) {
          
     FileIntCount c = new FileIntCount();

        get("/counter", (request, response) ->
                    int i = c.read();
                    return String.format(FORM_PAGE, i );

        post("/counter", (request, response) -> {
            
           int amt = Integer.parseInt(request.queryParams("countNum"));
       String count = request.queryParams("count");
          

       Scanner sc = new Scanner(new File("count.txt"));
       int p = sc.nextInt();
       sc.close();
      
      

       if (count.equals("Increase")) {
               c.write(p+amt);
           }
           else if (count.equals("Decrease")) {
               c.write(p-amt);
       }
          else {
              //An error has occurred. Please try again.
          }    

      return String.format(FORM_PAGE, i);    

        });

    }

        
    public class FileIntCount {

    public FileIntCount() { }
    
    public int read() {
    Scanner sc = new Scanner(new File("count.txt"));
        int c = sc.nextInt();
        sc.close(); }

    public void write(int num) {
    PrintWriter pw = new PrintWriter("count.txt");
        pw.println(num);
        pw.close(); }
    
    }

    
}


Can anybody see why I'm getting this error?

Thank you!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 03:07 PM