// The "Summative" class.
// Jane Smith
// Jan.16,2012
// Purpose: To create a program as part of the summative
import java.awt.*;
import hsa.Console;
public class Summative
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
// Title Page
c.setColor (Color.orange);
c.fillRect (0, 0, 2000, 900);
c.drawRect (0, 0, 2000, 900);
c.setColor (Color.white);
Font times = new Font ("Times", Font.BOLD, 50);
c.setFont(times);
c.drawString ("Summative", 180, 50);
Font tahoma = new Font ("Tahoma", Font.BOLD, 20);
c.setFont(tahoma);
c.getChar ();
c.clear ();
int choice;
{
c.drawString ("\t\t 1.Count Vowels", 0, 250);
c.drawString ("\t\t 2.One Dimensional Array Task", 0, 300);
c.drawString ("\t\t 3.Graphical animation", 0, 350);
c.drawString ("\t\t 4.String Methods", 0, 400);
c.drawString ("\t\t 5.ICS3U Program Portfolio ", 0, 450);
c.drawString ("\t\t 6.Exit", 0, 490);
}
do
{
c.print ("What is your choice (1-6): ");
choice = c.readInt ();
if ((choice < 1) || (choice > 6))
c.println ("Invalid ... enter 1-6 only");
}
while ((choice < 1) || (choice > 6));
switch (choice)
{
}
}
if (choice==1)
{
c.println ("What word would you like to enter?");
String word = c.readString ();
int count1 = 0;
for (int num = 0 ; num < word.length () ; num++)
{
char numbers = word.charAt (num);
if (numbers == '0' || numbers == '1' || numbers == '2' || numbers == '3' || numbers == '4' || numbers == '5' || numbers == '6' || numbers == '7' || numbers == '8' || numbers == '9')
{
count1++;
}
}
if (count1 != 0)
{
c.println("That is invalid, please try again");
}
if (count1 == 0)
{
int count = 0;
for (int num = 0 ; num < word.length () ; num++)
{
char vow = word.charAt (num);
if (vow == 'a' || vow == 'e' || vow == 'i' || vow == 'o' || vow == 'u' || vow == 'A' || vow == 'E' || vow == 'I' || vow == 'O' || vow == 'U')
{
count++;
}
}
c.println (" There are " + count + " vowels");
if (count == 0)
{
c.println("There are no vowels in the word");
}
}
这是我的考试项目,当我运行程序时似乎存在语法错误。错误发生在第 8 行和第 9 行,即类所在行和类下方行。我在这里做的是一个菜单,这些就是选项。我使用“准备编程”来创建程序。
你失踪了
{
:
public class Summative {
static Console c;
编辑
正如 @ccheneson 所提到的,您的类定义的结束
}
似乎也丢失了。
你应该看看你的代码缩进,一开始似乎很好,但后来就失败了。通过适当的缩进,您可以轻松发现这些错误,因为几乎所有缩进块都必须用
{
和 }
括起来。