mrjoe
07-22-2008, 11:53 PM
Itrying to get these two program to work ,but i keep getting error do anyone know what they and how can i correct them.
import java.util.Scanner;
/**Create a class that represents a grade distribution
for a given course.
*/
public class GradeGraph
{
public int grade = A;
public int grade = B;
public int grade = C;
public int grade = D;
public int grade = F;
public void readInput()
{
//*Ask the user to enter values for how many A's, B's, C's, D's, and F's.//*
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the number of A's: ");
numA = keyboard.nextInt();
System.out.println("Please enter the number of B's: ");
numB = keyboard.nextInt();
System.out.println("Please enter the number of C's: ");
numC = keyboard.nextInt();
System.out.println("Please enter the number of D's: ");
numD = keyboard.nextInt();
System.out.println("Please enter the number of F's: ");
numF = keyboard.nextInt();
}
public void writeOutput()
{
//calculate the total, display and print the result./
numTotal = numA + numB + numC + numD + numF;
System.out.println("You have entered a total of " + numTotal + " grades.");
//calculate the percentages for each letter grade and display/print./
System.out.println(" Percent A's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent B's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent C's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent D's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent F's: " + Math.round(100*numA/numTotal) +"%");
//Print graph.
System.out.println("0 10 20 30 40 50 60 70 80 90 100%");
System.out.println("| | | | | | | | | | |");
System.out.println("******************************");
//Now calculate how many stars to print horizontaly.
for (int i = 0; i < Math.round(50 * numA / numTotal); i++)
{
v + = "*";
}
System.out.println(v + " A");
for (int i = 0; i < Math.round(50 * numB / numTotal); i++)
{
v + = "*";
}
System.out.println(v + " B");
for (int i = 0; i < Math.round(50 * numC / numTotal); i++)
{
v + = " * ";
}
System.out.println(v + " C");
for (int i = 0; i < Math.round(50 * numD / numTotal); i++)
{
v + = " * ";
}
System.out.println(v + " D");
for (int i = 0; i < Math.round(50 * numF / numTotal); i++)
{
v + = " * ";
}
System.out.println(v + " F");
2.
import java.util.Scanner;
/**
Class for the purchase of five kind of item, such as 10 oranges.
12 eggs, 3 apples, 6 bagels and watermelons.
Prices are set supermarket style, such as 10 for $2.99.
Eggs 12 for $1.69, apples 3 for $1.00, bagels 6 for $3.50 and watermelons for $4.39 each.
*/
public class PurchaseBill
{
private String name;
private int groupCount; //Part of a price, like 10 in 10 for $2.99.
private double groupPrice; //Part of a price, like the $2.99 in 10 for $1.99.
private int numberBought; //Number of items bought.
public void setName(String newName)
{
name = newName;
}
/**
Sets price to count pieces for $costForCount.
For examples,10 for $2.99.
*/
public void setPrice(int count, double costForCount)
{
if ((count <= 0) || (costForCount <= 0))
{
System.out.println("Error: Bad parameter in setPrice.");
System.exit(0);
}
else
{
groupCount = count;
groupPrice = costForCount;
}
}
public void setNumberBrought(int number)
{
if (number <= 0)
{
System.out.println("Error: Bad parameter in setNumberBought.");
System.exit(0);
}
else
numberBought = number;
}
/**
Read from keyboard the price and number of a purchase.
*/
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter name of item you are purchasing:");
name = keyboard.nextLine();
System.out.println("Enter price of item as two numbers.");
System.out.println("For example, 10 for $2.99 is entered as");
System.out.println("10 2.99");
System.out.println("Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
while ((groupCount <= 0) || (groupPrice <= 0))
{ //Try again:
System.out.println(
"Both numbers must be positive. Try again.");
System.out.println("Enter price of item as two numbers.");
System.out.println("10 2.99");
System.out.println(
"Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
}
System.out.println("Enter number of items purchhased:");
numberBought = keyboard.nextInt();
while (numberBought <= 0);
{ //Try again:
System.out.println("Number must be positive. Try again.");
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
}
}
/**
Displays price and number being purchased.
*/
public void writeOutput()
{
System.out.println(numberBought + " " + name);
System.out.println("at " + groupCount +
" for $" + groupPrice);
}
public String getName()
{
return name;
}
public double getTotalCost()
{
return (groupPrice / groupCount) * numberBought;
}
public double getUnitCost()
{
return groupPrice / groupCount;
}
public int getNumberBought()
{
return numberBought;
}
}
import java.util.Scanner;
/**Create a class that represents a grade distribution
for a given course.
*/
public class GradeGraph
{
public int grade = A;
public int grade = B;
public int grade = C;
public int grade = D;
public int grade = F;
public void readInput()
{
//*Ask the user to enter values for how many A's, B's, C's, D's, and F's.//*
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the number of A's: ");
numA = keyboard.nextInt();
System.out.println("Please enter the number of B's: ");
numB = keyboard.nextInt();
System.out.println("Please enter the number of C's: ");
numC = keyboard.nextInt();
System.out.println("Please enter the number of D's: ");
numD = keyboard.nextInt();
System.out.println("Please enter the number of F's: ");
numF = keyboard.nextInt();
}
public void writeOutput()
{
//calculate the total, display and print the result./
numTotal = numA + numB + numC + numD + numF;
System.out.println("You have entered a total of " + numTotal + " grades.");
//calculate the percentages for each letter grade and display/print./
System.out.println(" Percent A's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent B's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent C's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent D's: " + Math.round(100*numA/numTotal) +"%");
System.out.println(" Percent F's: " + Math.round(100*numA/numTotal) +"%");
//Print graph.
System.out.println("0 10 20 30 40 50 60 70 80 90 100%");
System.out.println("| | | | | | | | | | |");
System.out.println("******************************");
//Now calculate how many stars to print horizontaly.
for (int i = 0; i < Math.round(50 * numA / numTotal); i++)
{
v + = "*";
}
System.out.println(v + " A");
for (int i = 0; i < Math.round(50 * numB / numTotal); i++)
{
v + = "*";
}
System.out.println(v + " B");
for (int i = 0; i < Math.round(50 * numC / numTotal); i++)
{
v + = " * ";
}
System.out.println(v + " C");
for (int i = 0; i < Math.round(50 * numD / numTotal); i++)
{
v + = " * ";
}
System.out.println(v + " D");
for (int i = 0; i < Math.round(50 * numF / numTotal); i++)
{
v + = " * ";
}
System.out.println(v + " F");
2.
import java.util.Scanner;
/**
Class for the purchase of five kind of item, such as 10 oranges.
12 eggs, 3 apples, 6 bagels and watermelons.
Prices are set supermarket style, such as 10 for $2.99.
Eggs 12 for $1.69, apples 3 for $1.00, bagels 6 for $3.50 and watermelons for $4.39 each.
*/
public class PurchaseBill
{
private String name;
private int groupCount; //Part of a price, like 10 in 10 for $2.99.
private double groupPrice; //Part of a price, like the $2.99 in 10 for $1.99.
private int numberBought; //Number of items bought.
public void setName(String newName)
{
name = newName;
}
/**
Sets price to count pieces for $costForCount.
For examples,10 for $2.99.
*/
public void setPrice(int count, double costForCount)
{
if ((count <= 0) || (costForCount <= 0))
{
System.out.println("Error: Bad parameter in setPrice.");
System.exit(0);
}
else
{
groupCount = count;
groupPrice = costForCount;
}
}
public void setNumberBrought(int number)
{
if (number <= 0)
{
System.out.println("Error: Bad parameter in setNumberBought.");
System.exit(0);
}
else
numberBought = number;
}
/**
Read from keyboard the price and number of a purchase.
*/
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter name of item you are purchasing:");
name = keyboard.nextLine();
System.out.println("Enter price of item as two numbers.");
System.out.println("For example, 10 for $2.99 is entered as");
System.out.println("10 2.99");
System.out.println("Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
while ((groupCount <= 0) || (groupPrice <= 0))
{ //Try again:
System.out.println(
"Both numbers must be positive. Try again.");
System.out.println("Enter price of item as two numbers.");
System.out.println("10 2.99");
System.out.println(
"Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
}
System.out.println("Enter number of items purchhased:");
numberBought = keyboard.nextInt();
while (numberBought <= 0);
{ //Try again:
System.out.println("Number must be positive. Try again.");
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
}
}
/**
Displays price and number being purchased.
*/
public void writeOutput()
{
System.out.println(numberBought + " " + name);
System.out.println("at " + groupCount +
" for $" + groupPrice);
}
public String getName()
{
return name;
}
public double getTotalCost()
{
return (groupPrice / groupCount) * numberBought;
}
public double getUnitCost()
{
return groupPrice / groupCount;
}
public int getNumberBought()
{
return numberBought;
}
}