Codehs 9.4 & 9.5
Codehs 9.4 & 9.5
4 CodeHS
@Override
public String toString(){
return getWidth() + " x " + getHeight() + " Square";
}
}
System.out.println(sq);
System.out.println("Area: " + sq.area());
System.out.println("Perimeter: " + sq.perimeter());
sq.setSideLength(7.0);
System.out.println("\nAfter resizing:");
System.out.println(sq);
System.out.println("Area: " + sq.area());
System.out.println("Perimeter: " + sq.perimeter());
}
}
public class Rectangle {
@Override
public void deposit(double amount){
double bonus = amount * 0.10;
super.deposit(amount + bonus);
}
@Override
public void withdraw(double amount){
super.withdraw(amount + 1.50);
}
@Override
public String toString(){
return String.format("Student account current balance $%.1f", getBalance());
}
}
h1.setHourlySalary(20.0);
System.out.println("Updated hourly: " + h1.getHourlySalary());
System.out.println(h1);
}
}
/**
* Example output:
* Mike makes $18.0 per hour
*/
public String toString(){
return getName() + " makes $" + getHourlySalary() + " per hour";
}
}
/**
* Example output:
* Mr. Karel makes $75000.0 per year
*/
public String toString(){
return name + " makes $" + salary + " per year";
}
}
import java.util.Scanner;
scanner.close();
}
}
9.5 CodeHS
import java.util.ArrayList;
pies.add(new ApplePie(6));
@Override
public void eatSlice()
{
if (this.hasSlice())
{
super.eatSlice();
}
}
}
import java.util.Scanner;
import java.util.*;
while (true) {
System.out.print("Please enter a company name, enter 'exit' to quit: ");
String name = input.nextLine();
if (name.equalsIgnoreCase("exit")) {
break;
}
if (online.equalsIgnoreCase("yes")) {
System.out.print("Please enter the website address: ");
String website = input.nextLine();
companies.add(new OnlineCompany(name, website));
} else {
System.out.print("Please enter the street address: ");
String street = input.nextLine();
System.out.print("Please enter the city: ");
String city = input.nextLine();
System.out.print("Please enter the state: ");
String state = input.nextLine();
companies.add(new Company(name, street, city, state));
}
}
System.out.println();
for (Company c : companies) {
System.out.println(c + "\n");
}
}
}
@Override
public String address(){
return webAddress;
}
@Override
public String toString(){
return super.getName() + "\nWebsite: " + address();
}
}
import java.util.*;
while (true) {
System.out.print("Enter the assignment's name (exit to quit): ");
String name = input.nextLine();
if (name.equalsIgnoreCase("exit")) {
break;
}
System.out.print("Enter the due date: ");
String dueDate = input.nextLine();
if (type.equalsIgnoreCase("T")) {
System.out.print("What type of test is it? ");
String testType = input.nextLine();
assignments.add(new Test(name, dueDate, availablePoints, earnedPoints, testType));
} else if (type.equalsIgnoreCase("P")) {
System.out.println("Does this project require (true/false) ... ");
System.out.print("Groups? ");
boolean groups = input.nextBoolean();
System.out.print("A presentation? ");
boolean presentation = input.nextBoolean();
input.nextLine();
printSummary(assignments);
}
public Test(String name, String dueDate, double availablePoints, double earnedPoints, String
testType) {
super(name, dueDate, availablePoints, earnedPoints);
this.testType = testType;
}