Assignment2
This commit is contained in:
parent
cb2460ee46
commit
95ebce05ed
Binary file not shown.
@ -53,4 +53,26 @@ public class Dog {
|
|||||||
return 24 + (humanYears - 2) * 5;
|
return 24 + (humanYears - 2) * 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void main(String args[]) {
|
||||||
|
Dog dog1 = new Dog("Luna");
|
||||||
|
Dog dog2 = new Dog("Max");
|
||||||
|
Dog dog3 = new Dog("Ashley");
|
||||||
|
|
||||||
|
dog1.setAge(3);
|
||||||
|
dog1.setGender("F");
|
||||||
|
dog1.setBones(202);
|
||||||
|
|
||||||
|
dog2.setAge(4);
|
||||||
|
dog2.setGender("M");
|
||||||
|
dog2.setBones(204);
|
||||||
|
|
||||||
|
dog3.setAge(5);
|
||||||
|
dog3.setGender("F");
|
||||||
|
dog3.setBones(101);
|
||||||
|
|
||||||
|
System.out.println("Dog 1 is called " + dog1.getName());
|
||||||
|
System.out.println("Dog 2 has caught " + dog2.getBones() + " bones so far.");
|
||||||
|
System.out.println("Dog 3 is " + dog3.dogAgeAsPeopleYears(dog3.getAge()) + " years old in human years.");
|
||||||
|
System.out.println("Dog 1 gender: "+ dog1.getGender());
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import java.util.*;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class histogram {
|
public class histogram {
|
||||||
|
|
||||||
|
@ -2,37 +2,37 @@ import java.util.*;
|
|||||||
|
|
||||||
public class numbers {
|
public class numbers {
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
ArrayList<Integer> ints = new ArrayList<Integer>();
|
ArrayList<Integer> ints = new ArrayList<Integer>();
|
||||||
Scanner scan = new Scanner(System.in);
|
Scanner scan = new Scanner(System.in);
|
||||||
System.out.println("Enter positive integer! (Enter -1 to stop!)");
|
System.out.println("Enter positive integer! (Enter -1 to stop!)");
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
double median = 0;
|
double median = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int input1 = scan.nextInt();
|
int input1 = scan.nextInt();
|
||||||
if (input1 == -1) {
|
if (input1 == -1) {
|
||||||
break;
|
break;
|
||||||
} else if (input1 > 0) {
|
} else if (input1 > 0) {
|
||||||
ints.add(input1);
|
ints.add(input1);
|
||||||
sum += input1;
|
sum += input1;
|
||||||
counter++;
|
counter++;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Not Positive!");
|
System.out.println("Not Positive!");
|
||||||
}
|
|
||||||
}
|
|
||||||
//Collections.sort(ints);
|
|
||||||
for (int i = 0; i < counter - 1; i++) {
|
|
||||||
int minValue = i;
|
|
||||||
for (int j = i + 1; j < counter; j++) {
|
|
||||||
if (ints.get(j) < ints.get(minValue)) {
|
|
||||||
minValue = j;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int t = ints.get(i);
|
//Collections.sort(ints);
|
||||||
ints.set(i, ints.get(minValue));
|
for (int i = 0; i < counter - 1; i++) {
|
||||||
ints.set(minValue, t);
|
int minValue = i;
|
||||||
|
for (int j = i + 1; j < counter; j++) {
|
||||||
|
if (ints.get(j) < ints.get(minValue)) {
|
||||||
|
minValue = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int t = ints.get(i);
|
||||||
|
ints.set(i, ints.get(minValue));
|
||||||
|
ints.set(minValue, t);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user