Unionville Hs AP COMP SCI 11 Chapter 4 Programming Projects
1 view 0 purchase
Course
AP COMPSCI 11
Institution
1
Counter
public class project1 {
int count;
public project1 (){
count = 0;
}
public void click() {
count++;
}p
ublic int getpublic1()
{
return count;
}p
ublic int reset()
{
count = 0;
return count;
}
} C
ountertest
public class project1part2 {
public static void main(String[] ar...
counter public class project1 int count public project1 count 0 public void click count p ublic int getpublic1 return count p ublic int reset count 0 return count
Written for
Secondary school
AP COMPSCI 11
2
All documents for this subject (1)
Seller
Follow
Examhack
Reviews received
Content preview
Counter
public class project1 {
int count;
public project1 (){
count = 0;
}
public void click() {
count++;
}
public int getpublic1()
{
return count;
}
public int reset()
{
count = 0;
return count;
}
}
Countertest
public class project1part2 {
public static void main(String[] args) {
project1 classcount1 = new project1();
project1 classcount2 = new project1();
classcount1.click();
classcount1.click();
classcount2.click();
int sum = classcount1.getpublic1() + classcount2.getpublic1();
, System.out.println("The count after click is " + sum);
classcount1.reset();
classcount2.reset();
sum = classcount1.getpublic1() + classcount2.getpublic1();
System.out.println("The count after the reset is " + sum);
}
}
bulb
public class Bulb {
String light;
public Bulb() {
light = "off";
}
public String TurnOn()
{
light = new String("on");
return light;
}
public String TurnOff()
{
light = new String("off");
return light;
}
}
, Lights
public class BulbPart2 {
public static void main(String [] args) {
Bulb bulb1 = new Bulb();
Bulb bulb2 = new Bulb();
String bulb3 = bulb1.TurnOff();
String bulb4 = bulb2.TurnOff();
System.out.println("Bulb one is "+bulb3);
System.out.println("Bulb two is "+bulb4);
bulb3 = bulb1.TurnOn();
bulb4 = bulb2.TurnOff();
System.out.println("Bulb one is "+bulb3);
System.out.println("Bulb two is "+bulb4);
bulb4 = bulb2.TurnOn();
System.out.println("Bulb one is "+bulb3);
System.out.println("Bulb two is "+bulb4);
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Examhack. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $11.99. You're not tied to anything after your purchase.