1
import java.util.Scanner;
public class Counter {
private int count;
public Counter() {
count = 0;
}
public void setZero() {
count = 0;
}
public void increment() {
count++;
}
public void decrement() {
if (count > 0) {
count--;
}
}
public int countIs() {
return count;
}
public void printCounter() {
System.out.println("Count: " + count);
}
}
2
import java.util.Scanner;
public class Purchase {
private String name;
private int groupCount;
private double groupPrice;
private int numberBought;
public void setName(String newName) {
name = newName;
}
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 setNumberBought(int number) {
if (number <= 0) {
System.out.println("Error: Bad parameter in setNumberBought.");
System.exit(0);
} else
numberBought = number;
}
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, 3 for $2.99 is entered as");
System.out.println("3 2.99");
System.out.println("Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt();
groupPrice = keyboard.nextDouble();
while ((groupCount <= 0) || (groupPrice <= 0)) {
System.out.println("Both numbers must be positive. Try again.");
System.out.println("Enter price of item as two numbers.");
System.out.println("For example, 3 for $2.99 is entered as");
System.out.println("3 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 purchased:");
numberBought = keyboard.nextInt();
while (numberBought <= 0) {
System.out.println("Number must be positive. Try again.");
System.out.println("Enter number of items purchased:");
numberBought = keyboard.nextInt();
}
}
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;
}
}
3
import java.util.Scanner;
public class ConcertPromoter {
private String bandName;
private int venueCapacity;
private int ticketsSold;
private double phoneTicketPrice;
private double venueTicketPrice;
private double totalSales;
public ConcertPromoter() {
bandName = "";
venueCapacity = 0;
ticketsSold = 0;
phoneTicketPrice = 0.0;
venueTicketPrice = 0.0;
totalSales = 0.0;
}
public void initialize(String bandName, int venueCapacity, double phoneTicketPrice, double venueTicketPrice) {
this.bandName = bandName;
this.venueCapacity = venueCapacity;
this.phoneTicketPrice = phoneTicketPrice;
this.venueTicketPrice = venueTicketPrice;
}
public void doTicketSale(int numTickets) {
ticketsSold += numTickets;
totalSales += phoneTicketPrice * numTickets;
}
public void phoneSalesOver() {
phoneTicketPrice = venueTicketPrice;
}
public int getTicketsSold() {
return ticketsSold;
}
public int getTicketsLeft() {
return venueCapacity - ticketsSold;
}
public double getSalesReport() {
return totalSales;
}
public boolean phoneSalesOnly() {
return phoneTicketPrice == venueTicketPrice;
}
public static void main(String[] args) {
ConcertPromoter concert = new ConcertPromoter();
concert.initialize("The Ducks", 100, 10.00, 12.00);
System.out.println("Concert Promoter Sales Program started");
Scanner reader = new Scanner(System.in);
boolean done = false;
while (!done) {
if (concert.phoneSalesOnly())
System.out.println("Sell tickets (S), Change to venue sales (V), Finish selling (F)");
else
System.out.println("Sell tickets (S), Finish selling (F)");
String response = reader.next();
if (response.equals("F"))
done = true;
else if (response.equals("S")) {
System.out.print("Enter number of tickets to sell: ");
int numTickets = reader.nextInt();
concert.doTicketSale(numTickets);
} else if (response.equals("V"))
concert.phoneSalesOver();
else {
System.out.println("Sorry the response " + response + " was not valid.");
}
System.out.println("Tickets remaining: " + concert.getTicketsLeft());
}
System.out.println("Final report: " + concert.getSalesReport());
}
}
4
import java.util.Scanner;
public class GradesGraph {
private int numberOfAs;
private int numberOfBs;
private int numberOfCs;
private int numberOfDs;
private int numberOfFs;
public void set(int numberOfAs, int numberOfBs, int numberOfCs, int numberOfDs, int numberOfFs) {
this.numberOfAs = numberOfAs;
this.numberOfBs = numberOfBs;
this.numberOfCs = numberOfCs;
this.numberOfDs = numberOfDs;
this.numberOfFs = numberOfFs;
}
public void readInput() {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of A grades: ");
numberOfAs = input.nextInt();
System.out.print("Enter the number of B grades: ");
numberOfBs = input.nextInt();
System.out.print("Enter the number of C grades: ");
numberOfCs = input.nextInt();
System.out.print("Enter the number of D grades: ");
numberOfDs = input.nextInt();
System.out.print("Enter the number of F grades: ");
numberOfFs = input.nextInt();
}
public void setAcount(int count) {
numberOfAs = count;
}
public void setBcount(int count) {
numberOfBs = count;
}
public void setCcount(int count) {
numberOfCs = count;
}
public void setDcount(int count) {
numberOfDs = count;
}
public void setFcount(int count) {
numberOfFs = count;
}
public int getAcount() {
return numberOfAs;
}
public int getBcount() {
return numberOfBs;
}
public int getCcount() {
return numberOfCs;
}
public int getDcount() {
return numberOfDs;
}
public int getFcount() {
return numberOfFs;
}
public int getTotalNumberOfGrades() {
return numberOfAs + numberOfBs + numberOfCs + numberOfDs + numberOfFs;
}
public int getPercentA() {
return (int) (((double) numberOfAs / getTotalNumberOfGrades()) * 100);
}
public int getPercentB() {
return (int) (((double) numberOfBs / getTotalNumberOfGrades()) * 100);
}
public int getPercentC() {
return (int) (((double) numberOfCs / getTotalNumberOfGrades()) * 100);
}
public int getPercentD() {
return (int) (((double) numberOfDs / getTotalNumberOfGrades()) * 100);
}
public int getPercentF() {
return (int) (((double) numberOfFs / getTotalNumberOfGrades()) * 100);
}
public void drawGradeDistribution() {
int maxPercentage = 100;
int scale = 2;
int maxAster