// The "Summative" class.
// Melanie Deivendram
// 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 行,一个有类,一个在它下面。我在这里做的是一个菜单,这些是选项。我使用“准备编程”来创建程序。