Java Programming Final Test review

Ace your homework & exams now with Quizwiz!

Painting.java Chapter 3, page 174, #14A

class Painting { private String title; private String artist; private String medium; private double price; private double gallaryComission; private final static double RATE = 0.20; public String getTitle() { return title; } public void setTitle(String artTitle) { title = artTitle; } public String getArtist() { return artist; } public void setArtist (String painter) { artist = painter; } public String getMedium() { public void setMedium(String med) { medium = med; } public double getPrice() { return price; } public void setPrice(double num) { price = num; gallaryCommission = price * RATE; } public double getCommission() { return gallaryCommission; }

Dog Boarding Chapter 2, page 114, #9 The Happy Yappy Kennel boards dogs at a cost of 50 cents per pound per day. Write a class that accepts a dog's weight and number of days to be boarded and displays the total price for boarding

import java.util.Scanner; public class DogBoarding { public static void main(String [] args) { final double DAY_RATE = 0.50; int weight; int days; double total; Scanner input = new Scanner(System.in); System.out.print("Enter the dog's weight in pounds >>"); weight = input.nextInt(); System.out.print("Enter the number of days to board >>"); days = input.nextInt(); total = DAY_RATE * days * weight; System.out.print("The price to board a " + weight + "pound dog for" + days "days is $" + total); } }

GasPrices Chapter 3, Page 172, #5 When gasoline is 100$ per barrel.

import java.util.Scanner; public class GasPrices { public static void main (String args []) { int pricePerBarrel; Scanner input = new Scanner(System.in); System.out.print("Enter the current gas price per barrel >>"); PricePerBarrel = input.nextInt(); calculatePricePerGallom(pricePerBarrel); } public static void calculatePricePerGallon(int ppb) { final double LOW = 3.50; final double HIGH = 4; final double BASE = 100; double lowppg = ppb / BASE * LOW; double highPPG = ppb / BASE * HIGH; System.out.print("When gas is" + ppb + "per barrel, then it price will be from" + lowPPG + "to" + highPPG + "per gallon") } } } }

Percentages.java Chapter 3, page 172, #4

import java.util.Scanner; public class Percentages { public static void main (String args []) { double num1 = 2.0, num2 = 5.0; computePercent(num1, num2); computePercent(num1,num2); public static void computePercent(double x, double y) System.out.printIn( x + "is" + (x/y) * 100 + "% of" + }

TicketNumber.java Chapter 2, page 114, #12 Travel Tickets Company sells tickets for airlines,tours, and other travel related services. Write an application that indicates invalid ticket number entries

import javax.swing.JOptionPane; public class TicketNumber { public static void main(String [] args) { final int CHECKDIGIT = 7; String ticketString; int tickNum, newTickNum, lastDigit, remainder; boolean result; ticketString = JOptionPane.showInputDialog(null, "Enter 6-digit ticket number", "Ticket Number Dialog", JOptionPane.INFORMATION_MESSAGE); tickNum = Integer.parseInt(ticketString); lastDigit = tickNum % 10; newTickNum = tickNum / 10; remainder = newTickNum % CHECKDIGIT; result = (remainder == lastDigit); JOptionPane.showMessageDialog(null, "For ticket number" + tickNum + ", last digit is" + lastDigit + "and the remainder is" + remainder + ",\nso result is" + result); } }

ProjectedSales.java (Chapter two, page 113, 5A) Write a java class that represents next year's anticipated 10 percent increase in sales for each division of a company.

public class ProjectedSales { public static void main(String[] args) { final double INCREASE = 0.10; int northSales = 4000; int southSales = 5500; double northProjection; double southProjection; northProjection = northSales + northSales * INCREASE; southProjection = southSales + southSales * INCREASE; System.out.print("The projected sales figure for the North division is" + northProjection); System.out.print("The projected sales figure gor the South division is" + southProjection); } }

TestPainting.java Chapter 3, page 175, #14B

public class TestPainting { public static void main(String [] args) { Painting p1 = new Painting(); Painting p2 = new Painting(); Painting p3 = new Painting(); p1.setTitle("Starry Night"); p1.setArtist("Van Gogh"); p1.setMedium("oil"); p1.setPrice(2000000); p2.setTitle("My dog"); p2.setArtist("Billy Thompson"); p2.setMedium("crayon"); p2.setPrice(5); System.out.printIn("The" + p1.getMedium() + "painting named" + p1.getTitle() + "by" + p1.getArtist() + "sells for $" + p1.getPrice() + p1.getCommission() + "commission"); System.out.printIn("The" + p2.getMedium() + "painting named" + p2.getTitle() + "by" + p2.getArtist() + "sells for $" + p2.getPrice() + p2.getCommission() + "commission"); System.out.printIn("The" + p3.getMedium() + "painting named" + p3.getTitle() + "by" + p3.getArtist() + "sells for $" + p3.getPrice() + p3.getCommission() + "commission"); System.out.printIn("The gallery commission rate is" + }


Related study sets

Chapter 12 Quiz Hardware and Network Troubleshooting

View Set

The Relationship of the Sun,Moon and Earth

View Set

Biology Exam 4 practice questions

View Set

Perception, Attribution & Decision Making

View Set

2019-20 WRS Sample Questions (1-5)

View Set

Lección 4 | Lesson Test, Lesson 4 - Lesson Test, Leccion 4 | Lesson Test (Spanish)

View Set

Ch. 11 Nucleic Acid Structure, DNA Replication, and Chromosome Structure Study Questions and Answers

View Set

Ch 5: Cost-Volume-Profit Relationships

View Set

Ch. 14 - Accounts Payable and Other Liabilities

View Set