求助!!!有帅哥美女上电脑1005的吗?

状态
不接受进一步回复。

水晶指环。。。

新手上路
注册
2004-11-12
消息
37
荣誉分数
0
声望点数
0
有谁做完了作业,教一下可以吗?

Q1. Assume that we want to write a program to simulate rolling of two dice. Write a main method for the Keyboard class below that prompts the user for two dice values each being between 1 and 6. If either of the two dice values is invalid, a message should appear indicating so but then the entered values should be ignored. This process should repeat for 5 times and then display in the console the number of times the roll of the dice was seven. Note that a seven can occur 6 ways as shown below.








image002.gif










public class Keyboard {
publicstaticint getInt() {
Scanner aScanner = new Scanner(System.in);
System.out.println("Enter a dice value between 1 and 6 :");
return(aScanner.nextInt());
}
}

Test your program with at least one test case and include the test results in out.txt file.


Q2. Write the method public int[] partialSort(int[] anArray) which takes an array of int as a parameter and returns a new array of int. The new array should contain at the front all the odd numbers from the given array and all the even numbers of that array at the end. For example, if we are given an array with the numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 then the resulting array should contain numbers as follows: 1, 3, 5, 7, 9, 2, 4, 6, 8, 10. Notice that all the odd numbers are in the first half of the array and the even numbers in the second half. Note however, that there may be no odd numbers or possibly no even numbers. You may assume that there is at least one number in the given array.
(Hint: you can use the modulus (%) operator to decide if something is odd/even).
Write the above method in a SortTester class with a public static void main() method that tests the partialSort() method withthe following arrays:
{1,2,3,4,5,6,7,8,9,10}
{8}
{5}
{9,7,5}
{98, 8}
{12, 57, 45, 9, 354, 3, 2, 56, 7,8 ,94, 45,67, 21}
Copy and paste your testing for marking. Your main method should prompt the user as follows:

Please enter number of elements in the array: 3
Please enter 1 element: 1
Please enter 2 element: 4
Please enter 3 element: 5

You entered the array: 1, 4, 5
Partially sorted as : 1, 5, 4

Note that you do not have to sort the input array.



Q3. Write a Month class with a public method called getName() and returns a String. This method would transform numbers 1, 2, 3, . . ., 12 into the corresponding month names January, February, March, . . ., December. Implement a class Month whose constructor parameter is the month number and whose getName () method returns the month name. Hint: Make a very long string "January February March . . .", in which you add spaces such that each month name has the same length. Then use substring to extract the month you want.
Test your class and method with the following tester and include the test results in out.txt file:
**
This program tests the Month class.
*/
public class MonthTester
{
public static void main(String[] args)
{
Month jan = new Month(1);
System.out.println("Name: " + jan.getName());
System.out.println("Expected: January");
Month mar = new Month(3);
System.out.println("Name: " + mar.getName());
System.out.println("Expected: March");
Month dec = new Month(12);
System.out.println("Name: " + dec.getName());
System.out.println("Expected: December");
}
}


Q4. Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList<String>. Supply a method

void addCoin(String coinName)

Add a method toString to the Purse class that prints the coins in the purse in the format

Purse[Quarter,Dime,Nickel,Dime]

Use the following class as your tester class:


/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse p = new Purse();
p.addCoin("Quarter");
p.addCoin("Dime");
p.addCoin("Nickel");
p.addCoin("Dime");

System.out.println(p.toString());
System.out.println("Expected: Purse[Quarter,Dime,Nickel,Dime]");
}
}


Q5. Write a method reverse() that reverses the sequence of coins in a purse. Use the toString() method of the preceding question to test your code. For example, if reverse is called with a purse


Purse[Quarter,Dime,Nickel,Dime]


then the purse is changed to

Purse[Dime,Nickel,Dime,Quarter]


Use the following class as your tester class:


/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse p = new Purse();
p.addCoin("Quarter");
p.addCoin("Dime");
p.addCoin("Nickel");
p.addCoin("Dime");
System.out.println("Original purse: " + p.toString());
System.out.println("Expected: Purse[Quarter,Dime,Nickel,Dime]");
p.reverse();
System.out.println("Reversed purse: " + p.toString());
System.out.println("Expected: Purse[Dime,Nickel,Dime,Quarter]");
}
}



Q.6 Add a transfer() method to the previous purse class

public void transfer(Purse other)

that transfers the contents of one purse to another. For example, if a is

Purse[Quarter,Dime,Nickel,Dime]

and b is

Purse[Dime,Nickel]

then after the call a.transfer(b), a is

Purse[Quarter,Dime,Nickel,Dime,Dime,Nickel]

and b is empty.


Use the following class as your tester class:


/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse a = new Purse();
a.addCoin("Quarter");
a.addCoin("Dime");
a.addCoin("Nickel");
a.addCoin("Dime");
Purse b = new Purse();
b.addCoin("Dime");
b.addCoin("Nickel");

a.transfer(b);

System.out.println(a.toString());
System.out.println("Expected: Purse[
Quarter,Dime,Nickel,Dime,Dime,Nickel]");
System.out.println(b.toString());
System.out.println("Expected: Purse[]");
}
}





Q7. Write a method for the Purse class

public boolean sameContents(Purse other)

that checks whether the other purse has the same coins in the same order.

Use the following class as your tester class:


/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse a = new Purse();
a.addCoin("Quarter");
a.addCoin("Dime");

Purse b = new Purse();
b.addCoin("Quarter");
b.addCoin("Dime");

System.out.println(a.sameContents(b));
System.out.println("Expected: true");

Purse c = new Purse();
c.addCoin("Nickel");
c.addCoin("Dime");
c.addCoin("Nickel");
Purse d = new Purse();
d.addCoin("Nickel");
d.addCoin("Dime");
d.addCoin("Quarter");

System.out.println(c.sameContents(d));
System.out.println("Expected: false");

Purse e = new Purse();
e.addCoin("Nickel");
e.addCoin("Dime");
e.addCoin("Nickel");

Purse f = new Purse();
f.addCoin("Nickel");
f.addCoin("Dime");

System.out.println(e.sameContents(f));
System.out.println("Expected: false");
}
}




Q8. Write a method for the Purse class

public boolean sameCoins(Purse other)

that checks whether the other purse has the same coins, perhaps in a different order. For example, the purses

Purse[Quarter,Dime,Nickel,Dime]

and

Purse [Nickel,Dime,Dime,Quarter]

should be considered equal.

You will probably need one or more helper methods.Use the following class as your tester class:

/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse a = new Purse();
a.addCoin("Quarter");
a.addCoin("Dime");
a.addCoin("Nickel");
a.addCoin("Dime");
Purse b = new Purse();
b.addCoin("Nickel");
b.addCoin("Dime");
b.addCoin("Dime");
b.addCoin("Quarter");

System.out.println(a.sameCoins(b));
System.out.println("Expected: true");

Purse c = new Purse();
c.addCoin("Quarter");
c.addCoin("Penny");
c.addCoin("Nickel");
c.addCoin("Dime");

Purse d = new Purse();
d.addCoin("Nickel");
d.addCoin("Dime");
d.addCoin("Dime");
d.addCoin("Quarter");

System.out.println(c.sameCoins(d));
System.out.println("Expected: false");
}
}

You will probably need one or more helper methods.Use the following class as your tester class:

/**
This class tests the Purse class.
*/
public class PurseTester
{
public static void main(String[] args)
{
Purse a = new Purse();
a.addCoin("Quarter");
a.addCoin("Dime");
a.addCoin("Nickel");
a.addCoin("Dime");
Purse b = new Purse();
b.addCoin("Nickel");
b.addCoin("Dime");
b.addCoin("Dime");
b.addCoin("Quarter");

System.out.println(a.sameCoins(b));
System.out.println("Expected: true");

Purse c = new Purse();
c.addCoin("Quarter");
c.addCoin("Penny");
c.addCoin("Nickel");
c.addCoin("Dime");

Purse d = new Purse();
d.addCoin("Nickel");
d.addCoin("Dime");
d.addCoin("Dime");
d.addCoin("Quarter");

System.out.println(c.sameCoins(d));
System.out.println("Expected: false");
}
}
 
谁手这么快啊,不帮写作业就给我扣声望啊,您老慢慢扣,扣到-2000最好,fucking losers
 

附件

  • untitled.jpg
    untitled.jpg
    8.1 KB · 查看: 175
那东西不用看 要考试了 找那么几天 认真的从头看到尾 啥都办了

注意 是从头看 看到尾
 
如果我没理解错的话, 现在的阿X教师总喜欢显摆自己臭英文 .. 愣是不能理解 ..

第一题大概就是建两个INT的ARRAY, 然后大小为4吧
然后第一个骰子就建一个整数变量, 用那个RANDOM NUM之类的METHOD随机一个出来然后余上6加1.
然后这个东西重复5次(题目似乎是这么说的), 每得一个数都放到上面得ARRAY里
第2个骰子得数一样步骤

然后就把两个ARRY得每一个值上下加起来. 找找有没有7, 有就好, 没有就SYSTEM.OUT.PRINTLN("U FKING NOOB, AX");
 
楼主,我可以替你这种一眼书不看的写作业,甚至可以代考期中考试
你给个价吧
 
作业不难, 还是推荐楼主写一写, 写了基本上MIDTERM就能拿100了.
 
如果我没理解错的话, 现在的阿X教师总喜欢显摆自己臭英文 .. 愣是不能理解 ..

第一题大概就是建两个INT的ARRAY, 然后大小为4吧
然后第一个骰子就建一个整数变量, 用那个RANDOM NUM之类的METHOD随机一个出来然后余上6加1.
然后这个东西重复5次(题目似乎是这么说的), 每得一个数都放到上面得ARRAY里
第2个骰子得数一样步骤

然后就把两个ARRY得每一个值上下加起来. 找找有没有7, 有就好, 没有就SYSTEM.OUT.PRINTLN("U FKING NOOB, AX");

什么啊?难道我理解错了?那2个骰子的数不是你自己写进去的吗?还要random?

说实在的,这学期1405的题都很抽像,notes简单了,反而题目难了
 
俺不是帅哥,也不是美女~只是来帮您顶贴的
 
什么啊?难道我理解错了?那2个骰子的数不是你自己写进去的吗?还要random?

说实在的,这学期1405的题都很抽像,notes简单了,反而题目难了

跟NEL哥差不多难度, 得看考试,

那问题我无法理解, 英语不好
 
状态
不接受进一步回复。
后退
顶部