Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Daniel Lawson 2-18 self-check (even)
- 2.
- a. true
- b. false
- c. true
- d. false
- e. false
- f. false
- g. false
- h. true
- i. true
- 4.
- -in line 4, it does not store the return of the minimum in a container. (Which would be smaller in this case)
- -in line 5, they used = instead of ==
- -in line 6, they forgot to put a outside of the the "" to use its actual values.
- -in line 10, they set the method as a void when it should int because it returns an integer.
- -in line 16, you do not need to specify the data type of smaller when returning it because it was already defined
- -The program does not have an if statement to handle if smaller is b, or both values are equal. It could be structured something like:
- if (a == b){
- a is the same as b
- }else if(smaller == b){
- b is smaller
- }else if(smaller == a){
- a is smaller
- }
- -in line 13 it forgot to put the if after the else and between (a=>v)
- -This is an 8th bonus error! - The program does not need to create a minimum method because one could already use the built in Math.min method
- 6.
- a.
- // b = 5, b = 6,
- it would print:10 6
- b.
- // a = 9, b = 9,
- it would print:9 9
- c.
- //a = 3
- it would print:3 4
- d. a = 30, a = 29
- it would print:29 30
- 8.
- if the number % 2 == 0 is true, but number % 3 is false, then it will print that the number is odd when it is actually even
- in the correct version the else statement should be outside of the first if.
- It would also be nice if it said something if it was even but not divisble by 6like:
- Scanner console = new Scanner(System.in);
- System.out.print("Type a number: ");
- int number = console.nextInt();
- if(number % 2 ==0){
- System.out.println("Even");
- if(number % 3 == 0){
- System.out.println("Divisible by 6.");
- }
- }
- else{
- System.out.println("Odd.");
- }
- 10.
- a = 2;
- if(x<30){
- x++;
- }
- System.out.println("Java is awesome" + x);
- 12.
- Scanner c = new Scanner(System.in);
- public static int m(Scanner c){
- System.out.print("How much will John be spending? ");
- double amount = c.nextDouble();
- System.out.println();
- int numBills = (int) (amount / 20.0);
- if(numBills * 20.0 <amount){
- numBills++;
- }
- return numBills;
- }
- int b1 = m(c);
- int b2 = m(c);
- System.out.println("John needs " + b1 +" bills");
- System.out.println("John needs " + b2 +" bills");
- 14.
- /**
- * Created by Daniel on 4/19/2016.
- */
- import java.util.*;
- public class selfCheck14 {
- public static void main(String[] args){
- Scanner c = new Scanner(System.in);
- card(c);
- }
- public static void card(Scanner c){
- String rank = "error";
- String suit ="error";
- System.out.print("Enter a card: ");
- String s = c.nextLine();
- s = s.toUpperCase();
- if(s.contains("2")){
- rank = "Two";
- }
- if(s.contains("3")){
- rank = "Three";
- }
- if(s.contains("4")){
- rank = "Four";
- }
- if(s.contains("5")){
- rank = "Five";
- }
- if(s.contains("6")){
- rank = "Six";
- }
- if(s.contains("7")){
- rank = "Seven";
- }
- if(s.contains("8")){
- rank ="Eight";
- }
- if(s.contains("9")){
- rank = "Nine";
- }
- if(s.contains("10")){
- rank = "10";
- }
- if(s.contains("J")){
- rank = "Jack";
- }
- if(s.contains("Q")){
- rank = "Queen";
- }
- if(s.contains("K")){
- rank = "King";
- }
- if(s.contains("A")){
- rank = "Ace";
- }
- if(s.contains("C")){
- suit = "Clubs";
- }
- if(s.contains("D")){
- suit = "Diamonds";
- }
- if(s.contains("H")){
- suit = "Hearts";
- }
- if(s.contains("S")){
- suit = "Spades";
- }
- System.out.println(rank + " of " + suit);
- }
- }
- 16.
- It returns the value of a factor every time it finds one in the for loop instead of the sum.
- It should first create a integer called factors before the for loop, and set it to 0
- In the n % i == 0 statement it should then increment the factor variable by one (factors++)
- at the outside of the for loop after it has finished, it should then return factors.
- 18.
- It evaluates to around 6.8 but with a lot of trailing zeroes because it is a double value, therefore something like 6.8000000.
Advertisement
Add Comment
Please, Sign In to add comment