Question
Java 1) Write a complete program that opens the file /usr/abc.txt and that outputs the smallest value on each line of the file. You may
Java
1) Write a complete program that opens the file /usr/abc.txt and that outputs the smallest value on each line of the file. You may assume that each line contains just 1 or more real values. For example, if the file contained
2.1 5 -9
3
1.4 9.2 3.8
Your program would output:
-9
3
1.4
(Hint: use more than one Scanner)
2) A class called NumberList represents a sequence of real numbers (doubles). Write the specification (prototype and pre and post conditions, Not The Body) for a member method that adds the data from one NumberList to the end of this NumberList. Of course, no input or output should be involved.
public class NumberList{
private double[] a; private int na; //[0..na-1] holds the data
// ... other stuff ...
// your prototype and pre and post conditions:
3) Student is a class that has just two fields, name and age. It has a no-parameter constructor that always constructs Bob whose age is 22. Assume that the fields are public.
Write a client method (i.e. a method that is not a member of Student) that is passed an array of Student and that returns an independent copy of the array. (Don't try to use clone.)
4) public class Clown extends Object{
private String name,circus;
public Clown(String n, String c){name=n;circus=c;}
public void talk(){
System.out.println("I'm a clown whose name is "+name);
}
}
A happy clown is a clown who says that he is a happy clown whenever he talks (in addition to also telling you his name) and who knows his own age. Write a complete class HappyClown by deriving it from Clown.
Add as little as possible, but provide and label (using a,b,c, and d) the following:
a) A constructor
b) An access method that returns some information about this HappyClown
c) Code that overloads a method or constructor
d) Code that overrides a method or constructor
5) Here is the specification of two instance methods of class Bank. Write the body of the second one (which calls the first one). (Don't write the body of the first one.) Don't use anything else from class Bank. Use try catch so that your sum method doesn't throw any exceptions.
private int assets(String accountId) throws AccountException
//post: the balance held in the account in this Bank whose identifier
// is accountId is returned, or there is no such account in
// this Bank and AccountException is thrown
public int sum(String[] list){
//pre: list contains 1 or more strings, all distinct.
//post: returns the sum of the balances of all the accounts in this
// Bank whose identifiers are in list. (Elements of list that
// are not account id's in this Bank are ignored.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started