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

java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files....
Objectives: Use class inheritance to create new classes. Separate class definition and implementation in different files. Use include guard in class header files to avoid multiple inclusion of a header. Tasks: In our lecture, we wrote a program that defines and implements a class Rectangle. The source code can be found on Blackboard > Course Content > Classes and Objects > Demo Program 2: class Rectangle in three files. In this lab, we will use class inheritance to write a...
please use C++ Create a class named Byte that encapsulates an array of 8 Bit objects....
please use C++ Create a class named Byte that encapsulates an array of 8 Bit objects. The Byte class will provide the following member functions: Byte - word: Bit[8] static Bit array defaults to all Bits false + BITS_PER_BYTE: Integer16 Size of a byte constant in Bits; 8 + Byte() default constructor + Byte(Byte) copy constructor + set(Integer): void sets Bit to true + clear(): void sets to 0 + load(Byte): void sets Byte to the passed Byte + read():...
Make Animal an abstract class. Create a Kennel Class Create 2-3 Dog objects Create 2-3 Cat...
Make Animal an abstract class. Create a Kennel Class Create 2-3 Dog objects Create 2-3 Cat objects Put your Dog and Cat objects in an Array of Animals Loop over your Animals and print the animal with Species, Age, and the status of the appropriate vaccines. Using the code below: public class Animal { //Declaring instance variables private int age; private boolean RabiesVaccinationStatus; private String name; private String ownerName; //Zero argumented constructor public Animal() { } //Parameterized constructor public Animal(int...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance of Dog and use its methods. Purpose: This application provides experience with creating classes and instances of objects in C#. Requirements: Project Name: Dog Target Platform: Console Programming Language: C# Documentation: Types and variables (Links to an external site.) (Microsoft) Classes and objects (Links to an external site.) (Microsoft) Enums (Links to an external site.) (Microsoft) Create a class called Dog. Dog is to...
Create a Square Class and Create a graphical representation of your Square class - your class...
Create a Square Class and Create a graphical representation of your Square class - your class will have the following data fields: double width, String color. - provide a no-args constructor. - provide a constructor that creates a square with the specific width - implement method getArea() - implement method getPerimeter() - implement method setColor(). - draw a UML diagram for your class - write a test program that will create a square with the width 30, 40 and 50....
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...
Create a generic method to print objects in java. Include a tester class.
Create a generic method to print objects in java. Include a tester class.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT