Question

In: Computer Science

Where the OOD approach is specified use a separate test class to create your objects. Odd.java...

Where the OOD approach is specified use a separate test class to create your objects.

  1. Odd.java Write a program that takes an integer input and prints an output messages stating whether or not the user enters an odd positive number.
  1. Guessing.java: Use OOD: Write a number guessing program. Assign a value to a variable called number at the top of the program. Give a prompt that asks for five guesses. See whether any of the guesses matches the number and then print an appropriate message if one does.
  2. GuessingTest
  1. Tax.java: Use OOD: Write a tax calculation program. Prompt the user to input two salaries for a family and output their combined tax bill. A family pays no tax if its income is less than 15000 euro. The family pays a 10% tax if the combined salaries are for 15000 euro through 19,999 euro, or a 20% tax if the combined salaries are from 20000 euro through 29,999. Otherwise the family pays a 30% tax.
  2. TaxTest
  1. GreaterThan.java Write a program with a main method that calls a method called greaterThan, that takes two integer arguments and returns 1, if the first is greater than the second, and 0 otherwise.
  1. Initals.java : Use OOD: Write a program that asks the user for two initials. Print a message telling the user whether the first initial falls alphabetically before the second.
  2. InitialsTest

Solutions

Expert Solution

Kindly upvote if this helped


As there are multiple questions answering initial 2 Questons. Kindly create seperate questions for multiple questions.

1)

Odd.java

import java.util.Scanner;

public class Odd {
  public void OddTest() {
                Scanner sc = new Scanner(System.in);
                System.out.println("Enter a number");
                int input = sc.nextInt();
                sc.close();
                if( input%2!=0 && input>0 ) {  // number is odd and positive
                        System.out.println("Number is an odd positive number");
                }else {
                        System.out.println("Number is either even or negative");
                }
  }
}


OddTest.java

class OddTest{
        public static void main(String[] args) {
                Odd d = new Odd();
                d.OddTest();
        }
}








2.)

Guessing.java

import java.util.ArrayList;
import java.util.Scanner;

public class Guessing{
        public int getNumber() {
                return number;
        }
        int number = 10;
        public void GuessNumber() {
                ArrayList<Integer> numbers = new ArrayList<Integer>(); // arrayList to store the guesses
                Scanner sc = new Scanner(System.in);
                int num;
                System.out.println("Guess the number");
                for(int i=1;i<=5;i++) {
                        num = Integer.parseInt(sc.nextLine());
                        numbers.add(num);
                }
                sc.close();
                boolean flag = true;
                for(int i=0;i<5;i++) {
                        if(numbers.get(i) == getNumber()) {
                                int t = i+1;
                                System.out.println("Guess number "+t+" matched");
                                flag = false;
                        }
                }
                if(flag) {
                        System.out.println("No guess successful");
                }
        }
}


GuessingTest.java

class GuessingTest{
        public static void main(String[] args) {
                Guessing g = new Guessing();
                g.GuessNumber();
        }
}








Snapshot for indent

Adding solution to other parts for student understanding

class Tax{
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                System.out.println("Enter salary of 2 members");
                double s1 = Double.parseDouble(sc.nextLine());
                double s2 = Double.parseDouble(sc.nextLine());
                double income = s1+s2;
                double tax = 0;
                sc.close();
                if(income>=15000 && income < 20000) {
                        tax = income * 0.1; //10%
                }
                if(income>=20000 && income < 30000) {
                        tax = income * 0.2; //20%
                }
                if(income >=30000) {
                        tax = income * 0.3; //30%
                }
                System.out.println("Tax is "+tax);
        }
        
        
}


class Inte{
public static int greaterThan(int a , int b) {
                if(a>b) {
                        return 1;
                }
                return 0;
        }
        public static void main(String[] args) {
                greaterThan(10, 20);
        }
}



class Initials{
public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter 2 initials");
        String a = sc.nextLine();
        String b = sc.nextLine();
        if(a.compareTo(b)>0) {
                System.out.println(a+ " falls after "+b);
        }else if(a.compareTo(b)<0) {
                System.out.println(a+ " falls before "+b);
        }else {
                System.out.println("Both are equal");
                sc.close();
        }
}       
}

Related Solutions

In this class add Comparable interface. In the driver program create a few objects and In...
In this class add Comparable interface. In the driver program create a few objects and In the driver program create a few objects and compare them . then create a list of those objects and sort them .A Quadratic is bigger than another Quadratic if it opens faster package pack2; /** * This is a program for defining a quadratic equation * @author sonik */ public class Quadratic { public int coeffX2 = 0; public int coeffX = 0; public...
Step 4: Create a class called BabyNamesDatabase This class maintains an ArrayList of BabyName objects. Instance...
Step 4: Create a class called BabyNamesDatabase This class maintains an ArrayList of BabyName objects. Instance Variables Declare an ArrayList of BabyName objects. Constructor public BabyNamesDatabase () - instantiate the ArrayList of BabyName objects. You will not insert the items yet. This method will be one line of code. Mutator Methods public void readBabyNameData(String filename) - open the provided filename given as input parameter, use a loop to read all the data in the file, create a BabyName object for...
9.6 (Rational Class) Create a class called Rational (separate the files as shown in the chapter)...
9.6 (Rational Class) Create a class called Rational (separate the files as shown in the chapter) for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the class-the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For...
This assignment will test your knowledge and skills in C++. Create a class named employee and...
This assignment will test your knowledge and skills in C++. Create a class named employee and have the data members of: Name ID Salary Create a class named manager that inherits the employee class and adds the data members: Managed_Employees (Array of up to 3 employees) Department Create methods to update each data member in the employee class. Create a method to print out the managed employees sorted by their salary in the manager class. (You can use one of...
Python Create a move function that is only defined in the base class called Objects. The...
Python Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside...
In python please Problem Create two server objects using the class create a function, biggest_server_object_sum, outside of the ServerClass class, that: 1. Takes the IP 2. Sums the octets of the IP together (example 127.0.0.1 = 127+0+0+1 = 128) 3. Returns the Server object with the larger sum Example: server_one = ServerClass("127.0.0.1") server_two = ServerClass("192.168.0.1") result = biggest_ip_sum(server_one, server_two) print(result) Hint Modify get_server_ip in the previous problem. -------------------- Please use this code to start class ServerClass: """ Server class for...
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The...
Details: Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. NOTE: You are not allowed to use...
Directions: For each problem, use the specified approach to decide whether to reject the null hypothesis....
Directions: For each problem, use the specified approach to decide whether to reject the null hypothesis. In each case, be sure to: 1) Cite your evidence a. For the p-value approach, write the p-value and compare it to ? b. For the Critical Value approach, look up the CV(s) and either apply the appropriate mathematical rule or draw the rejection region diagram 2) State your conclusion about the null hypothesis (i.e. Reject ?o; Do not reject ?a) 3) State your...
R problem 1. Student records. Create an S3 class studentRecord for objects that are a list...
R problem 1. Student records. Create an S3 class studentRecord for objects that are a list with the named elements ‘name’, ‘subjects completed’, ‘grades’, and ‘credit’. Write a studentRecord method for the generic function mean, which returns a weighted GPA, with subjects weighted by credit. Also write a studentRecord method for print, which employs some nice formatting, perhaps arranging subjects by year code. Finally create a further class for a cohort of students, and write methods for mean and print...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT