Hey all! I'm a new member here and a new member to the programming community. I've managed to do a few simple programs, but I do have a problem with 2:
1. This is a program which is supposed to translate a letter grade into a numeric value. The assignment states that a "+" or a "+" will change the letter grade by 0.3 (i.e. B- is equivalent to a 2.7). The constraints are that an F+, F-, and A+ should yield the solid grade (i.e. an A+ should equal the same of an A. An F+/F- is the same value as an F (50). I don't know where to start. I have the base grade programmed, but adding or subtracting 0.3 confuses me.
CODE
import java.util.*;
class Grades
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
String grade="";
System.out.println("Enter your letter grade");
grade=in.nextLine();
String letter=grade.substring(0,1);
String symbol=grade.substring(1,2);
if (letter.equals("A"))
System.out.print("4.0");
else if (letter.equals("B"))
System.out.print("3.0");
else if (letter.equals("C"))
System.out.print("2.0");
else if (letter.equals("D"))
System.out.print("1.0");
else if (letter.equals("F"))
System.out.print("0.0");
if
else if (symbol.equals("+"))
System.out.print("le");
else if (symbol.equals("-"))
System.out.print("-0.3");
}
}
2. This program is for a game of Nim. It's a very simple program compared to those that are posted on the internet. I know that this is the correct code because my teacher approved, however, he wouldn't help me in identifying the errors. This is what my code looks like:
CODE
import java.util.*;
class Nim
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
Random generator = new Random();
int marbles = 10 + generator.nextInt(91), person = generator.nextInt(2);
mode = generator.nextInt(2);
System.out.println("size" + marbles);
while (marbles>0)
{
if (person == 1)
{
System.out.print("Pick");
marbles = marbles-pick;
System.out.println(marbles + "remaining");
}
else
{
int randPick = 0;
if (marbles==1)
randPick = 1;
else randPick = 1 + generator.nextInt(marbles/2);
if (mode==1)
{
marbles = marbles-randPick;
System.out.print(marbles + "remaining");
}
else {if (marbles==63 || marbles==31 || marbles==15 || marbles==7 || marbles==3)
marbles = marbles-randPick;
else if (marbles > 63)
pick = marbles - 63;
else if (marbles > 31)
pick = marbles - 31;
else if (marbles > 15)
pick = marbles - 15;
else if (marbles > 7)
pick = marbles - 7;
else if (marbles > 3)
pick = marbles - 3;
System.out.print(marbles + "remaining");
}
}
if (person==0)
person = 1;
else
person = 0;
if (person==1)
System.out.println("You win");
else System.out.println("You lose");
}
}
}
I get 8 errors, which state
CODE
C:\Documents and Settings\Admin\Desktop\Nim.java:9: cannot find symbol
symbol : variable mode
location: class Nim
mode = generator.nextInt(2);
^
C:\Documents and Settings\Admin\Desktop\Nim.java:16: cannot find symbol
symbol : variable pick
location: class Nim
marbles = marbles-pick;
^
C:\Documents and Settings\Admin\Desktop\Nim.java:25: cannot find symbol
symbol : variable mode
location: class Nim
if (mode==1)
^
C:\Documents and Settings\Admin\Desktop\Nim.java:34: cannot find symbol
symbol : variable pick
location: class Nim
pick = marbles - 63;
^
C:\Documents and Settings\Admin\Desktop\Nim.java:36: cannot find symbol
symbol : variable pick
location: class Nim
pick = marbles - 31;
^
C:\Documents and Settings\Admin\Desktop\Nim.java:38: cannot find symbol
symbol : variable pick
location: class Nim
pick = marbles - 15;
^
C:\Documents and Settings\Admin\Desktop\Nim.java:40: cannot find symbol
symbol : variable pick
location: class Nim
pick = marbles - 7;
^
C:\Documents and Settings\Admin\Desktop\Nim.java:42: cannot find symbol
symbol : variable pick
location: class Nim
pick = marbles - 3;
^
8 errors
Tool completed with exit code 1
but I don't know how to fix this.
I'm eagerly awaiting any help I can get!